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