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
randominstancing_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists purely as an
9// implementation detail. This header file may change from version to
10// version without notice, or even be removed.
11//
12// We mean it.
13//
14
15#ifndef RANDOMINSTANCING_P_H
16#define RANDOMINSTANCING_P_H
17
18#include <QtQuick3DHelpers/qtquick3dhelpersexports.h>
19#include <QtQuick3D/QQuick3DInstancing>
20
22
24{
25 Q_OBJECT
26
27 QML_ADDED_IN_VERSION(6, 2)
28 Q_PROPERTY(QVariant from READ from WRITE setFrom NOTIFY fromChanged)
29 Q_PROPERTY(QVariant to READ to WRITE setTo NOTIFY toChanged)
30 Q_PROPERTY(bool proportional READ proportional WRITE setProportional NOTIFY proportionalChanged)
31 QML_NAMED_ELEMENT(InstanceRange)
32
33public:
34 explicit QQuick3DInstanceRange(QQuick3DObject *parent = nullptr);
35 ~QQuick3DInstanceRange() override {}
36 QVariant from() const
37 {
38 return m_from;
39 }
40 QVariant to() const
41 {
42 return m_to;
43 }
44
45 bool proportional() const
46 {
47 return m_proportional;
48 }
49
50public Q_SLOTS:
51 void setFrom(QVariant from);
52 void setTo(QVariant to);
53 void setProportional(bool proportional);
54
55Q_SIGNALS:
56 void fromChanged();
57 void toChanged();
58 void proportionalChanged();
59 void changed();
60
61protected:
62 QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *) override
63 {
64 return nullptr;
65 }
66private:
67 QVariant m_from;
68 QVariant m_to;
69 bool m_proportional = false;
70};
71
72class QRandomGenerator;
73class Q_QUICK3DHELPERS_EXPORT QQuick3DRandomInstancing : public QQuick3DInstancing
74{
75 Q_OBJECT
76
77 Q_PROPERTY(int instanceCount READ instanceCount WRITE setInstanceCount NOTIFY instanceCountChanged)
78 Q_PROPERTY(QQuick3DInstanceRange *position READ position WRITE setPosition NOTIFY positionChanged)
79 Q_PROPERTY(QQuick3DInstanceRange *scale READ scale WRITE setScale NOTIFY scaleChanged)
80 Q_PROPERTY(QQuick3DInstanceRange *rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
81 Q_PROPERTY(QQuick3DInstanceRange *color READ color WRITE setColor NOTIFY colorChanged)
82 Q_PROPERTY(ColorModel colorModel READ colorModel WRITE setColorModel NOTIFY colorModelChanged)
83 Q_PROPERTY(QQuick3DInstanceRange *customData READ customData WRITE setCustomData NOTIFY customDataChanged)
84
85 Q_PROPERTY(QVector3D gridSpacing READ gridSpacing WRITE setGridSpacing NOTIFY gridSpacingChanged FINAL REVISION(6, 9))
86
87 Q_PROPERTY(int randomSeed READ randomSeed WRITE setRandomSeed NOTIFY randomSeedChanged)
88
89 QML_NAMED_ELEMENT(RandomInstancing)
90 QML_ADDED_IN_VERSION(6, 2)
91
92public:
93 enum class ColorModel { RGB, HSV, HSL };
94 Q_ENUM(ColorModel)
95
96 explicit QQuick3DRandomInstancing(QQuick3DObject *parent = nullptr);
97 ~QQuick3DRandomInstancing();
98
99 QByteArray getInstanceBuffer(int *instanceCount) override;
100
101 int instanceCount() const
102 {
103 return m_randomCount;
104 }
105
106 int randomSeed() const
107 {
108 return m_randomSeed;
109 }
110
111 QQuick3DInstanceRange *position() const
112 {
113 return m_position;
114 }
115
116 QQuick3DInstanceRange* scale() const
117 {
118 return m_scale;
119 }
120
121 QQuick3DInstanceRange* rotation() const
122 {
123 return m_rotation;
124 }
125
126 QQuick3DInstanceRange* color() const
127 {
128 return m_color;
129 }
130
131 QQuick3DInstanceRange* customData() const
132 {
133 return m_customData;
134 }
135
136 ColorModel colorModel() const
137 {
138 return m_colorModel;
139 }
140
141 QVector3D gridSpacing() const;
142 void setGridSpacing(const QVector3D &newGridSpacing);
143
144public Q_SLOTS:
145 void setInstanceCount(int instanceCount);
146 void setRandomSeed(int randomSeed);
147
148 void setPosition(QQuick3DInstanceRange *position);
149 void setScale(QQuick3DInstanceRange *scale);
150 void setRotation(QQuick3DInstanceRange *rotation);
151 void setColor(QQuick3DInstanceRange *color);
152 void setCustomData(QQuick3DInstanceRange *customData);
153 void setColorModel(ColorModel colorModel);
154
155Q_SIGNALS:
156 void instanceCountChanged();
157 void randomSeedChanged();
158 void positionChanged();
159 void scaleChanged();
160 void rotationChanged();
161 void colorChanged();
162 void customDataChanged();
163 void colorModelChanged();
164
165 void gridSpacingChanged();
166
167private Q_SLOTS:
168 void handleChange();
169
170private:
171 void generateInstanceTable();
172 int m_randomCount = 0;
173 int m_randomSeed = -1;
174 bool m_dirty = true;
175 bool m_gridMode = false;
176 QByteArray m_instanceData;
177 QQuick3DInstanceRange *m_position = nullptr;
178 QQuick3DInstanceRange *m_scale = nullptr;
179 QQuick3DInstanceRange *m_rotation = nullptr;
180 QQuick3DInstanceRange *m_color = nullptr;
181 QQuick3DInstanceRange *m_customData = nullptr;
182 ColorModel m_colorModel = ColorModel::RGB;
183 QVector3D m_gridSpacing;
184};
185QT_END_NAMESPACE
186#endif // RANDOMINSTANCING_P_H
static QVector3D genRandom(const QVector3D &from, const QVector3D &to, bool proportional, QRandomGenerator *rgen)
static float genRandom(float from, float to, QRandomGenerator *rgen)
static QColor genRandom(const QColor &from, const QColor &to, bool proportional, QQuick3DRandomInstancing::ColorModel colorModel, QRandomGenerator *rgen)