| 1 | // Copyright (C) 2024 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef PLANEGEOMETRY_P_H |
| 5 | #define PLANEGEOMETRY_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 | |
| 27 | QT_BEGIN_NAMESPACE |
| 28 | |
| 29 | class PlaneGeometry : public QQuick3DGeometry |
| 30 | { |
| 31 | Q_OBJECT |
| 32 | Q_PROPERTY(float width READ width WRITE setWidth NOTIFY widthChanged FINAL) |
| 33 | Q_PROPERTY(float height READ height WRITE setHeight NOTIFY heightChanged FINAL) |
| 34 | Q_PROPERTY(QSize meshResolution READ meshResolution WRITE setMeshResolution NOTIFY meshResolutionChanged FINAL) |
| 35 | Q_PROPERTY(Plane plane READ plane WRITE setPlane NOTIFY planeChanged FINAL) |
| 36 | Q_PROPERTY(bool reversed READ reversed WRITE setReversed NOTIFY reversedChanged FINAL) |
| 37 | Q_PROPERTY(bool mirrored READ mirrored WRITE setMirrored NOTIFY mirroredChanged 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) |
| 42 | public: |
| 43 | enum Status { Null, Ready, Loading, Error }; |
| 44 | Q_ENUM(Status) |
| 45 | |
| 46 | enum Plane { XY, XZ, ZY }; |
| 47 | Q_ENUM(Plane) |
| 48 | |
| 49 | explicit PlaneGeometry(QQuick3DObject *parent = nullptr); |
| 50 | ~PlaneGeometry() override; |
| 51 | |
| 52 | float width() const; |
| 53 | void setWidth(float newWidth); |
| 54 | float height() const; |
| 55 | void setHeight(float newHeight); |
| 56 | |
| 57 | QSize meshResolution() const; |
| 58 | void setMeshResolution(const QSize &newMeshResolution); |
| 59 | |
| 60 | Plane plane() const; |
| 61 | void setPlane(Plane newPlane); |
| 62 | |
| 63 | bool mirrored() const; |
| 64 | void setMirrored(bool newMirrored); |
| 65 | |
| 66 | bool asynchronous() const; |
| 67 | void setAsynchronous(bool newAsynchronous); |
| 68 | |
| 69 | Status status() const; |
| 70 | |
| 71 | bool reversed() const; |
| 72 | void setReversed(bool newReversed); |
| 73 | |
| 74 | private Q_SLOTS: |
| 75 | void doUpdateGeometry(); |
| 76 | void requestFinished(); |
| 77 | |
| 78 | Q_SIGNALS: |
| 79 | void widthChanged(); |
| 80 | void heightChanged(); |
| 81 | void meshResolutionChanged(); |
| 82 | void planeChanged(); |
| 83 | void mirroredChanged(); |
| 84 | void asynchronousChanged(); |
| 85 | void statusChanged(); |
| 86 | void reversedChanged(); |
| 87 | |
| 88 | private: |
| 89 | struct GeometryData { |
| 90 | QByteArray vertexData; |
| 91 | QByteArray indexData; |
| 92 | QVector3D boundsMin; |
| 93 | QVector3D boundsMax; |
| 94 | }; |
| 95 | |
| 96 | void scheduleGeometryUpdate(); |
| 97 | void updateGeometry(const GeometryData &geometryData); |
| 98 | |
| 99 | static PlaneGeometry::GeometryData generatePlaneGeometry(float width, |
| 100 | float height, |
| 101 | QSize meshResolution, |
| 102 | Plane plane, |
| 103 | bool reversed, |
| 104 | bool mirrored); |
| 105 | #if QT_CONFIG(concurrent) |
| 106 | static void generatePlaneGeometryAsync(QPromise<PlaneGeometry::GeometryData> &promise, |
| 107 | float width, |
| 108 | float height, |
| 109 | QSize meshResolution, |
| 110 | Plane plane, |
| 111 | bool reversed, |
| 112 | bool mirrored); |
| 113 | #endif |
| 114 | float m_width = 100.0f; |
| 115 | float m_height = 100.0f; |
| 116 | QSize m_meshResolution = QSize(2, 2); |
| 117 | Plane m_plane = XY; |
| 118 | bool m_reversed = false; |
| 119 | bool m_mirrored = false; |
| 120 | bool m_asynchronous = true; |
| 121 | Status m_status = Null; |
| 122 | #if QT_CONFIG(concurrent) |
| 123 | QFuture<GeometryData> m_geometryDataFuture; |
| 124 | QFutureWatcher<GeometryData> m_geometryDataWatcher; |
| 125 | #endif |
| 126 | bool m_geometryUpdateRequested = false; |
| 127 | bool m_pendingAsyncUpdate = false; |
| 128 | }; |
| 129 | |
| 130 | QT_END_NAMESPACE |
| 131 | |
| 132 | #endif // PLANEGEOMETRY_P_H |
| 133 | |