| 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 | QT_BEGIN_NAMESPACE |
| 25 | struct QSSGRenderNode; |
| 26 | class QQuick3DNodePrivate; |
| 27 | class Q_QUICK3D_EXPORT QQuick3DNode : public QQuick3DObject |
| 28 | { |
| 29 | Q_OBJECT |
| 30 | Q_PROPERTY(float x READ x WRITE setX NOTIFY xChanged) |
| 31 | Q_PROPERTY(float y READ y WRITE setY NOTIFY yChanged) |
| 32 | Q_PROPERTY(float z READ z WRITE setZ NOTIFY zChanged) |
| 33 | Q_PROPERTY(QQuaternion rotation READ rotation WRITE setRotation NOTIFY rotationChanged) |
| 34 | Q_PROPERTY(QVector3D eulerRotation READ eulerRotation WRITE setEulerRotation NOTIFY eulerRotationChanged) |
| 35 | Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged) |
| 36 | Q_PROPERTY(QVector3D scale READ scale WRITE setScale NOTIFY scaleChanged) |
| 37 | Q_PROPERTY(QVector3D pivot READ pivot WRITE setPivot NOTIFY pivotChanged) |
| 38 | Q_PROPERTY(float opacity READ localOpacity WRITE setLocalOpacity NOTIFY localOpacityChanged) |
| 39 | Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged) |
| 40 | Q_PROPERTY(QVector3D forward READ forward NOTIFY forwardChanged) |
| 41 | Q_PROPERTY(QVector3D up READ up NOTIFY upChanged) |
| 42 | Q_PROPERTY(QVector3D right READ right NOTIFY rightChanged) |
| 43 | Q_PROPERTY(QVector3D scenePosition READ scenePosition NOTIFY scenePositionChanged) |
| 44 | Q_PROPERTY(QQuaternion sceneRotation READ sceneRotation NOTIFY sceneRotationChanged) |
| 45 | Q_PROPERTY(QVector3D sceneScale READ sceneScale NOTIFY sceneScaleChanged) |
| 46 | Q_PROPERTY(QMatrix4x4 sceneTransform READ sceneTransform NOTIFY sceneTransformChanged) |
| 47 | Q_PROPERTY(int staticFlags READ staticFlags WRITE setStaticFlags NOTIFY staticFlagsChanged) |
| 48 | |
| 49 | QML_NAMED_ELEMENT(Node) |
| 50 | |
| 51 | public: |
| 52 | enum TransformSpace { |
| 53 | LocalSpace, |
| 54 | ParentSpace, |
| 55 | SceneSpace |
| 56 | }; |
| 57 | Q_ENUM(TransformSpace) |
| 58 | |
| 59 | enum StaticFlags { |
| 60 | None |
| 61 | }; |
| 62 | Q_ENUM(StaticFlags) |
| 63 | |
| 64 | explicit QQuick3DNode(QQuick3DNode *parent = nullptr); |
| 65 | ~QQuick3DNode() override; |
| 66 | |
| 67 | float x() const; |
| 68 | float y() const; |
| 69 | float z() const; |
| 70 | QQuaternion rotation() const; |
| 71 | QVector3D eulerRotation() const; |
| 72 | QVector3D position() const; |
| 73 | QVector3D scale() const; |
| 74 | QVector3D pivot() const; |
| 75 | float localOpacity() const; |
| 76 | bool visible() const; |
| 77 | int staticFlags() const; |
| 78 | |
| 79 | QQuick3DNode *parentNode() const; |
| 80 | |
| 81 | QVector3D forward() const; |
| 82 | QVector3D up() const; |
| 83 | QVector3D right() const; |
| 84 | |
| 85 | QVector3D scenePosition() const; |
| 86 | QQuaternion sceneRotation() const; |
| 87 | QVector3D sceneScale() const; |
| 88 | QMatrix4x4 sceneTransform() const; |
| 89 | |
| 90 | Q_INVOKABLE void rotate(qreal degrees, const QVector3D &axis, QQuick3DNode::TransformSpace space); |
| 91 | |
| 92 | Q_INVOKABLE QVector3D mapPositionToScene(const QVector3D &localPosition) const; |
| 93 | Q_INVOKABLE QVector3D mapPositionFromScene(const QVector3D &scenePosition) const; |
| 94 | Q_INVOKABLE QVector3D mapPositionToNode(const QQuick3DNode *node, const QVector3D &localPosition) const; |
| 95 | Q_INVOKABLE QVector3D mapPositionFromNode(const QQuick3DNode *node, const QVector3D &localPosition) const; |
| 96 | Q_INVOKABLE QVector3D mapDirectionToScene(const QVector3D &localDirection) const; |
| 97 | Q_INVOKABLE QVector3D mapDirectionFromScene(const QVector3D &sceneDirection) const; |
| 98 | Q_INVOKABLE QVector3D mapDirectionToNode(const QQuick3DNode *node, const QVector3D &localDirection) const; |
| 99 | Q_INVOKABLE QVector3D mapDirectionFromNode(const QQuick3DNode *node, const QVector3D &localDirection) const; |
| 100 | |
| 101 | void markAllDirty() override; |
| 102 | |
| 103 | protected: |
| 104 | void connectNotify(const QMetaMethod &signal) override; |
| 105 | void disconnectNotify(const QMetaMethod &signal) override; |
| 106 | void componentComplete() override; |
| 107 | |
| 108 | public Q_SLOTS: |
| 109 | void setX(float x); |
| 110 | void setY(float y); |
| 111 | void setZ(float z); |
| 112 | void setRotation(const QQuaternion &rotation); |
| 113 | void setEulerRotation(const QVector3D &eulerRotation); |
| 114 | void setPosition(const QVector3D &position); |
| 115 | void setScale(const QVector3D &scale); |
| 116 | void setPivot(const QVector3D &pivot); |
| 117 | void setLocalOpacity(float opacity); |
| 118 | void setVisible(bool visible); |
| 119 | void setStaticFlags(int staticFlags); |
| 120 | |
| 121 | Q_SIGNALS: |
| 122 | void xChanged(); |
| 123 | void yChanged(); |
| 124 | void zChanged(); |
| 125 | void rotationChanged(); |
| 126 | void eulerRotationChanged(); |
| 127 | void positionChanged(); |
| 128 | void scaleChanged(); |
| 129 | void pivotChanged(); |
| 130 | void localOpacityChanged(); |
| 131 | void visibleChanged(); |
| 132 | void forwardChanged(); |
| 133 | void upChanged(); |
| 134 | void rightChanged(); |
| 135 | void sceneTransformChanged(); |
| 136 | void scenePositionChanged(); |
| 137 | void sceneRotationChanged(); |
| 138 | void sceneScaleChanged(); |
| 139 | void staticFlagsChanged(); |
| 140 | |
| 141 | protected: |
| 142 | QQuick3DNode(QQuick3DNodePrivate &dd, QQuick3DNode *parent = nullptr); |
| 143 | QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override; |
| 144 | virtual void itemChange(ItemChange, const ItemChangeData &) override; |
| 145 | |
| 146 | private: |
| 147 | friend QQuick3DSceneManager; |
| 148 | Q_DISABLE_COPY(QQuick3DNode) |
| 149 | Q_DECLARE_PRIVATE(QQuick3DNode) |
| 150 | }; |
| 151 | |
| 152 | QT_END_NAMESPACE |
| 153 | |
| 154 | QML_DECLARE_TYPE(QQuick3DNode) |
| 155 | |
| 156 | #endif // QSSGNODE_H |
| 157 | |