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

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