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
qquick3dinstancing_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
4#ifndef Q_QUICK3D_INSTANCING_P_H
5#define Q_QUICK3D_INSTANCING_P_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/qquick3dinstancing.h>
19#include <QtQuick3D/private/qquick3dobject_p.h>
20
21#include <QtGui/qvector3d.h>
22
23QT_BEGIN_NAMESPACE
24
25class QQuick3DInstancingPrivate : public QQuick3DObjectPrivate
26{
27public:
28 QQuick3DInstancingPrivate();
29 int m_instanceCountOverride = -1;
30 int m_instanceCount = 0;
31 bool m_hasTransparency = false;
32 bool m_instanceDataChanged = true;
33 bool m_instanceCountOverrideChanged = false;
34 bool m_depthSortingEnabled = false;
35 QVector3D m_shadowBoundsMinimum = QVector3D(1, 1, 1);
36 QVector3D m_shadowBoundsMaximum = QVector3D(-1, -1, -1);
37};
38
39class Q_QUICK3D_EXPORT QQuick3DInstanceListEntry : public QQuick3DObject
40{
41 Q_OBJECT
42
43 QML_ADDED_IN_VERSION(6, 2)
44 Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
45 Q_PROPERTY(QVector3D scale READ scale WRITE setScale NOTIFY scaleChanged)
46 Q_PROPERTY(QVector3D eulerRotation READ eulerRotation WRITE setEulerRotation NOTIFY eulerRotationChanged)
47 Q_PROPERTY(QQuaternion rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
48 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
49 Q_PROPERTY(QVector4D customData READ customData WRITE setCustomData NOTIFY customDataChanged)
50 QML_NAMED_ELEMENT(InstanceListEntry)
51
52public:
53 explicit QQuick3DInstanceListEntry(QQuick3DObject *parent = nullptr);
54 ~QQuick3DInstanceListEntry() override {}
55
56 QVector3D position() const
57 {
58 return m_position;
59 }
60 QVector3D scale() const
61 {
62 return m_scale;
63 }
64
65 QVector3D eulerRotation() const
66 {
67 return m_eulerRotation;
68 }
69
70 QQuaternion rotation() const
71 {
72 return m_rotation;
73 }
74
75 QColor color() const
76 {
77 return m_color;
78 }
79
80 QVector4D customData() const
81 {
82 return m_customData;
83 }
84
85public Q_SLOTS:
86 void setPosition(QVector3D position);
87 void setScale(QVector3D scale);
88 void setEulerRotation(QVector3D eulerRotation);
89 void setRotation(QQuaternion rotation);
90 void setColor(QColor color);
91 void setCustomData(QVector4D customData);
92
93Q_SIGNALS:
94 void positionChanged();
95 void scaleChanged();
96 void eulerRotationChanged();
97 void rotationChanged();
98 void colorChanged();
99 void customDataChanged();
100 void changed();
101
102protected:
103 QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *) override
104 {
105 return nullptr;
106 }
107
108private:
109 QVector3D m_position;
110 QVector3D m_scale = {1, 1, 1};
111 QVector3D m_eulerRotation;
112 QQuaternion m_rotation;
113 QColor m_color = Qt::white;
114 QVector4D m_customData;
115 bool m_useEulerRotation = true;
116 friend class QQuick3DInstanceList;
117};
118
119class Q_QUICK3D_EXPORT QQuick3DInstanceList : public QQuick3DInstancing
120{
121 Q_OBJECT
122 Q_PROPERTY(QQmlListProperty<QQuick3DInstanceListEntry> instances READ instances)
123 Q_PROPERTY(int instanceCount READ instanceCount NOTIFY instanceCountChanged)
124 QML_NAMED_ELEMENT(InstanceList)
125 QML_ADDED_IN_VERSION(6, 2)
126
127 Q_CLASSINFO("DefaultProperty", "instances")
128
129public:
130 explicit QQuick3DInstanceList(QQuick3DObject *parent = nullptr);
131 ~QQuick3DInstanceList() override;
132
133 QByteArray getInstanceBuffer(int *instanceCount) override;
134 QQmlListProperty<QQuick3DInstanceListEntry> instances();
135 int instanceCount() const;
136
137Q_SIGNALS:
138 void instanceCountChanged();
139
140private Q_SLOTS:
141 void handleInstanceChange();
142 void onInstanceDestroyed(QObject *object);
143
144private:
145 void generateInstanceData();
146
147 static void qmlAppendInstanceListEntry(QQmlListProperty<QQuick3DInstanceListEntry> *list, QQuick3DInstanceListEntry *material);
148 static QQuick3DInstanceListEntry *qmlInstanceListEntryAt(QQmlListProperty<QQuick3DInstanceListEntry> *list, qsizetype index);
149 static qsizetype qmlInstanceListEntriesCount(QQmlListProperty<QQuick3DInstanceListEntry> *list);
150 static void qmlClearInstanceListEntries(QQmlListProperty<QQuick3DInstanceListEntry> *list);
151
152 bool m_dirty = true;
153 QByteArray m_instanceData;
154 QList<QQuick3DInstanceListEntry *> m_instances;
155};
156
157class Q_QUICK3D_EXPORT QQuick3DFileInstancing : public QQuick3DInstancing
158{
159 Q_OBJECT
160 QML_NAMED_ELEMENT(FileInstancing)
161 QML_ADDED_IN_VERSION(6, 2)
162 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
163 Q_PROPERTY(int instanceCount READ instanceCount NOTIFY instanceCountChanged)
164
165public:
166 explicit QQuick3DFileInstancing(QQuick3DObject *parent = nullptr);
167 ~QQuick3DFileInstancing() override;
168
169 const QUrl &source() const;
170 void setSource(const QUrl &newSource);
171
172 bool loadFromBinaryFile(const QString &filename);
173 bool loadFromXmlFile(const QString &filename);
174 int writeToBinaryFile(QIODevice *out);
175
176 int instanceCount() const;
177
178Q_SIGNALS:
179 void instanceCountChanged();
180 void sourceChanged();
181
182protected:
183 QByteArray getInstanceBuffer(int *instanceCount) override;
184
185private:
186 bool loadFromFile(const QUrl &source);
187
188private:
189 int m_instanceCount = 0;
190 QByteArray m_instanceData;
191 QFile *m_dataFile = nullptr;
192 bool m_dirty = true;
193 QUrl m_source;
194};
195
196QT_END_NAMESPACE
197
198#endif
static constexpr quint16 currentMajorVersion
\qmltype FileInstancing \inherits Instancing \inqmlmodule QtQuick3D
static QQuick3DInstancing::InstanceTableEntry calculate(const QVector3D &position, const QVector3D &scale, const QVector3D &eulerRotation, const QColor &color, const QVector4D &customData)
static bool writeInstanceTable(QIODevice *out, const QByteArray &instanceData, int instanceCount)