1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef Q_QUICK3D_GEOMETRY_H
5#define Q_QUICK3D_GEOMETRY_H
6
7#include <QtQuick3D/qquick3dobject.h>
8
9QT_BEGIN_NAMESPACE
10
11class QQuick3DGeometryPrivate;
12
13class Q_QUICK3D_EXPORT QQuick3DGeometry : public QQuick3DObject
14{
15 Q_OBJECT
16 Q_DECLARE_PRIVATE(QQuick3DGeometry)
17
18 QML_NAMED_ELEMENT(Geometry)
19 QML_UNCREATABLE("Geometry is Abstract")
20public:
21 explicit QQuick3DGeometry(QQuick3DObject *parent = nullptr);
22 ~QQuick3DGeometry() override;
23
24 enum class PrimitiveType {
25 Points,
26 LineStrip,
27 Lines,
28 TriangleStrip,
29 TriangleFan,
30 Triangles
31 };
32
33 struct Attribute {
34 enum Semantic {
35 IndexSemantic,
36 PositionSemantic, // attr_pos
37 NormalSemantic, // attr_norm
38 TexCoordSemantic, // attr_uv0
39 TangentSemantic, // attr_textan
40 BinormalSemantic, // attr_binormal
41 JointSemantic, // attr_joints
42 WeightSemantic, // attr_weights
43 ColorSemantic, // attr_color
44 TargetPositionSemantic, // attr_tpos0
45 TargetNormalSemantic, // attr_tnorm0
46 TargetTangentSemantic, // attr_ttan0
47 TargetBinormalSemantic, // attr_tbinorm0
48 TexCoord1Semantic, // attr_uv1
49 TexCoord0Semantic = TexCoordSemantic // for compatibility
50 };
51 enum ComponentType {
52 U16Type,
53 U32Type,
54 I32Type,
55 F32Type
56 };
57 Semantic semantic = PositionSemantic;
58 int offset = -1;
59 ComponentType componentType = F32Type;
60 };
61
62 struct TargetAttribute {
63 quint32 targetId = 0;
64 Attribute attr;
65 int stride = 0;
66 };
67
68 QByteArray vertexData() const;
69 QByteArray indexData() const;
70 int attributeCount() const;
71 Attribute attribute(int index) const;
72 PrimitiveType primitiveType() const;
73 QVector3D boundsMin() const;
74 QVector3D boundsMax() const;
75 int stride() const;
76
77 void setVertexData(const QByteArray &data);
78 void setVertexData(int offset, const QByteArray &data);
79 void setIndexData(const QByteArray &data);
80 void setIndexData(int offset, const QByteArray &data);
81 void setStride(int stride);
82 void setBounds(const QVector3D &min, const QVector3D &max);
83 void setPrimitiveType(PrimitiveType type);
84
85 void addAttribute(Attribute::Semantic semantic, int offset,
86 Attribute::ComponentType componentType);
87 void addAttribute(const Attribute &att);
88
89 Q_REVISION(6, 3) int subsetCount() const;
90 Q_REVISION(6, 3) QVector3D subsetBoundsMin(int subset) const;
91 Q_REVISION(6, 3) QVector3D subsetBoundsMax(int subset) const;
92 Q_REVISION(6, 3) int subsetOffset(int subset) const;
93 Q_REVISION(6, 3) int subsetCount(int subset) const;
94 Q_REVISION(6, 3) QString subsetName(int subset) const;
95 Q_REVISION(6, 3) void addSubset(int offset, int count, const QVector3D &boundsMin, const QVector3D &boundsMax, const QString &name = {});
96
97 Q_REVISION(6, 6) QByteArray targetData() const;
98 Q_REVISION(6, 6) void setTargetData(const QByteArray &data);
99 Q_REVISION(6, 6) void setTargetData(int offset, const QByteArray &data);
100 Q_REVISION(6, 6) TargetAttribute targetAttribute(int index) const;
101 Q_REVISION(6, 6) int targetAttributeCount() const;
102 Q_REVISION(6, 6) void addTargetAttribute(quint32 targetId,
103 Attribute::Semantic semantic, int offset,
104 int stride = 0);
105 Q_REVISION(6, 6) void addTargetAttribute(const TargetAttribute &att);
106
107 void clear();
108
109Q_SIGNALS:
110 void geometryNodeDirty();
111
112protected:
113 QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override;
114 void markAllDirty() override;
115};
116
117QT_END_NAMESPACE
118
119#endif // Q_QUICK3D_GEOMETRY_H
120

source code of qtquick3d/src/quick3d/qquick3dgeometry.h