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
capsulegeometry_p.h
Go to the documentation of this file.
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 <QtQuick3DHelpers/qtquick3dhelpersexports.h>
19#include <QQuick3DGeometry>
20#include <QQmlEngine>
21#include <QVector3D>
22
23#if QT_CONFIG(concurrent)
24#include <QFuture>
25#include <QFutureWatcher>
26#endif
27
29
30class Q_QUICK3DHELPERS_EXPORT CapsuleGeometry : public QQuick3DGeometry
31{
32 Q_OBJECT
33 Q_PROPERTY(bool enableNormals READ enableNormals WRITE setEnableNormals NOTIFY enableNormalsChanged)
34 Q_PROPERTY(bool enableUV READ enableUV WRITE setEnableUV NOTIFY enableUVChanged)
35 Q_PROPERTY(int longitudes READ longitudes WRITE setLongitudes NOTIFY longitudesChanged)
36 Q_PROPERTY(int latitudes READ latitudes WRITE setLatitudes NOTIFY latitudesChanged)
37 Q_PROPERTY(int rings READ rings WRITE setRings NOTIFY ringsChanged)
38 Q_PROPERTY(float height READ height WRITE setHeight NOTIFY heightChanged)
39 Q_PROPERTY(float diameter READ diameter WRITE setDiameter NOTIFY diameterChanged)
40 Q_PROPERTY(UVProfile uvProfile READ uvProfile WRITE setUVProfile NOTIFY uvProfileChanged FINAL)
41 Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged)
42 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
43 QML_ELEMENT
44 QML_ADDED_IN_VERSION(6, 10)
45public:
46 enum Status { Null, Ready, Loading, Error };
47 Q_ENUM(Status)
48 enum UVProfile { Fixed, Aspect, Uniform };
49 Q_ENUM(UVProfile)
50
51 explicit CapsuleGeometry(QQuick3DObject *parent = nullptr);
52 ~CapsuleGeometry() override;
53
54 bool enableNormals() const { return m_enableNormals; }
55 void setEnableNormals(bool enable);
56
57 bool enableUV() const { return m_enableUV; }
58 void setEnableUV(bool enable);
59
60 int longitudes() const { return m_longitudes; }
61 void setLongitudes(int longitudes);
62
63 int latitudes() const { return m_latitudes; }
64 void setLatitudes(int latitudes);
65
66 int rings() const { return m_rings; }
67 void setRings(int rings);
68
69 float height() const { return m_height; }
70 void setHeight(float height);
71
72 float diameter() const { return m_diameter; }
73 void setDiameter(float diameter);
74
75 UVProfile uvProfile() const;
76 void setUVProfile(UVProfile newUVProfile);
77
78 bool asynchronous() const;
79 void setAsynchronous(bool newAsynchronous);
80
81 Status status() const;
82
83private Q_SLOTS:
84 void doUpdateGeometry();
85 void requestFinished();
86
87Q_SIGNALS:
88 void enableNormalsChanged();
89 void enableUVChanged();
90 void longitudesChanged();
91 void latitudesChanged();
92 void ringsChanged();
93 void heightChanged();
94 void diameterChanged();
95 void uvProfileChanged();
96 void asynchronousChanged();
97 void statusChanged();
98
99private:
100 struct GeometryData
101 {
102 QByteArray vertexData;
103 QByteArray indexData;
104 QVector3D boundsMin;
105 QVector3D boundsMax;
106 uint32_t stride = 0;
107 uint32_t strideNormal = 0;
108 uint32_t strideUV = 0;
109 bool enableNormals = false;
110 bool enableUV = false;
111 };
112
113 void scheduleGeometryUpdate();
114 void updateGeometry(const GeometryData &geometryData);
115
116 static CapsuleGeometry::GeometryData generateCapsuleGeometry(bool enableNormals,
117 bool enableUV,
118 int longitudes,
119 int latitudes,
120 int rings,
121 float height,
122 float diameter,
123 UVProfile uvProfile);
124#if QT_CONFIG(concurrent)
125 static void generateCapsuleGeometryAsync(QPromise<CapsuleGeometry::GeometryData> &promise,
126 bool enableNormals,
127 bool enableUV,
128 int longitudes,
129 int latitudes,
130 int rings,
131 float height,
132 float diameter,
133 UVProfile uvProfile);
134#endif
135
136 void updateData();
137
138 bool m_enableNormals = true;
139 bool m_enableUV = false;
140
141 int m_longitudes = 32;
142 int m_latitudes = 16;
143 int m_rings = 1;
144 float m_height = 100.f;
145 float m_diameter = 100.f;
146 UVProfile m_uvProfile = UVProfile::Fixed;
147
148 bool m_asynchronous = true;
149 Status m_status = Null;
150#if QT_CONFIG(concurrent)
151 QFuture<GeometryData> m_geometryDataFuture;
152 QFutureWatcher<GeometryData> m_geometryDataWatcher;
153#endif
154 bool m_geometryUpdateRequested = false;
155 bool m_pendingAsyncUpdate = false;
156};
157
158QT_END_NAMESPACE
159
160#endif // PILLGEOMETRY_P_H
#define M_PI
Definition qmath.h:200