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