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
spheregeometry_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 SPHEREGEOMETRY_P_H
5#define SPHEREGEOMETRY_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 SphereGeometry : public QQuick3DGeometry
31{
32 Q_OBJECT
33 Q_PROPERTY(float radius READ radius WRITE setRadius NOTIFY radiusChanged 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 SphereGeometry(QQuick3DObject *parent = nullptr);
45 ~SphereGeometry() override;
46 float radius() const;
47 void setRadius(float newRadius);
48 int rings() const;
49 void setRings(int newRings);
50
51 int segments() const;
52 void setSegments(int newSegments);
53
54 bool asynchronous() const;
55 void setAsynchronous(bool newAsynchronous);
56
57 Status status() const;
58
59private Q_SLOTS:
60 void doUpdateGeometry();
61 void requestFinished();
62
63Q_SIGNALS:
64 void radiusChanged();
65 void ringsChanged();
66 void segmentsChanged();
67 void asynchronousChanged();
68 void statusChanged();
69
70private:
71 struct GeometryData {
72 QByteArray vertexData;
73 QByteArray indexData;
74 QVector3D boundsMin;
75 QVector3D boundsMax;
76 };
77
78 void scheduleGeometryUpdate();
79 void updateGeometry(const GeometryData &geometryData);
80
81 static SphereGeometry::GeometryData generateSphereGeometry(float radius,
82 int rings,
83 int segments);
84#if QT_CONFIG(concurrent)
85 static void generateSphereGeometryAsync(QPromise<SphereGeometry::GeometryData> &promise,
86 float radius,
87 int rings,
88 int segments);
89#endif
90
91 float m_radius = 100.0f;
92 int m_rings = 16;
93 int m_segments = 32;
94 bool m_asynchronous = true;
95 Status m_status = Null;
96#if QT_CONFIG(concurrent)
97 QFuture<GeometryData> m_geometryDataFuture;
98 QFutureWatcher<GeometryData> m_geometryDataWatcher;
99#endif
100 bool m_geometryUpdateRequested = false;
101 bool m_pendingAsyncUpdate = false;
102};
103
104QT_END_NAMESPACE
105
106#endif // SPHEREGEOMETRY_P_H