Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
24
36
37class Q_QUICK3D_EXPORT QQuick3DInstanceListEntry : public QQuick3DObject
38{
40
42 Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
43 Q_PROPERTY(QVector3D scale READ scale WRITE setScale NOTIFY scaleChanged)
44 Q_PROPERTY(QVector3D eulerRotation READ eulerRotation WRITE setEulerRotation NOTIFY eulerRotationChanged)
45 Q_PROPERTY(QQuaternion rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
47 Q_PROPERTY(QVector4D customData READ customData WRITE setCustomData NOTIFY customDataChanged)
48 QML_NAMED_ELEMENT(InstanceListEntry)
49
50public:
53
55 {
56 return m_position;
57 }
59 {
60 return m_scale;
61 }
62
64 {
65 return m_eulerRotation;
66 }
67
69 {
70 return m_rotation;
71 }
72
73 QColor color() const
74 {
75 return m_color;
76 }
77
79 {
80 return m_customData;
81 }
82
83public Q_SLOTS:
85 void setScale(QVector3D scale);
86 void setEulerRotation(QVector3D eulerRotation);
87 void setRotation(QQuaternion rotation);
88 void setColor(QColor color);
89 void setCustomData(QVector4D customData);
90
98 void changed();
99
100protected:
102 {
103 return nullptr;
104 }
105
106private:
107 QVector3D m_position;
108 QVector3D m_scale = {1, 1, 1};
109 QVector3D m_eulerRotation;
110 QQuaternion m_rotation;
111 QColor m_color = Qt::white;
112 QVector4D m_customData;
113 bool m_useEulerRotation = true;
115};
116
117class Q_QUICK3D_EXPORT QQuick3DInstanceList : public QQuick3DInstancing
118{
120 Q_PROPERTY(QQmlListProperty<QQuick3DInstanceListEntry> instances READ instances)
121 Q_PROPERTY(int instanceCount READ instanceCount NOTIFY instanceCountChanged)
122 QML_NAMED_ELEMENT(InstanceList)
124
125 Q_CLASSINFO("DefaultProperty", "instances")
126
127public:
129 ~QQuick3DInstanceList() override;
130
131 QByteArray getInstanceBuffer(int *instanceCount) override;
133 int instanceCount() const;
134
136 void instanceCountChanged();
137
139 void handleInstanceChange();
140 void onInstanceDestroyed(QObject *object);
141
142private:
143 void generateInstanceData();
144
145 static void qmlAppendInstanceListEntry(QQmlListProperty<QQuick3DInstanceListEntry> *list, QQuick3DInstanceListEntry *material);
147 static qsizetype qmlInstanceListEntriesCount(QQmlListProperty<QQuick3DInstanceListEntry> *list);
148 static void qmlClearInstanceListEntries(QQmlListProperty<QQuick3DInstanceListEntry> *list);
149
150 bool m_dirty = true;
151 QByteArray m_instanceData;
152 QList<QQuick3DInstanceListEntry *> m_instances;
153};
154
155class Q_QUICK3D_EXPORT QQuick3DFileInstancing : public QQuick3DInstancing
156{
158 QML_NAMED_ELEMENT(FileInstancing)
160 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
161 Q_PROPERTY(int instanceCount READ instanceCount NOTIFY instanceCountChanged)
162
163public:
165 ~QQuick3DFileInstancing() override;
166
167 const QUrl &source() const;
168 void setSource(const QUrl &newSource);
169
170 bool loadFromBinaryFile(const QString &filename);
171 bool loadFromXmlFile(const QString &filename);
172 int writeToBinaryFile(QIODevice *out);
173
174 int instanceCount() const;
175
177 void instanceCountChanged();
178 void sourceChanged();
179
180protected:
181 QByteArray getInstanceBuffer(int *instanceCount) override;
182
183private:
184 bool loadFromFile(const QUrl &source);
185
186private:
187 int m_instanceCount = 0;
188 QByteArray m_instanceData;
189 QFile *m_dataFile = nullptr;
190 bool m_dirty = true;
191 QUrl m_source;
192};
193
195
196#endif
\inmodule QtCore
Definition qbytearray.h:57
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtCore
Definition qfile.h:93
\inmodule QtCore \reentrant
Definition qiodevice.h:34
Definition qlist.h:76
\inmodule QtCore
Definition qobject.h:103
The QQmlListProperty class allows applications to expose list-like properties of QObject-derived clas...
Definition qqmllist.h:24
The QQuaternion class represents a quaternion consisting of a vector and scalar.
QSSGRenderGraphObject * updateSpatialNode(QSSGRenderGraphObject *) override
\inmodule QtQuick3D \inherits QQuick3DObject
\qmltype Object3D \inqmlmodule QtQuick3D \instantiates QQuick3DObject \inherits QtObject
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
The QVector4D class represents a vector or vertex in 4D space.
Definition qvectornd.h:330
void colorChanged()
Combined button and popup list for selecting options.
@ white
Definition qnamespace.h:31
static int instanceCount
n void setPosition(void) \n\
GLuint index
[2]
GLuint color
[2]
GLsizei GLsizei GLchar * source
GLenum GLenum GLenum GLenum GLenum scale
#define QML_NAMED_ELEMENT(NAME)
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_CLASSINFO(name, value)
#define Q_SLOTS
#define Q_SIGNALS
ptrdiff_t qsizetype
Definition qtypes.h:165
#define explicit
QList< int > list
[14]
QTextStream out(stdout)
[7]
myFilter setColor(QColor(128, 0, 0))