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
cylindergeometry_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 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 <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 CylinderGeometry : public QQuick3DGeometry
31{
32 Q_OBJECT
33 Q_PROPERTY(float radius READ radius WRITE setRadius NOTIFY radiusChanged 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 CylinderGeometry(QQuick3DObject *parent = nullptr);
46 ~CylinderGeometry() override;
47 float radius() const;
48 void setRadius(float newRadius);
49 float length() const;
50 void setLength(float newLength);
51
52 int rings() const;
53 void setRings(int newRings);
54
55 int segments() const;
56 void setSegments(int newSegments);
57
58 bool asynchronous() const;
59 void setAsynchronous(bool newAsynchronous);
60
61 Status status() const;
62
63private Q_SLOTS:
64 void doUpdateGeometry();
65 void requestFinished();
66
67Q_SIGNALS:
68 void radiusChanged();
69 void lengthChanged();
70 void ringsChanged();
71 void segmentsChanged();
72 void asynchronousChanged();
73 void statusChanged();
74
75private:
76 struct GeometryData {
77 QByteArray vertexData;
78 QByteArray indexData;
79 QVector3D boundsMin;
80 QVector3D boundsMax;
81 };
82
83 void scheduleGeometryUpdate();
84 void updateGeometry(const GeometryData &geometryData);
85
86 static CylinderGeometry::GeometryData generateCylinderGeometry(float radius,
87 float length,
88 int rings,
89 int slices);
90#if QT_CONFIG(concurrent)
91 static void generateCylinderGeometryAsync(QPromise<CylinderGeometry::GeometryData> &promise,
92 float radius,
93 float length,
94 int rings,
95 int segments);
96#endif
97
98 float m_radius = 50.0f;
99 float m_length = 100.0f;
100 int m_rings = 0;
101 int m_segments = 20;
102 bool m_asynchronous = true;
103 Status m_status = Null;
104#if QT_CONFIG(concurrent)
105 QFuture<GeometryData> m_geometryDataFuture;
106 QFutureWatcher<GeometryData> m_geometryDataWatcher;
107#endif
108 bool m_geometryUpdateRequested = false;
109 bool m_pendingAsyncUpdate = false;
110};
111
112QT_END_NAMESPACE
113
114#endif // CYLINDERGEOMETRY_P_H
void createCylinderSidesIndices(quint16 *&indicesPtr, int rings, int slices)
void createCylinderDiscVertices(float *&verticesPtr, int slices, double topRadius, double bottomRadius, double length, double yPosition)
void createCylinderSidesVertices(float *&verticesPtr, int rings, int slices, double topRadius, double bottomRadius, double length)
void createCylinderDiscIndices(quint16 *&indicesPtr, int discCenterIndex, int slices, bool isTopCap)