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