1 | // Copyright (C) 2024 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QQUICK3DXRANCHORMANAGER_OPENXR_P_H |
5 | #define QQUICK3DXRANCHORMANAGER_OPENXR_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 <openxr/openxr.h> |
19 | |
20 | #if __has_include(<openxr/fb_spatial_entity.h>) && __has_include(<openxr/fb_scene.h>) |
21 | #include <openxr/fb_spatial_entity.h> |
22 | #if __has_include(<openxr/fb_spatial_entity_query.h>) && __has_include(<openxr/fb_spatial_entity_storage.h>) && __has_include(<openxr/fb_spatial_entity_container.h>) |
23 | #include <openxr/fb_spatial_entity_query.h> |
24 | #include <openxr/fb_spatial_entity_storage.h> |
25 | #include <openxr/fb_spatial_entity_container.h> |
26 | #endif |
27 | #include <openxr/fb_scene.h> |
28 | #if __has_include(<openxr/fb_scene_capture.h>) |
29 | #include <openxr/fb_scene_capture.h> |
30 | #endif |
31 | #endif |
32 | // Otherwise, these may be all provided in openxr.h, if it is new enough, no |
33 | // need for the Mobile SDK specific headers anymore. If that's not the case |
34 | // (too old openxr.h), compilation will fail. |
35 | |
36 | #include <QList> |
37 | #include <QSet> |
38 | #include <QUuid> |
39 | |
40 | #include <QObject> |
41 | |
42 | #include <QtQuick3DXr/private/qtquick3dxrglobal_p.h> |
43 | |
44 | QT_BEGIN_NAMESPACE |
45 | |
46 | class QQuick3DXrSpatialAnchor; |
47 | |
48 | class QQuick3DXrAnchorManager : public QObject |
49 | { |
50 | Q_OBJECT |
51 | public: |
52 | static QQuick3DXrAnchorManager* instance(); |
53 | |
54 | void initialize(XrInstance instance, XrSession session); |
55 | void teardown(); |
56 | |
57 | QList<const char*> requiredExtensions() const; |
58 | |
59 | void handleEvent(const XrEventDataBaseHeader* event); |
60 | |
61 | void requestSceneCapture(); |
62 | bool queryAllAnchors(); |
63 | const QList<QQuick3DXrSpatialAnchor *> &anchors() const; |
64 | qsizetype anchorCount() const; |
65 | |
66 | void updateAnchors(XrTime predictedDisplayTime, XrSpace appSpace); |
67 | QString getSemanticLabels(const XrSpace space); |
68 | QSet<QUuid> collectRoomLayoutUuids(XrSpace space); |
69 | QSet<QUuid> collectSpaceContainerUuids(XrSpace space); |
70 | |
71 | bool isComponentSupported(XrSpace space, XrSpaceComponentTypeFB type); |
72 | bool isComponentEnabled(XrSpace space, XrSpaceComponentTypeFB type); |
73 | |
74 | bool getBoundingBox3D(XrSpace space, QVector3D &offset, QVector3D &extent); |
75 | bool getBoundingBox2D(XrSpace space, QVector2D &offset, QVector2D &extent); |
76 | |
77 | bool setupSpatialAnchor(XrSpace space, QQuick3DXrSpatialAnchor &anchor); |
78 | |
79 | Q_SIGNALS: |
80 | void anchorAdded(QQuick3DXrSpatialAnchor* anchor); |
81 | void anchorRemoved(QUuid uuid); |
82 | void anchorUpdated(QQuick3DXrSpatialAnchor *anchor); |
83 | void sceneCaptureCompleted(); |
84 | |
85 | private: |
86 | QQuick3DXrAnchorManager(); |
87 | ~QQuick3DXrAnchorManager(); |
88 | |
89 | XrInstance m_instance{XR_NULL_HANDLE}; |
90 | XrSession m_session{XR_NULL_HANDLE}; |
91 | |
92 | [[nodiscard]] bool checkXrResult(const XrResult &result); |
93 | bool resolveXrFunction(const char *name, PFN_xrVoidFunction *function); |
94 | |
95 | bool queryAllAnchorsWithSpecificComponentEnabled(const XrSpaceComponentTypeFB componentType); |
96 | bool queryAnchorsByUuids(const QSet<QUuid>& uuidSet); |
97 | |
98 | void addAnchor(XrSpace space, XrUuidEXT uuid); |
99 | |
100 | // API Wrappers |
101 | XrResult enumerateSpaceSupportedComponents(XrSpace space, |
102 | uint32_t componentTypeCapacityInput, |
103 | uint32_t* componentTypeCountOutput, |
104 | XrSpaceComponentTypeFB* componentTypes); |
105 | XrResult getSpaceComponentStatus(XrSpace space, |
106 | XrSpaceComponentTypeFB componentType, |
107 | XrSpaceComponentStatusFB* status); |
108 | XrResult setSpaceComponentStatus(XrSpace space, |
109 | const XrSpaceComponentStatusSetInfoFB* info, |
110 | XrAsyncRequestIdFB* requestId); |
111 | XrResult getSpaceUuid(XrSpace space, XrUuidEXT *uuid); |
112 | XrResult (const XrSpaceQueryInfoBaseHeaderFB* info, XrAsyncRequestIdFB* requestId); |
113 | XrResult retrieveSpaceQueryResults(XrAsyncRequestIdFB requestId, XrSpaceQueryResultsFB* results); |
114 | XrResult getSpaceBoundingBox2D(XrSpace space, XrRect2Df* boundingBox2DOutput); |
115 | XrResult getSpaceBoundingBox3D(XrSpace space, XrRect3DfFB* boundingBox3DOutput); |
116 | XrResult getSpaceSemanticLabels(XrSpace space, XrSemanticLabelsFB* semanticLabelsOutput); |
117 | XrResult getSpaceBoundary2D(XrSpace space, XrBoundary2DFB* boundary2DOutput); |
118 | XrResult getSpaceRoomLayout(XrSpace space, XrRoomLayoutFB* roomLayoutOutput); |
119 | XrResult getSpaceContainer(XrSpace space, XrSpaceContainerFB* spaceContainerOutput); |
120 | XrResult requestSceneCapture(const XrSceneCaptureRequestInfoFB* info, XrAsyncRequestIdFB* requestId); |
121 | |
122 | PFN_xrEnumerateSpaceSupportedComponentsFB xrEnumerateSpaceSupportedComponentsFB = nullptr; |
123 | PFN_xrGetSpaceComponentStatusFB xrGetSpaceComponentStatusFB = nullptr; |
124 | PFN_xrSetSpaceComponentStatusFB xrSetSpaceComponentStatusFB = nullptr; |
125 | PFN_xrGetSpaceUuidFB xrGetSpaceUuidFB = nullptr; |
126 | PFN_xrQuerySpacesFB xrQuerySpacesFB = nullptr; |
127 | PFN_xrRetrieveSpaceQueryResultsFB xrRetrieveSpaceQueryResultsFB = nullptr; |
128 | PFN_xrGetSpaceBoundingBox2DFB xrGetSpaceBoundingBox2DFB = nullptr; |
129 | PFN_xrGetSpaceBoundingBox3DFB xrGetSpaceBoundingBox3DFB = nullptr; |
130 | PFN_xrGetSpaceSemanticLabelsFB xrGetSpaceSemanticLabelsFB = nullptr; |
131 | PFN_xrGetSpaceBoundary2DFB xrGetSpaceBoundary2DFB = nullptr; |
132 | PFN_xrGetSpaceRoomLayoutFB xrGetSpaceRoomLayoutFB = nullptr; |
133 | PFN_xrGetSpaceContainerFB xrGetSpaceContainerFB = nullptr; |
134 | PFN_xrRequestSceneCaptureFB xrRequestSceneCaptureFB = nullptr; |
135 | |
136 | QList<QQuick3DXrSpatialAnchor *> m_anchors; |
137 | QHash<QUuid,QQuick3DXrSpatialAnchor *> m_anchorsByUuid; |
138 | }; |
139 | |
140 | QT_END_NAMESPACE |
141 | |
142 | #endif // QQUICK3DXRANCHORMANAGER_OPENXR_P_H |
143 | |