1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef CYLINDERGEOMETRY_P_H
5#define CYLINDERGEOMETRY_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 CylinderGeometry : public QQuick3DGeometry
30{
31 Q_OBJECT
32 Q_PROPERTY(float radius READ radius WRITE setRadius NOTIFY radiusChanged FINAL)
33 Q_PROPERTY(float length READ length WRITE setLength NOTIFY lengthChanged FINAL)
34 Q_PROPERTY(int rings READ rings WRITE setRings NOTIFY ringsChanged FINAL)
35 Q_PROPERTY(int segments READ segments WRITE setSegments NOTIFY segmentsChanged FINAL)
36 Q_PROPERTY(bool asynchronous READ asynchronous WRITE setAsynchronous NOTIFY asynchronousChanged)
37 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
38 QML_ELEMENT
39 QML_ADDED_IN_VERSION(6, 9)
40public:
41 enum Status { Null, Ready, Loading, Error };
42 Q_ENUM(Status)
43
44 explicit CylinderGeometry(QQuick3DObject *parent = nullptr);
45 ~CylinderGeometry() override;
46 float radius() const;
47 void setRadius(float newRadius);
48 float length() const;
49 void setLength(float newLength);
50
51 int rings() const;
52 void setRings(int newRings);
53
54 int segments() const;
55 void setSegments(int newSegments);
56
57 bool asynchronous() const;
58 void setAsynchronous(bool newAsynchronous);
59
60 Status status() const;
61
62private Q_SLOTS:
63 void doUpdateGeometry();
64 void requestFinished();
65
66Q_SIGNALS:
67 void radiusChanged();
68 void lengthChanged();
69 void ringsChanged();
70 void segmentsChanged();
71 void asynchronousChanged();
72 void statusChanged();
73
74private:
75 struct GeometryData {
76 QByteArray vertexData;
77 QByteArray indexData;
78 QVector3D boundsMin;
79 QVector3D boundsMax;
80 };
81
82 void scheduleGeometryUpdate();
83 void updateGeometry(const GeometryData &geometryData);
84
85 static CylinderGeometry::GeometryData generateCylinderGeometry(float radius,
86 float length,
87 int rings,
88 int slices);
89#if QT_CONFIG(concurrent)
90 static void generateCylinderGeometryAsync(QPromise<CylinderGeometry::GeometryData> &promise,
91 float radius,
92 float length,
93 int rings,
94 int segments);
95#endif
96
97 float m_radius = 50.0f;
98 float m_length = 100.0f;
99 int m_rings = 0;
100 int m_segments = 20;
101 bool m_asynchronous = true;
102 Status m_status = Null;
103#if QT_CONFIG(concurrent)
104 QFuture<GeometryData> m_geometryDataFuture;
105 QFutureWatcher<GeometryData> m_geometryDataWatcher;
106#endif
107 bool m_geometryUpdateRequested = false;
108 bool m_pendingAsyncUpdate = false;
109};
110
111QT_END_NAMESPACE
112
113#endif // CYLINDERGEOMETRY_P_H
114

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