1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef TORUSGEOMETRY_P_H
5#define TORUSGEOMETRY_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 TorusGeometry : public QQuick3DGeometry
30{
31 Q_OBJECT
32 Q_PROPERTY(int rings READ rings WRITE setRings NOTIFY ringsChanged FINAL)
33 Q_PROPERTY(int segments READ segments WRITE setSegments NOTIFY segmentsChanged FINAL)
34 Q_PROPERTY(float radius READ radius WRITE setRadius NOTIFY radiusChanged FINAL)
35 Q_PROPERTY(float tubeRadius READ tubeRadius WRITE setTubeRadius NOTIFY tubeRadiusChanged 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 explicit TorusGeometry(QQuick3DObject *parent = nullptr);
44 ~TorusGeometry() override;
45
46 int rings() const;
47 void setRings(int newRings);
48 int segments() const;
49 void setSegments(int newSegments);
50
51 float radius() const;
52 void setRadius(float newRadius);
53
54 float tubeRadius() const;
55 void setTubeRadius(float newTubeRadius);
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 ringsChanged();
68 void segmentsChanged();
69 void radiusChanged();
70 void tubeRadiusChanged();
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 TorusGeometry::GeometryData generateTorusGeometry(int rings,
86 int segments,
87 float radius,
88 float tubeRadius);
89#if QT_CONFIG(concurrent)
90 static void generateTorusGeometryAsync(QPromise<TorusGeometry::GeometryData> &promise,
91 int rings,
92 int segments,
93 float radius,
94 float tubeRadius);
95#endif
96
97 int m_rings = 50;
98 int m_segments = 50;
99 float m_radius = 100.0f;
100 float m_tubeRadius = 10.0f;
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 // TORUSGEOMETRY_P_H
114

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