1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef CUBOIDGEOMETRY_P_H
5#define CUBOIDGEOMETRY_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 CuboidGeometry : public QQuick3DGeometry
30{
31 Q_OBJECT
32 Q_PROPERTY(float xExtent READ xExtent WRITE setXExtent NOTIFY xExtentChanged FINAL)
33 Q_PROPERTY(float yExtent READ yExtent WRITE setYExtent NOTIFY yExtentChanged FINAL)
34 Q_PROPERTY(float zExtent READ zExtent WRITE setZExtent NOTIFY zExtentChanged FINAL)
35 Q_PROPERTY(QSize yzMeshResolution READ yzMeshResolution WRITE setYzMeshResolution NOTIFY yzMeshResolutionChanged FINAL)
36 Q_PROPERTY(QSize xzMeshResolution READ xzMeshResolution WRITE setXzMeshResolution NOTIFY xzMeshResolutionChanged FINAL)
37 Q_PROPERTY(QSize xyMeshResolution READ xyMeshResolution WRITE setXyMeshResolution NOTIFY xyMeshResolutionChanged 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 CuboidGeometry(QQuick3DObject *parent = nullptr);
47 ~CuboidGeometry() override;
48 float xExtent() const;
49 void setXExtent(float newXExtent);
50 float yExtent() const;
51 void setYExtent(float newYExtent);
52
53 float zExtent() const;
54 void setZExtent(float newZExtent);
55
56 QSize yzMeshResolution() const;
57 void setYzMeshResolution(const QSize &newYzMeshResolution);
58
59 QSize xzMeshResolution() const;
60 void setXzMeshResolution(const QSize &newXzMeshResolution);
61
62 QSize xyMeshResolution() const;
63 void setXyMeshResolution(const QSize &newXyMeshResolution);
64
65 bool asynchronous() const;
66 void setAsynchronous(bool newAsynchronous);
67
68 Status status() const;
69
70private Q_SLOTS:
71 void doUpdateGeometry();
72 void requestFinished();
73
74Q_SIGNALS:
75 void xExtentChanged();
76 void yExtentChanged();
77 void zExtentChanged();
78 void yzMeshResolutionChanged();
79 void xzMeshResolutionChanged();
80 void xyMeshResolutionChanged();
81 void asynchronousChanged();
82 void statusChanged();
83
84private:
85 struct GeometryData {
86 QByteArray vertexData;
87 QByteArray indexData;
88 QVector3D boundsMin;
89 QVector3D boundsMax;
90 };
91
92 void scheduleGeometryUpdate();
93 void updateGeometry(const GeometryData &geometryData);
94
95 static CuboidGeometry::GeometryData generateCuboidGeometry(float xExtent,
96 float yExtent,
97 float zExtent,
98 QSize yzMeshResolution,
99 QSize xzMeshResolution,
100 QSize xyMeshResolution);
101#if QT_CONFIG(concurrent)
102 static void generateCuboidGeometryAsync(QPromise<CuboidGeometry::GeometryData> &promise,
103 float xExtent,
104 float yExtent,
105 float zExtent,
106 QSize yzMeshResolution,
107 QSize xzMeshResolution,
108 QSize xyMeshResolution);
109#endif
110
111 float m_xExtent = 100.0f;
112 float m_yExtent = 100.0f;
113 float m_zExtent = 100.0f;
114 QSize m_yzMeshResolution = QSize(2, 2);
115 QSize m_xzMeshResolution = QSize(2, 2);
116 QSize m_xyMeshResolution = QSize(2, 2);
117 bool m_asynchronous = true;
118 Status m_status = Null;
119#if QT_CONFIG(concurrent)
120 QFuture<GeometryData> m_geometryDataFuture;
121 QFutureWatcher<GeometryData> m_geometryDataWatcher;
122#endif
123 bool m_geometryUpdateRequested = false;
124 bool m_pendingAsyncUpdate = false;
125};
126
127QT_END_NAMESPACE
128
129#endif // CUBOIDGEOMETRY_P_H
130

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