1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QSSGNODE_H
5#define QSSGNODE_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick3D/qquick3dobject.h>
19
20#include <QtGui/QVector3D>
21#include <QtGui/QQuaternion>
22#include <QtGui/QMatrix4x4>
23
24#include <QtQuick3DRuntimeRender/private/qssgrendergraphobject_p.h>
25
26QT_BEGIN_NAMESPACE
27struct QSSGRenderNode;
28class QQuick3DNodePrivate;
29class Q_QUICK3D_EXPORT QQuick3DNode : public QQuick3DObject
30{
31 Q_OBJECT
32 Q_PROPERTY(float x READ x WRITE setX NOTIFY xChanged)
33 Q_PROPERTY(float y READ y WRITE setY NOTIFY yChanged)
34 Q_PROPERTY(float z READ z WRITE setZ NOTIFY zChanged)
35 Q_PROPERTY(QQuaternion rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
36 Q_PROPERTY(QVector3D eulerRotation READ eulerRotation WRITE setEulerRotation NOTIFY eulerRotationChanged)
37 Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
38 Q_PROPERTY(QVector3D scale READ scale WRITE setScale NOTIFY scaleChanged)
39 Q_PROPERTY(QVector3D pivot READ pivot WRITE setPivot NOTIFY pivotChanged)
40 Q_PROPERTY(float opacity READ localOpacity WRITE setLocalOpacity NOTIFY localOpacityChanged)
41 Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged)
42 Q_PROPERTY(QVector3D forward READ forward NOTIFY forwardChanged)
43 Q_PROPERTY(QVector3D up READ up NOTIFY upChanged)
44 Q_PROPERTY(QVector3D right READ right NOTIFY rightChanged)
45 Q_PROPERTY(QVector3D scenePosition READ scenePosition NOTIFY scenePositionChanged)
46 Q_PROPERTY(QQuaternion sceneRotation READ sceneRotation NOTIFY sceneRotationChanged)
47 Q_PROPERTY(QVector3D sceneScale READ sceneScale NOTIFY sceneScaleChanged)
48 Q_PROPERTY(QMatrix4x4 sceneTransform READ sceneTransform NOTIFY sceneTransformChanged)
49 Q_PROPERTY(int staticFlags READ staticFlags WRITE setStaticFlags NOTIFY staticFlagsChanged)
50
51 QML_NAMED_ELEMENT(Node)
52
53public:
54 enum TransformSpace {
55 LocalSpace,
56 ParentSpace,
57 SceneSpace
58 };
59 Q_ENUM(TransformSpace)
60
61 enum StaticFlags {
62 None
63 };
64 Q_ENUM(StaticFlags)
65
66 explicit QQuick3DNode(QQuick3DNode *parent = nullptr);
67 ~QQuick3DNode() override;
68
69 float x() const;
70 float y() const;
71 float z() const;
72 QQuaternion rotation() const;
73 QVector3D eulerRotation() const;
74 QVector3D position() const;
75 QVector3D scale() const;
76 QVector3D pivot() const;
77 float localOpacity() const;
78 bool visible() const;
79 int staticFlags() const;
80
81 QQuick3DNode *parentNode() const;
82
83 QVector3D forward() const;
84 QVector3D up() const;
85 QVector3D right() const;
86
87 QVector3D scenePosition() const;
88 QQuaternion sceneRotation() const;
89 QVector3D sceneScale() const;
90 QMatrix4x4 sceneTransform() const;
91
92 Q_INVOKABLE void rotate(qreal degrees, const QVector3D &axis, QQuick3DNode::TransformSpace space);
93
94 Q_INVOKABLE QVector3D mapPositionToScene(const QVector3D &localPosition) const;
95 Q_INVOKABLE QVector3D mapPositionFromScene(const QVector3D &scenePosition) const;
96 Q_INVOKABLE QVector3D mapPositionToNode(const QQuick3DNode *node, const QVector3D &localPosition) const;
97 Q_INVOKABLE QVector3D mapPositionFromNode(const QQuick3DNode *node, const QVector3D &localPosition) const;
98 Q_INVOKABLE QVector3D mapDirectionToScene(const QVector3D &localDirection) const;
99 Q_INVOKABLE QVector3D mapDirectionFromScene(const QVector3D &sceneDirection) const;
100 Q_INVOKABLE QVector3D mapDirectionToNode(const QQuick3DNode *node, const QVector3D &localDirection) const;
101 Q_INVOKABLE QVector3D mapDirectionFromNode(const QQuick3DNode *node, const QVector3D &localDirection) const;
102
103 void markAllDirty() override;
104
105protected:
106 void connectNotify(const QMetaMethod &signal) override;
107 void disconnectNotify(const QMetaMethod &signal) override;
108 void componentComplete() override;
109
110public Q_SLOTS:
111 void setX(float x);
112 void setY(float y);
113 void setZ(float z);
114 void setRotation(const QQuaternion &rotation);
115 void setEulerRotation(const QVector3D &eulerRotation);
116 void setPosition(const QVector3D &position);
117 void setScale(const QVector3D &scale);
118 void setPivot(const QVector3D &pivot);
119 void setLocalOpacity(float opacity);
120 void setVisible(bool visible);
121 void setStaticFlags(int staticFlags);
122
123Q_SIGNALS:
124 void xChanged();
125 void yChanged();
126 void zChanged();
127 void rotationChanged();
128 void eulerRotationChanged();
129 void positionChanged();
130 void scaleChanged();
131 void pivotChanged();
132 void localOpacityChanged();
133 void visibleChanged();
134 void forwardChanged();
135 void upChanged();
136 void rightChanged();
137 void sceneTransformChanged();
138 void scenePositionChanged();
139 void sceneRotationChanged();
140 void sceneScaleChanged();
141 void staticFlagsChanged();
142
143protected:
144 QQuick3DNode(QQuick3DNodePrivate &dd, QQuick3DNode *parent = nullptr);
145 QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override;
146 virtual void itemChange(ItemChange, const ItemChangeData &) override;
147
148private:
149 friend QQuick3DSceneManager;
150 Q_DISABLE_COPY(QQuick3DNode)
151 Q_DECLARE_PRIVATE(QQuick3DNode)
152};
153
154QT_END_NAMESPACE
155
156QML_DECLARE_TYPE(QQuick3DNode)
157
158#endif // QSSGNODE_H
159

source code of qtquick3d/src/quick3d/qquick3dnode_p.h