1// Copyright (C) 2023 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 PROCEDURALMESH_H
16#define PROCEDURALMESH_H
17
18#include <QQuick3DGeometry>
19#include <QQmlEngine>
20#include <QList>
21#include <QVector3D>
22
23QT_BEGIN_NAMESPACE
24
25class ProceduralMeshSubset : public QObject {
26 Q_OBJECT
27 Q_PROPERTY(unsigned int offset READ offset WRITE setOffset NOTIFY offsetChanged FINAL)
28 Q_PROPERTY(unsigned int count READ count WRITE setCount NOTIFY countChanged FINAL)
29 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged FINAL)
30 QML_NAMED_ELEMENT(ProceduralMeshSubset)
31 QML_ADDED_IN_VERSION(6, 6)
32
33public:
34 int offset() const;
35 void setOffset(int newOffset);
36
37 int count() const;
38 void setCount(int newCount);
39
40 QString name() const;
41 void setName(const QString &newName);
42Q_SIGNALS:
43 void offsetChanged();
44 void countChanged();
45 void nameChanged();
46 void isDirty();
47
48private:
49 int m_offset = 0;
50 int m_count = 0;
51 QString m_name;
52};
53
54class ProceduralMesh : public QQuick3DGeometry
55{
56 Q_OBJECT
57 Q_PROPERTY(QList<QVector3D> positions READ positions WRITE setPositions NOTIFY positionsChanged FINAL)
58 Q_PROPERTY(QList<QVector3D> normals READ normals WRITE setNormals NOTIFY normalsChanged FINAL)
59 Q_PROPERTY(QList<QVector3D> tangents READ tangents WRITE setTangents NOTIFY tangentsChanged FINAL)
60 Q_PROPERTY(QList<QVector3D> binormals READ binormals WRITE setBinormals NOTIFY binormalsChanged FINAL)
61 Q_PROPERTY(QList<QVector2D> uv0s READ uv0s WRITE setUv0s NOTIFY uv0sChanged FINAL)
62 Q_PROPERTY(QList<QVector2D> uv1s READ uv1s WRITE setUv1s NOTIFY uv1sChanged FINAL)
63 Q_PROPERTY(QList<QVector4D> colors READ colors WRITE setColors NOTIFY colorsChanged FINAL)
64 Q_PROPERTY(QList<QVector4D> joints READ joints WRITE setJoints NOTIFY jointsChanged FINAL)
65 Q_PROPERTY(QList<QVector4D> weights READ weights WRITE setWeights NOTIFY weightsChanged FINAL)
66 Q_PROPERTY(QList<unsigned int> indexes READ indexes WRITE setIndexes NOTIFY indexesChanged FINAL)
67 Q_PROPERTY(QQmlListProperty<ProceduralMeshSubset> subsets READ subsets FINAL)
68 Q_PROPERTY(PrimitiveMode primitiveMode READ primitiveMode WRITE setPrimitiveMode NOTIFY primitiveModeChanged FINAL)
69 QML_ELEMENT
70 QML_ADDED_IN_VERSION(6, 6)
71public:
72 enum PrimitiveMode {
73 Points,
74 LineStrip,
75 Lines,
76 TriangleStrip,
77 TriangleFan,
78 Triangles
79 };
80 Q_ENUM(PrimitiveMode)
81
82 ProceduralMesh();
83 QList<QVector3D> positions() const;
84 void setPositions(const QList<QVector3D> &newPositions);
85 PrimitiveMode primitiveMode() const;
86 void setPrimitiveMode(PrimitiveMode newPrimitiveMode);
87
88 QList<unsigned int> indexes() const;
89 void setIndexes(const QList<unsigned int> &newIndexes);
90
91 QList<QVector3D> normals() const;
92 void setNormals(const QList<QVector3D> &newNormals);
93
94 QList<QVector3D> tangents() const;
95 void setTangents(const QList<QVector3D> &newTangents);
96
97 QList<QVector3D> binormals() const;
98 void setBinormals(const QList<QVector3D> &newBinormals);
99
100 QList<QVector2D> uv0s() const;
101 void setUv0s(const QList<QVector2D> &newUv0s);
102
103 QList<QVector2D> uv1s() const;
104 void setUv1s(const QList<QVector2D> &newUv1s);
105
106 QList<QVector4D> colors() const;
107 void setColors(const QList<QVector4D> &newColors);
108
109 QList<QVector4D> joints() const;
110 void setJoints(const QList<QVector4D> &newJoints);
111
112 QList<QVector4D> weights() const;
113 void setWeights(const QList<QVector4D> &newWeights);
114
115 QQmlListProperty<ProceduralMeshSubset> subsets();
116
117Q_SIGNALS:
118 void positionsChanged();
119 void primitiveModeChanged();
120 void indexesChanged();
121 void normalsChanged();
122 void tangentsChanged();
123 void binormalsChanged();
124 void uv0sChanged();
125 void uv1sChanged();
126 void colorsChanged();
127 void jointsChanged();
128 void weightsChanged();
129
130private Q_SLOTS:
131 void requestUpdate();
132 void updateGeometry();
133 void subsetDestroyed(QObject *subset);
134
135private:
136 bool supportsTriangleFanPrimitive() const;
137
138 static void qmlAppendProceduralMeshSubset(QQmlListProperty<ProceduralMeshSubset> *list, ProceduralMeshSubset *subset);
139 static ProceduralMeshSubset *qmlProceduralMeshSubsetAt(QQmlListProperty<ProceduralMeshSubset> *list, qsizetype index);
140 static qsizetype qmlProceduralMeshSubsetCount(QQmlListProperty<ProceduralMeshSubset> *list);
141 static void qmlClearProceduralMeshSubset(QQmlListProperty<ProceduralMeshSubset> *list);
142
143 bool m_updateRequested = false;
144 PrimitiveMode m_primitiveMode = Triangles;
145 QList<QVector3D> m_positions;
146 QList<unsigned int> m_indexes;
147 QList<QVector3D> m_normals;
148 QList<QVector3D> m_tangents;
149 QList<QVector3D> m_binormals;
150 QList<QVector2D> m_uv0s;
151 QList<QVector2D> m_uv1s;
152 QList<QVector4D> m_colors;
153 QList<QVector4D> m_joints;
154 QList<QVector4D> m_weights;
155 QList<ProceduralMeshSubset *> m_subsets;
156};
157
158QT_END_NAMESPACE
159
160#endif // PROCEDURALMESH_H
161

source code of qtquick3d/src/helpers/proceduralmesh_p.h