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