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 instancingLodFactor READ instancingLodFactor WRITE setInstancingLodFactor NOTIFY instancingLodFactorChanged REVISION(6, 12))
87 Q_PROPERTY(float levelOfDetailBias READ levelOfDetailBias WRITE setLevelOfDetailBias NOTIFY levelOfDetailBiasChanged REVISION(6, 5))
88 Q_PROPERTY(float texelsPerUnit READ texelsPerUnit WRITE setTexelsPerUnit NOTIFY texelsPerUnitChanged FINAL REVISION(6, 10))
89 Q_PROPERTY(bool motionVectorEnabled READ motionVectorEnabled WRITE setMotionVectorEnabled NOTIFY motionVectorEnabledChanged REVISION(6, 11))
90 Q_PROPERTY(float motionVectorScale READ motionVectorScale WRITE setMotionVectorScale NOTIFY motionVectorScaleChanged REVISION(6, 11))
91 QML_NAMED_ELEMENT(Model)
92
93public:
94 explicit QQuick3DModel(QQuick3DNode *parent = nullptr);
95 ~QQuick3DModel() override;
96
97 QUrl source() const;
98 bool castsShadows() const;
99 bool receivesShadows() const;
100 bool pickable() const;
101 QQuick3DGeometry *geometry() const;
102 QQuick3DSkeleton *skeleton() const;
103 QList<QMatrix4x4> inverseBindPoses() const;
104 QQuick3DBounds3 bounds() const;
105 float depthBias() const;
106
107 QQmlListProperty<QQuick3DMaterial> materials();
108 QQmlListProperty<QQuick3DMorphTarget> morphTargets();
109
110 QQuick3DInstancing *instancing() const;
111 QQuick3DNode *instanceRoot() const;
112
113 Q_REVISION(6, 3) bool receivesReflections() const;
114 Q_REVISION(6, 4) bool castsReflections() const;
115 Q_REVISION(6, 4) QQuick3DSkin *skin() const;
116
117 static QString translateMeshSource(const QUrl &source, QObject *contextObject);
118
119 Q_REVISION(6, 4) bool isUsedInBakedLighting() const;
120 Q_REVISION(6, 4) int lightmapBaseResolution() const;
121 Q_REVISION(6, 4) QQuick3DBakedLightmap *bakedLightmap() const;
122
123 Q_REVISION(6, 5) float instancingLodMin() const;
124 Q_REVISION(6, 5) float instancingLodMax() const;
125 Q_REVISION(6, 5) float levelOfDetailBias() const;
126 Q_REVISION(6, 12) float instancingLodFactor() const;
127
128 Q_REVISION(6, 10) float texelsPerUnit() const;
129 Q_REVISION(6, 10) void setTexelsPerUnit(float newTexelsPerUnit);
130
131 Q_REVISION(6, 11) bool motionVectorEnabled() const;
132 Q_REVISION(6, 11) float motionVectorScale() const;
133
134public Q_SLOTS:
135 void setSource(const QUrl &source);
136 void setCastsShadows(bool castsShadows);
137 void setReceivesShadows(bool receivesShadows);
138 void setPickable(bool pickable);
139 void setGeometry(QQuick3DGeometry *geometry);
140 void setSkeleton(QQuick3DSkeleton *skeleton);
141 void setInverseBindPoses(const QList<QMatrix4x4> &poses);
142 void setBounds(const QVector3D &min, const QVector3D &max);
143 void setInstancing(QQuick3DInstancing *instancing);
144 void setInstanceRoot(QQuick3DNode *instanceRoot);
145 void setDepthBias(float bias);
146 Q_REVISION(6, 3) void setReceivesReflections(bool receivesReflections);
147 Q_REVISION(6, 4) void setCastsReflections(bool castsReflections);
148 Q_REVISION(6, 4) void setSkin(QQuick3DSkin *skin);
149 Q_REVISION(6, 4) void setUsedInBakedLighting(bool enable);
150 Q_REVISION(6, 4) void setLightmapBaseResolution(int resolution);
151 Q_REVISION(6, 4) void setBakedLightmap(QQuick3DBakedLightmap *bakedLightmap);
152
153 Q_REVISION(6, 5) void setInstancingLodMin(float minDistance);
154 Q_REVISION(6, 5) void setInstancingLodMax(float maxDistance);
155 Q_REVISION(6, 5) void setLevelOfDetailBias(float newLevelOfDetailBias);
156 Q_REVISION(6, 12) void setInstancingLodFactor(float newInstancingLodFactor);
157
158 Q_REVISION(6, 11) void setMotionVectorScale(float newMotionVectorScale);
159 Q_REVISION(6, 11) void setMotionVectorEnabled(bool newMotionVectorEnabled);
160
161Q_SIGNALS:
162 void sourceChanged();
163 void castsShadowsChanged();
164 void receivesShadowsChanged();
165 void pickableChanged();
166 void geometryChanged();
167 void skeletonChanged();
168 void inverseBindPosesChanged();
169 void boundsChanged();
170 void instancingChanged();
171 void instanceRootChanged();
172 void morphTargetsChanged();
173 void depthBiasChanged();
174 Q_REVISION(6, 3) void receivesReflectionsChanged();
175 Q_REVISION(6, 4) void castsReflectionsChanged();
176 Q_REVISION(6, 4) void skinChanged();
177 Q_REVISION(6, 4) void usedInBakedLightingChanged();
178 Q_REVISION(6, 4) void lightmapBaseResolutionChanged();
179 Q_REVISION(6, 4) void bakedLightmapChanged();
180
181 Q_REVISION(6, 5) void instancingLodMinChanged();
182 Q_REVISION(6, 5) void instancingLodMaxChanged();
183 Q_REVISION(6, 12) void instancingLodFactorChanged();
184 Q_REVISION(6, 5) void levelOfDetailBiasChanged();
185
186 Q_REVISION(6, 10) void texelsPerUnitChanged();
187
188 Q_REVISION(6, 11) void motionVectorEnabledChanged();
189 Q_REVISION(6, 11) void motionVectorScaleChanged();
190
191protected:
192 QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override;
193 void markAllDirty() override;
194 void itemChange(ItemChange, const ItemChangeData &) override;
195
196private Q_SLOTS:
197 void onMaterialDestroyed(QObject *object);
198 void onMorphTargetDestroyed(QObject *object);
199
200private:
201 enum QSSGModelDirtyType {
202 SourceDirty = 0x00000001,
203 MaterialsDirty = 0x00000002,
204 ShadowsDirty = 0x00000004,
205 PickingDirty = 0x00000008,
206 GeometryDirty = 0x00000010,
207 SkeletonDirty = 0x00000020,
208 PoseDirty = 0x00000040,
209 InstancesDirty = 0x00000080,
210 MorphTargetsDirty = 0x00000100,
211 PropertyDirty = 0x00000200,
212 ReflectionDirty = 0x00000400,
213 SkinDirty = 0x00000800,
214 LodDirty = 0x00001000,
215 InstanceRootDirty = 0x00002000,
216 };
217
218 QUrl m_source;
219
220 quint32 m_dirtyAttributes = 0xffffffff; // all dirty by default
221 void markDirty(QSSGModelDirtyType type);
222 void updateSceneManager(QQuick3DSceneManager *sceneManager);
223
224 static void qmlAppendMaterial(QQmlListProperty<QQuick3DMaterial> *list, QQuick3DMaterial *material);
225 static QQuick3DMaterial *qmlMaterialAt(QQmlListProperty<QQuick3DMaterial> *list, qsizetype index);
226 static qsizetype qmlMaterialsCount(QQmlListProperty<QQuick3DMaterial> *list);
227 static void qmlClearMaterials(QQmlListProperty<QQuick3DMaterial> *list);
228
229 struct Material {
230 QQuick3DMaterial *material;
231 bool refed;
232 };
233 QVector<Material> m_materials;
234
235 static void qmlAppendMorphTarget(QQmlListProperty<QQuick3DMorphTarget> *list, QQuick3DMorphTarget *morphTarget);
236 static QQuick3DMorphTarget *qmlMorphTargetAt(QQmlListProperty<QQuick3DMorphTarget> *list, qsizetype index);
237 static qsizetype qmlMorphTargetsCount(QQmlListProperty<QQuick3DMorphTarget> *list);
238 static void qmlClearMorphTargets(QQmlListProperty<QQuick3DMorphTarget> *list);
239 QVector<QQuick3DMorphTarget *> m_morphTargets;
240 QQuick3DGeometry *m_geometry = nullptr;
241 QQuick3DBounds3 m_bounds;
242 QQuick3DSkeleton *m_skeleton = nullptr;
243 QList<QMatrix4x4> m_inverseBindPoses;
244 QQuick3DInstancing *m_instancing = nullptr;
245 QQuick3DNode *m_instanceRoot = nullptr;
246 QMetaObject::Connection m_geometryConnection;
247 QMetaObject::Connection m_instancingConnection;
248 float m_depthBias = 0.0f;
249 bool m_castsShadows = true;
250 bool m_receivesShadows = true;
251 bool m_pickable = false;
252 bool m_receivesReflections = false;
253 bool m_castsReflections = true;
254 bool m_usedInBakedLighting = false;
255 int m_lightmapBaseResolution = 1024;
256 QQuick3DBakedLightmap *m_bakedLightmap = nullptr;
257 QMetaObject::Connection m_bakedLightmapSignalConnection;
258 QQuick3DSkin *m_skin = nullptr;
259 float m_instancingLodMin = -1;
260 float m_instancingLodMax = -1;
261 float m_instancingLodFactor = 0.0f;
262 float m_levelOfDetailBias = 1.0f;
263 float m_texelsPerUnit = 0.0f;
264 bool m_motionVectorEnabled = true;
265 float m_motionVectorScale = 1.0f;
266};
267
269
271
272#endif // QSSGMODEL_H
Combined button and popup list for selecting options.
QT_END_NAMESPACE Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QOhosPlatformWindow::NativeNodeRenderFitPolicy))