Debian Codegraph @

modules/openxr/extensions/spatial_entities/openxr_spatial_marker_tracking.h

raw symbols SCIP
1 /**************************************************************************/
2 /* openxr_spatial_marker_tracking.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "openxr_spatial_entities.h"
34
35 // QrCode marker tracking capability configuration
36 class OpenXRSpatialCapabilityConfigurationQrCode : public OpenXRSpatialCapabilityConfigurationBaseHeader {
37 GDCLASS(OpenXRSpatialCapabilityConfigurationQrCode, OpenXRSpatialCapabilityConfigurationBaseHeader);
38
39 public:
40 virtual bool has_valid_configuration() const override;
41 virtual XrSpatialCapabilityConfigurationBaseHeaderEXT *get_configuration() override;
42
43 Vector<XrSpatialComponentTypeEXT> get_enabled_components() const { return enabled_components; }
44
45 protected:
46 static void _bind_methods();
47
48 private:
49 Vector<XrSpatialComponentTypeEXT> enabled_components;
50 XrSpatialCapabilityConfigurationQrCodeEXT marker_config = { XR_TYPE_SPATIAL_CAPABILITY_CONFIGURATION_QR_CODE_EXT, nullptr, XR_SPATIAL_CAPABILITY_MARKER_TRACKING_QR_CODE_EXT, 0, nullptr };
51
52 PackedInt64Array _get_enabled_components() const;
53 };
54
55 // Micro QrCode marker tracking capability configuration
56 class OpenXRSpatialCapabilityConfigurationMicroQrCode : public OpenXRSpatialCapabilityConfigurationBaseHeader {
57 GDCLASS(OpenXRSpatialCapabilityConfigurationMicroQrCode, OpenXRSpatialCapabilityConfigurationBaseHeader);
58
59 public:
60 virtual bool has_valid_configuration() const override;
61 virtual XrSpatialCapabilityConfigurationBaseHeaderEXT *get_configuration() override;
62
63 Vector<XrSpatialComponentTypeEXT> get_enabled_components() const { return enabled_components; }
64
65 protected:
66 static void _bind_methods();
67
68 private:
69 Vector<XrSpatialComponentTypeEXT> enabled_components;
70 XrSpatialCapabilityConfigurationMicroQrCodeEXT marker_config = { XR_TYPE_SPATIAL_CAPABILITY_CONFIGURATION_MICRO_QR_CODE_EXT, nullptr, XR_SPATIAL_CAPABILITY_MARKER_TRACKING_MICRO_QR_CODE_EXT, 0, nullptr };
71
72 PackedInt64Array _get_enabled_components() const;
73 };
74
75 // Aruco marker tracking capability configuration
76 class OpenXRSpatialCapabilityConfigurationAruco : public OpenXRSpatialCapabilityConfigurationBaseHeader {
77 GDCLASS(OpenXRSpatialCapabilityConfigurationAruco, OpenXRSpatialCapabilityConfigurationBaseHeader);
78
79 public:
80 enum ArucoDict {
81 ARUCO_DICT_4X4_50 = XR_SPATIAL_MARKER_ARUCO_DICT_4X4_50_EXT,
82 ARUCO_DICT_4X4_100 = XR_SPATIAL_MARKER_ARUCO_DICT_4X4_100_EXT,
83 ARUCO_DICT_4X4_250 = XR_SPATIAL_MARKER_ARUCO_DICT_4X4_250_EXT,
84 ARUCO_DICT_4X4_1000 = XR_SPATIAL_MARKER_ARUCO_DICT_4X4_1000_EXT,
85 ARUCO_DICT_5X5_50 = XR_SPATIAL_MARKER_ARUCO_DICT_5X5_50_EXT,
86 ARUCO_DICT_5X5_100 = XR_SPATIAL_MARKER_ARUCO_DICT_5X5_100_EXT,
87 ARUCO_DICT_5X5_250 = XR_SPATIAL_MARKER_ARUCO_DICT_5X5_250_EXT,
88 ARUCO_DICT_5X5_1000 = XR_SPATIAL_MARKER_ARUCO_DICT_5X5_1000_EXT,
89 ARUCO_DICT_6X6_50 = XR_SPATIAL_MARKER_ARUCO_DICT_6X6_50_EXT,
90 ARUCO_DICT_6X6_100 = XR_SPATIAL_MARKER_ARUCO_DICT_6X6_100_EXT,
91 ARUCO_DICT_6X6_250 = XR_SPATIAL_MARKER_ARUCO_DICT_6X6_250_EXT,
92 ARUCO_DICT_6X6_1000 = XR_SPATIAL_MARKER_ARUCO_DICT_6X6_1000_EXT,
93 ARUCO_DICT_7X7_50 = XR_SPATIAL_MARKER_ARUCO_DICT_7X7_50_EXT,
94 ARUCO_DICT_7X7_100 = XR_SPATIAL_MARKER_ARUCO_DICT_7X7_100_EXT,
95 ARUCO_DICT_7X7_250 = XR_SPATIAL_MARKER_ARUCO_DICT_7X7_250_EXT,
96 ARUCO_DICT_7X7_1000 = XR_SPATIAL_MARKER_ARUCO_DICT_7X7_1000_EXT,
97 };
98
99 virtual bool has_valid_configuration() const override;
100 virtual XrSpatialCapabilityConfigurationBaseHeaderEXT *get_configuration() override;
101
102 void set_aruco_dict(XrSpatialMarkerArucoDictEXT p_dict);
103 XrSpatialMarkerArucoDictEXT get_aruco_dict() const;
104
105 Vector<XrSpatialComponentTypeEXT> get_enabled_components() const { return enabled_components; }
106
107 protected:
108 static void _bind_methods();
109
110 private:
111 Vector<XrSpatialComponentTypeEXT> enabled_components;
112 XrSpatialCapabilityConfigurationArucoMarkerEXT marker_config = { XR_TYPE_SPATIAL_CAPABILITY_CONFIGURATION_ARUCO_MARKER_EXT, nullptr, XR_SPATIAL_CAPABILITY_MARKER_TRACKING_ARUCO_MARKER_EXT, 0, nullptr, XR_SPATIAL_MARKER_ARUCO_DICT_7X7_1000_EXT };
113
114 PackedInt64Array _get_enabled_components() const;
115
116 void _set_aruco_dict(ArucoDict p_dict);
117 ArucoDict _get_aruco_dict() const;
118 };
119
120 VARIANT_ENUM_CAST(OpenXRSpatialCapabilityConfigurationAruco::ArucoDict);
121
122 // April tag marker tracking capability configuration
123 class OpenXRSpatialCapabilityConfigurationAprilTag : public OpenXRSpatialCapabilityConfigurationBaseHeader {
124 GDCLASS(OpenXRSpatialCapabilityConfigurationAprilTag, OpenXRSpatialCapabilityConfigurationBaseHeader);
125
126 public:
127 enum AprilTagDict {
128 APRIL_TAG_DICT_16H5 = XR_SPATIAL_MARKER_APRIL_TAG_DICT_16H5_EXT,
129 APRIL_TAG_DICT_25H9 = XR_SPATIAL_MARKER_APRIL_TAG_DICT_25H9_EXT,
130 APRIL_TAG_DICT_36H10 = XR_SPATIAL_MARKER_APRIL_TAG_DICT_36H10_EXT,
131 APRIL_TAG_DICT_36H11 = XR_SPATIAL_MARKER_APRIL_TAG_DICT_36H11_EXT,
132 };
133
134 virtual bool has_valid_configuration() const override;
135 virtual XrSpatialCapabilityConfigurationBaseHeaderEXT *get_configuration() override;
136
137 void set_april_dict(XrSpatialMarkerAprilTagDictEXT p_dict);
138 XrSpatialMarkerAprilTagDictEXT get_april_dict() const;
139
140 Vector<XrSpatialComponentTypeEXT> get_enabled_components() const { return enabled_components; }
141
142 protected:
143 static void _bind_methods();
144
145 private:
146 Vector<XrSpatialComponentTypeEXT> enabled_components;
147 XrSpatialCapabilityConfigurationAprilTagEXT marker_config = { XR_TYPE_SPATIAL_CAPABILITY_CONFIGURATION_APRIL_TAG_EXT, nullptr, XR_SPATIAL_CAPABILITY_MARKER_TRACKING_APRIL_TAG_EXT, 0, nullptr, XR_SPATIAL_MARKER_APRIL_TAG_DICT_36H11_EXT };
148
149 PackedInt64Array _get_enabled_components() const;
150
151 void _set_april_dict(AprilTagDict p_dict);
152 AprilTagDict _get_april_dict() const;
153 };
154
155 VARIANT_ENUM_CAST(OpenXRSpatialCapabilityConfigurationAprilTag::AprilTagDict);
156
157 // Marker component data
158 class OpenXRSpatialComponentMarkerList : public OpenXRSpatialComponentData {
159 GDCLASS(OpenXRSpatialComponentMarkerList, OpenXRSpatialComponentData);
160
161 public:
162 enum MarkerType {
163 MARKER_TYPE_UNKNOWN,
164 MARKER_TYPE_QRCODE,
165 MARKER_TYPE_MICRO_QRCODE,
166 MARKER_TYPE_ARUCO,
167 MARKER_TYPE_APRIL_TAG,
168 MARKER_TYPE_MAX
169 };
170
171 virtual void set_capacity(uint32_t p_capacity) override;
172 virtual XrSpatialComponentTypeEXT get_component_type() const override;
173 virtual void *get_structure_data(void *p_next) override;
174
175 MarkerType get_marker_type(int64_t p_index) const;
176 uint32_t get_marker_id(int64_t p_index) const;
177 Variant get_marker_data(RID p_snapshot, int64_t p_index) const;
178
179 protected:
180 static void _bind_methods();
181
182 private:
183 Vector<XrSpatialMarkerDataEXT> marker_data;
184
185 XrSpatialComponentMarkerListEXT marker_list = { XR_TYPE_SPATIAL_COMPONENT_MARKER_LIST_EXT, nullptr, 0, nullptr };
186 };
187
188 VARIANT_ENUM_CAST(OpenXRSpatialComponentMarkerList::MarkerType);
189
190 // Marker tracker
191 class OpenXRMarkerTracker : public OpenXRSpatialEntityTracker {
192 GDCLASS(OpenXRMarkerTracker, OpenXRSpatialEntityTracker);
193
194 public:
195 void set_bounds_size(const Vector2 &p_bounds_size);
196 Vector2 get_bounds_size() const;
197
198 void set_marker_type(OpenXRSpatialComponentMarkerList::MarkerType p_marker_type);
199 OpenXRSpatialComponentMarkerList::MarkerType get_marker_type() const;
200
201 void set_marker_id(uint32_t p_id);
202 uint32_t get_marker_id() const;
203
204 void set_marker_data(const Variant &p_data);
205 Variant get_marker_data() const;
206
207 protected:
208 static void _bind_methods();
209
210 private:
211 Vector2 bounds_size;
212
213 OpenXRSpatialComponentMarkerList::MarkerType marker_type = OpenXRSpatialComponentMarkerList::MarkerType::MARKER_TYPE_UNKNOWN;
214 uint32_t marker_id = 0;
215 Variant marker_data;
216 };
217
218 // Marker tracking logic
219 class OpenXRSpatialMarkerTrackingCapability : public OpenXRExtensionWrapper {
220 GDCLASS(OpenXRSpatialMarkerTrackingCapability, OpenXRExtensionWrapper);
221
222 protected:
223 static void _bind_methods();
224
225 public:
226 static OpenXRSpatialMarkerTrackingCapability *get_singleton();
227
228 OpenXRSpatialMarkerTrackingCapability();
229 virtual ~OpenXRSpatialMarkerTrackingCapability() override;
230
231 virtual HashMap<String, bool *> get_requested_extensions(XrVersion p_version) override;
232
233 virtual void on_session_created(const XrSession p_session) override;
234 virtual void on_session_destroyed() override;
235
236 virtual void on_process() override;
237
238 bool is_qrcode_supported();
239 bool is_micro_qrcode_supported();
240 bool is_aruco_supported();
241 bool is_april_tag_supported();
242
243 private:
244 static OpenXRSpatialMarkerTrackingCapability *singleton;
245 bool spatial_marker_tracking_ext = false;
246
247 RID spatial_context;
248 bool need_discovery = false;
249 int discovery_cooldown = 0;
250 Ref<OpenXRFutureResult> discovery_query_result;
251
252 Ref<OpenXRSpatialCapabilityConfigurationQrCode> qrcode_configuration;
253 Ref<OpenXRSpatialCapabilityConfigurationMicroQrCode> micro_qrcode_configuration;
254 Ref<OpenXRSpatialCapabilityConfigurationAruco> aruco_configuration;
255 Ref<OpenXRSpatialCapabilityConfigurationAprilTag> april_tag_configuration;
256
257 // Discovery logic
258 Ref<OpenXRFutureResult> _create_spatial_context();
259 void _on_spatial_context_created(RID p_spatial_context);
260
261 void _on_spatial_discovery_recommended(RID p_spatial_context);
262
263 Ref<OpenXRFutureResult> _start_entity_discovery();
264 void _process_snapshot(RID p_snapshot, bool p_is_discovery);
265
266 // Trackers
267 HashMap<XrSpatialEntityIdEXT, Ref<OpenXRMarkerTracker>> marker_trackers;
268 };