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