aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick3d/qquick3dgeometry.h
blob: 2ae3f4b9c6e907cbb8e48ae0eaeddc8780e84089 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#ifndef Q_QUICK3D_GEOMETRY_H
#define Q_QUICK3D_GEOMETRY_H

#include <QtQuick3D/qquick3dobject.h>

QT_BEGIN_NAMESPACE

class QQuick3DGeometryPrivate;

class Q_QUICK3D_EXPORT QQuick3DGeometry : public QQuick3DObject
{
    Q_OBJECT
    Q_DECLARE_PRIVATE(QQuick3DGeometry)

    QML_NAMED_ELEMENT(Geometry)
    QML_UNCREATABLE("Geometry is Abstract")
public:
    explicit QQuick3DGeometry(QQuick3DObject *parent = nullptr);
    ~QQuick3DGeometry() override;

    enum class PrimitiveType {
        Points,
        LineStrip,
        Lines,
        TriangleStrip,
        TriangleFan,
        Triangles
    };

    struct Attribute {
        enum Semantic {
            IndexSemantic,
            PositionSemantic,                     // attr_pos
            NormalSemantic,                       // attr_norm
            TexCoordSemantic,                     // attr_uv0
            TangentSemantic,                      // attr_textan
            BinormalSemantic,                     // attr_binormal
            JointSemantic,                        // attr_joints
            WeightSemantic,                       // attr_weights
            ColorSemantic,                        // attr_color
            TargetPositionSemantic,               // attr_tpos0
            TargetNormalSemantic,                 // attr_tnorm0
            TargetTangentSemantic,                // attr_ttan0
            TargetBinormalSemantic,               // attr_tbinorm0
            TexCoord1Semantic,                    // attr_uv1
            TexCoord0Semantic = TexCoordSemantic  // for compatibility
        };
        enum ComponentType {
            U16Type,
            U32Type,
            I32Type,
            F32Type
        };
        Semantic semantic = PositionSemantic;
        int offset = -1;
        ComponentType componentType = F32Type;
    };

    struct TargetAttribute {
        quint32 targetId = 0;
        Attribute attr;
        int stride = 0;
    };

    QByteArray vertexData() const;
    QByteArray indexData() const;
    int attributeCount() const;
    Attribute attribute(int index) const;
    PrimitiveType primitiveType() const;
    QVector3D boundsMin() const;
    QVector3D boundsMax() const;
    int stride() const;

    void setVertexData(const QByteArray &data);
    void setVertexData(int offset, const QByteArray &data);
    void setIndexData(const QByteArray &data);
    void setIndexData(int offset, const QByteArray &data);
    void setStride(int stride);
    void setBounds(const QVector3D &min, const QVector3D &max);
    void setPrimitiveType(PrimitiveType type);

    void addAttribute(Attribute::Semantic semantic, int offset,
                      Attribute::ComponentType componentType);
    void addAttribute(const Attribute &att);

    Q_REVISION(6, 3) int subsetCount() const;
    Q_REVISION(6, 3) QVector3D subsetBoundsMin(int subset) const;
    Q_REVISION(6, 3) QVector3D subsetBoundsMax(int subset) const;
    Q_REVISION(6, 3) int subsetOffset(int subset) const;
    Q_REVISION(6, 3) int subsetCount(int subset) const;
    Q_REVISION(6, 3) QString subsetName(int subset) const;
    Q_REVISION(6, 3) void addSubset(int offset, int count, const QVector3D &boundsMin, const QVector3D &boundsMax, const QString &name = {});

    Q_REVISION(6, 6) QByteArray targetData() const;
    Q_REVISION(6, 6) void setTargetData(const QByteArray &data);
    Q_REVISION(6, 6) void setTargetData(int offset, const QByteArray &data);
    Q_REVISION(6, 6) TargetAttribute targetAttribute(int index) const;
    Q_REVISION(6, 6) int targetAttributeCount() const;
    Q_REVISION(6, 6) void addTargetAttribute(quint32 targetId,
                                             Attribute::Semantic semantic, int offset,
                                             int stride = 0);
    Q_REVISION(6, 6) void addTargetAttribute(const TargetAttribute &att);

    void clear();

Q_SIGNALS:
    void geometryNodeDirty();
    Q_REVISION(6, 7) void geometryChanged();

protected:
    QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override;
    void markAllDirty() override;
};

QT_END_NAMESPACE

#endif // Q_QUICK3D_GEOMETRY_H