Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquick3dmodel_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5
6#ifndef QSSGMODEL_H
7#define QSSGMODEL_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <QtQuick3D/private/qquick3dnode_p.h>
21#include <QtQuick3D/private/qquick3dmaterial_p.h>
22#include <QtQuick3D/private/qquick3dgeometry_p.h>
23#include <QtQuick3D/private/qquick3dinstancing_p.h>
24#include <QtQuick3D/private/qquick3dskeleton_p.h>
25#include <QtQuick3D/private/qquick3dskin_p.h>
26#include <QtQuick3D/private/qquick3dbakedlightmap_p.h>
27#include <QtQuick3D/private/qquick3dmorphtarget_p.h>
28#include <QtQuick3DUtils/private/qssgbounds3_p.h>
29
30#include <QtQml/QQmlListProperty>
31
32#include <QtCore/QVector>
33#include <QtCore/QList>
34#include <QtCore/QUrl>
35
36#include <QtGui/QVector4D>
37
39
41{
42 Q_GADGET
43 Q_PROPERTY(QVector3D minimum READ minimum CONSTANT)
44 Q_PROPERTY(QVector3D maximum READ maximum CONSTANT)
45 QML_VALUE_TYPE(bounds)
46
47public:
48 QVector3D minimum() const
49 {
50 return bounds.minimum;
51 }
52
53 QVector3D maximum() const
54 {
55 return bounds.maximum;
56 }
57
58 // For compatibility we start with zero values.
59 QSSGBounds3 bounds { QVector3D{}, QVector3D{} };
60};
61
62class Q_QUICK3D_EXPORT QQuick3DModel : public QQuick3DNode
63{
64 Q_OBJECT
65 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
66 Q_PROPERTY(bool castsShadows READ castsShadows WRITE setCastsShadows NOTIFY castsShadowsChanged)
67 Q_PROPERTY(bool receivesShadows READ receivesShadows WRITE setReceivesShadows NOTIFY receivesShadowsChanged)
68 Q_PROPERTY(QQmlListProperty<QQuick3DMaterial> materials READ materials)
69 Q_PROPERTY(QQmlListProperty<QQuick3DMorphTarget> morphTargets READ morphTargets NOTIFY morphTargetsChanged)
70 Q_PROPERTY(bool pickable READ pickable WRITE setPickable NOTIFY pickableChanged)
71 Q_PROPERTY(QQuick3DGeometry *geometry READ geometry WRITE setGeometry NOTIFY geometryChanged)
72 Q_PROPERTY(QQuick3DInstancing *instancing READ instancing WRITE setInstancing NOTIFY instancingChanged)
73 Q_PROPERTY(QQuick3DNode *instanceRoot READ instanceRoot WRITE setInstanceRoot NOTIFY instanceRootChanged)
74 Q_PROPERTY(QQuick3DSkeleton *skeleton READ skeleton WRITE setSkeleton NOTIFY skeletonChanged)
75 Q_PROPERTY(QQuick3DSkin *skin READ skin WRITE setSkin NOTIFY skinChanged REVISION(6, 4))
76 Q_PROPERTY(QList<QMatrix4x4> inverseBindPoses READ inverseBindPoses WRITE setInverseBindPoses NOTIFY inverseBindPosesChanged)
77 Q_PROPERTY(QQuick3DBounds3 bounds READ bounds NOTIFY boundsChanged)
78 Q_PROPERTY(float depthBias READ depthBias WRITE setDepthBias NOTIFY depthBiasChanged)
79 Q_PROPERTY(bool receivesReflections READ receivesReflections WRITE setReceivesReflections NOTIFY receivesReflectionsChanged REVISION(6, 3))
80 Q_PROPERTY(bool castsReflections READ castsReflections WRITE setCastsReflections NOTIFY castsReflectionsChanged REVISION(6, 4))
81 Q_PROPERTY(bool usedInBakedLighting READ isUsedInBakedLighting WRITE setUsedInBakedLighting NOTIFY usedInBakedLightingChanged REVISION(6, 4))
82 Q_PROPERTY(int lightmapBaseResolution READ lightmapBaseResolution WRITE setLightmapBaseResolution NOTIFY lightmapBaseResolutionChanged REVISION(6, 4))
83 Q_PROPERTY(QQuick3DBakedLightmap *bakedLightmap READ bakedLightmap WRITE setBakedLightmap NOTIFY bakedLightmapChanged REVISION(6, 4))
84 Q_PROPERTY(float instancingLodMin READ instancingLodMin WRITE setInstancingLodMin NOTIFY instancingLodMinChanged REVISION(6, 5))
85 Q_PROPERTY(float instancingLodMax READ instancingLodMax WRITE setInstancingLodMax NOTIFY instancingLodMaxChanged REVISION(6, 5))
86 Q_PROPERTY(float levelOfDetailBias READ levelOfDetailBias WRITE setLevelOfDetailBias NOTIFY levelOfDetailBiasChanged REVISION(6, 5))
87 Q_PROPERTY(float texelsPerUnit READ texelsPerUnit WRITE setTexelsPerUnit NOTIFY texelsPerUnitChanged FINAL REVISION(6, 10))
88 Q_PROPERTY(bool motionVectorEnabled READ motionVectorEnabled WRITE setMotionVectorEnabled NOTIFY motionVectorEnabledChanged REVISION(6, 11))
89 Q_PROPERTY(float motionVectorScale READ motionVectorScale WRITE setMotionVectorScale NOTIFY motionVectorScaleChanged REVISION(6, 11))
90 QML_NAMED_ELEMENT(Model)
91
92public:
93 explicit QQuick3DModel(QQuick3DNode *parent = nullptr);
94 ~QQuick3DModel() override;
95
96 QUrl source() const;
97 bool castsShadows() const;
98 bool receivesShadows() const;
99 bool pickable() const;
100 QQuick3DGeometry *geometry() const;
101 QQuick3DSkeleton *skeleton() const;
102 QList<QMatrix4x4> inverseBindPoses() const;
103 QQuick3DBounds3 bounds() const;
104 float depthBias() const;
105
106 QQmlListProperty<QQuick3DMaterial> materials();
107 QQmlListProperty<QQuick3DMorphTarget> morphTargets();
108
109 QQuick3DInstancing *instancing() const;
110 QQuick3DNode *instanceRoot() const;
111
112 Q_REVISION(6, 3) bool receivesReflections() const;
113 Q_REVISION(6, 4) bool castsReflections() const;
114 Q_REVISION(6, 4) QQuick3DSkin *skin() const;
115
116 static QString translateMeshSource(const QUrl &source, QObject *contextObject);
117
118 Q_REVISION(6, 4) bool isUsedInBakedLighting() const;
119 Q_REVISION(6, 4) int lightmapBaseResolution() const;
120 Q_REVISION(6, 4) QQuick3DBakedLightmap *bakedLightmap() const;
121
122 Q_REVISION(6, 5) float instancingLodMin() const;
123 Q_REVISION(6, 5) float instancingLodMax() const;
124 Q_REVISION(6, 5) float levelOfDetailBias() const;
125
126 Q_REVISION(6, 10) float texelsPerUnit() const;
127 Q_REVISION(6, 10) void setTexelsPerUnit(float newTexelsPerUnit);
128
129 Q_REVISION(6, 11) bool motionVectorEnabled() const;
130 Q_REVISION(6, 11) float motionVectorScale() const;
131
132public Q_SLOTS:
133 void setSource(const QUrl &source);
134 void setCastsShadows(bool castsShadows);
135 void setReceivesShadows(bool receivesShadows);
136 void setPickable(bool pickable);
137 void setGeometry(QQuick3DGeometry *geometry);
138 void setSkeleton(QQuick3DSkeleton *skeleton);
139 void setInverseBindPoses(const QList<QMatrix4x4> &poses);
140 void setBounds(const QVector3D &min, const QVector3D &max);
141 void setInstancing(QQuick3DInstancing *instancing);
142 void setInstanceRoot(QQuick3DNode *instanceRoot);
143 void setDepthBias(float bias);
144 Q_REVISION(6, 3) void setReceivesReflections(bool receivesReflections);
145 Q_REVISION(6, 4) void setCastsReflections(bool castsReflections);
146 Q_REVISION(6, 4) void setSkin(QQuick3DSkin *skin);
147 Q_REVISION(6, 4) void setUsedInBakedLighting(bool enable);
148 Q_REVISION(6, 4) void setLightmapBaseResolution(int resolution);
149 Q_REVISION(6, 4) void setBakedLightmap(QQuick3DBakedLightmap *bakedLightmap);
150
151 Q_REVISION(6, 5) void setInstancingLodMin(float minDistance);
152 Q_REVISION(6, 5) void setInstancingLodMax(float maxDistance);
153 Q_REVISION(6, 5) void setLevelOfDetailBias(float newLevelOfDetailBias);
154
155 Q_REVISION(6, 11) void setMotionVectorScale(float newMotionVectorScale);
156 Q_REVISION(6, 11) void setMotionVectorEnabled(bool newMotionVectorEnabled);
157
158Q_SIGNALS:
159 void sourceChanged();
160 void castsShadowsChanged();
161 void receivesShadowsChanged();
162 void pickableChanged();
163 void geometryChanged();
164 void skeletonChanged();
165 void inverseBindPosesChanged();
166 void boundsChanged();
167 void instancingChanged();
168 void instanceRootChanged();
169 void morphTargetsChanged();
170 void depthBiasChanged();
171 Q_REVISION(6, 3) void receivesReflectionsChanged();
172 Q_REVISION(6, 4) void castsReflectionsChanged();
173 Q_REVISION(6, 4) void skinChanged();
174 Q_REVISION(6, 4) void usedInBakedLightingChanged();
175 Q_REVISION(6, 4) void lightmapBaseResolutionChanged();
176 Q_REVISION(6, 4) void bakedLightmapChanged();
177
178 Q_REVISION(6, 5) void instancingLodMinChanged();
179 Q_REVISION(6, 5) void instancingLodMaxChanged();
180 Q_REVISION(6, 5) void levelOfDetailBiasChanged();
181
182 Q_REVISION(6, 10) void texelsPerUnitChanged();
183
184 Q_REVISION(6, 11) void motionVectorEnabledChanged();
185 Q_REVISION(6, 11) void motionVectorScaleChanged();
186
187protected:
188 QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override;
189 void markAllDirty() override;
190 void itemChange(ItemChange, const ItemChangeData &) override;
191
192private Q_SLOTS:
193 void onMaterialDestroyed(QObject *object);
194 void onMorphTargetDestroyed(QObject *object);
195
196private:
197 enum QSSGModelDirtyType {
198 SourceDirty = 0x00000001,
199 MaterialsDirty = 0x00000002,
200 ShadowsDirty = 0x00000004,
201 PickingDirty = 0x00000008,
202 GeometryDirty = 0x00000010,
203 SkeletonDirty = 0x00000020,
204 PoseDirty = 0x00000040,
205 InstancesDirty = 0x00000080,
206 MorphTargetsDirty = 0x00000100,
207 PropertyDirty = 0x00000200,
208 ReflectionDirty = 0x00000400,
209 SkinDirty = 0x00000800,
210 LodDirty = 0x00001000,
211 InstanceRootDirty = 0x00002000,
212 };
213
214 QUrl m_source;
215
216 quint32 m_dirtyAttributes = 0xffffffff; // all dirty by default
217 void markDirty(QSSGModelDirtyType type);
218 void updateSceneManager(QQuick3DSceneManager *sceneManager);
219
220 static void qmlAppendMaterial(QQmlListProperty<QQuick3DMaterial> *list, QQuick3DMaterial *material);
221 static QQuick3DMaterial *qmlMaterialAt(QQmlListProperty<QQuick3DMaterial> *list, qsizetype index);
222 static qsizetype qmlMaterialsCount(QQmlListProperty<QQuick3DMaterial> *list);
223 static void qmlClearMaterials(QQmlListProperty<QQuick3DMaterial> *list);
224
225 struct Material {
226 QQuick3DMaterial *material;
227 bool refed;
228 };
229 QVector<Material> m_materials;
230
231 static void qmlAppendMorphTarget(QQmlListProperty<QQuick3DMorphTarget> *list, QQuick3DMorphTarget *morphTarget);
232 static QQuick3DMorphTarget *qmlMorphTargetAt(QQmlListProperty<QQuick3DMorphTarget> *list, qsizetype index);
233 static qsizetype qmlMorphTargetsCount(QQmlListProperty<QQuick3DMorphTarget> *list);
234 static void qmlClearMorphTargets(QQmlListProperty<QQuick3DMorphTarget> *list);
235 QVector<QQuick3DMorphTarget *> m_morphTargets;
236 QQuick3DGeometry *m_geometry = nullptr;
237 QQuick3DBounds3 m_bounds;
238 QQuick3DSkeleton *m_skeleton = nullptr;
239 QList<QMatrix4x4> m_inverseBindPoses;
240 QQuick3DInstancing *m_instancing = nullptr;
241 QQuick3DNode *m_instanceRoot = nullptr;
242 QMetaObject::Connection m_geometryConnection;
243 QMetaObject::Connection m_instancingConnection;
244 float m_depthBias = 0.0f;
245 bool m_castsShadows = true;
246 bool m_receivesShadows = true;
247 bool m_pickable = false;
248 bool m_receivesReflections = false;
249 bool m_castsReflections = true;
250 bool m_usedInBakedLighting = false;
251 int m_lightmapBaseResolution = 1024;
252 QQuick3DBakedLightmap *m_bakedLightmap = nullptr;
253 QMetaObject::Connection m_bakedLightmapSignalConnection;
254 QQuick3DSkin *m_skin = nullptr;
255 float m_instancingLodMin = -1;
256 float m_instancingLodMax = -1;
257 float m_levelOfDetailBias = 1.0f;
258 float m_texelsPerUnit = 0.0f;
259 bool m_motionVectorEnabled = true;
260 float m_motionVectorScale = 1.0f;
261};
262
263QT_END_NAMESPACE
264
265Q_DECLARE_METATYPE(QQuick3DBounds3)
266
267#endif // QSSGMODEL_H
Combined button and popup list for selecting options.