1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef PILLGEOMETRY_P_H
5#define PILLGEOMETRY_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QQuick3DGeometry>
19#include <QQmlEngine>
20#include <QVector3D>
21
22#if QT_CONFIG(concurrent)
23#include <QFuture>
24#include <QFutureWatcher>
25#endif
26
27QT_BEGIN_NAMESPACE
28
29class CapsuleGeometry : public QQuick3DGeometry
30{
31 Q_OBJECT
32 Q_PROPERTY(bool enableNormals READ enableNormals WRITE setEnableNormals NOTIFY enableNormalsChanged)
33 Q_PROPERTY(bool enableUV READ enableUV WRITE setEnableUV NOTIFY enableUVChanged)
34 Q_PROPERTY(int longitudes READ longitudes WRITE setLongitudes NOTIFY longitudesChanged)
35 Q_PROPERTY(int latitudes READ latitudes WRITE setLatitudes NOTIFY latitudesChanged)
36 Q_PROPERTY(int rings READ rings WRITE setRings NOTIFY ringsChanged)
37 Q_PROPERTY(float height READ height WRITE setHeight NOTIFY heightChanged)
38 Q_PROPERTY(float diameter READ diameter WRITE setDiameter NOTIFY diameterChanged)
39 Q_PROPERTY(UVProfile uvProfile READ uvProfile WRITE setUVProfile NOTIFY uvProfileChanged FINAL)
40 Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged)
41 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
42 QML_ELEMENT
43 QML_ADDED_IN_VERSION(6, 10)
44public:
45 enum Status { Null, Ready, Loading, Error };
46 Q_ENUM(Status)
47 enum UVProfile { Fixed, Aspect, Uniform };
48 Q_ENUM(UVProfile)
49
50 explicit CapsuleGeometry(QQuick3DObject *parent = nullptr);
51 ~CapsuleGeometry() override;
52
53 bool enableNormals() const { return m_enableNormals; }
54 void setEnableNormals(bool enable);
55
56 bool enableUV() const { return m_enableUV; }
57 void setEnableUV(bool enable);
58
59 int longitudes() const { return m_longitudes; }
60 void setLongitudes(int longitudes);
61
62 int latitudes() const { return m_latitudes; }
63 void setLatitudes(int latitudes);
64
65 int rings() const { return m_rings; }
66 void setRings(int rings);
67
68 float height() const { return m_height; }
69 void setHeight(float height);
70
71 float diameter() const { return m_diameter; }
72 void setDiameter(float diameter);
73
74 UVProfile uvProfile() const;
75 void setUVProfile(UVProfile newUVProfile);
76
77 bool asynchronous() const;
78 void setAsynchronous(bool newAsynchronous);
79
80 Status status() const;
81
82private Q_SLOTS:
83 void doUpdateGeometry();
84 void requestFinished();
85
86Q_SIGNALS:
87 void enableNormalsChanged();
88 void enableUVChanged();
89 void longitudesChanged();
90 void latitudesChanged();
91 void ringsChanged();
92 void heightChanged();
93 void diameterChanged();
94 void uvProfileChanged();
95 void asynchronousChanged();
96 void statusChanged();
97
98private:
99 struct GeometryData
100 {
101 QByteArray vertexData;
102 QByteArray indexData;
103 QVector3D boundsMin;
104 QVector3D boundsMax;
105 uint32_t stride = 0;
106 uint32_t strideNormal = 0;
107 uint32_t strideUV = 0;
108 bool enableNormals = false;
109 bool enableUV = false;
110 };
111
112 void scheduleGeometryUpdate();
113 void updateGeometry(const GeometryData &geometryData);
114
115 static CapsuleGeometry::GeometryData generateCapsuleGeometry(bool enableNormals,
116 bool enableUV,
117 int longitudes,
118 int latitudes,
119 int rings,
120 float height,
121 float diameter,
122 UVProfile uvProfile);
123#if QT_CONFIG(concurrent)
124 static void generateCapsuleGeometryAsync(QPromise<CapsuleGeometry::GeometryData> &promise,
125 bool enableNormals,
126 bool enableUV,
127 int longitudes,
128 int latitudes,
129 int rings,
130 float height,
131 float diameter,
132 UVProfile uvProfile);
133#endif
134
135 void updateData();
136
137 bool m_enableNormals = true;
138 bool m_enableUV = false;
139
140 int m_longitudes = 32;
141 int m_latitudes = 16;
142 int m_rings = 1;
143 float m_height = 100.f;
144 float m_diameter = 100.f;
145 UVProfile m_uvProfile = UVProfile::Fixed;
146
147 bool m_asynchronous = true;
148 Status m_status = Null;
149#if QT_CONFIG(concurrent)
150 QFuture<GeometryData> m_geometryDataFuture;
151 QFutureWatcher<GeometryData> m_geometryDataWatcher;
152#endif
153 bool m_geometryUpdateRequested = false;
154 bool m_pendingAsyncUpdate = false;
155};
156
157QT_END_NAMESPACE
158
159#endif // PILLGEOMETRY_P_H
160

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