| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "../../openxr_structure.h" |
| 34 |
#include "../openxr_future_extension.h" |
| 35 |
#include "scene/resources/mesh.h" |
| 36 |
#include "servers/xr/xr_positional_tracker.h" |
| 37 |
|
| 38 |
#define XR_NULL_ENTITY 0x7FFFFFFF |
| 39 |
|
| 40 |
|
| 41 |
class OpenXRSpatialCapabilityConfigurationBaseHeader : public RefCounted { |
| 42 |
GDCLASS(OpenXRSpatialCapabilityConfigurationBaseHeader, RefCounted); |
| 43 |
|
| 44 |
protected: |
| 45 |
static void _bind_methods(); |
| 46 |
|
| 47 |
public: |
| 48 |
virtual bool has_valid_configuration() const; |
| 49 |
virtual XrSpatialCapabilityConfigurationBaseHeaderEXT *get_configuration(); |
| 50 |
|
| 51 |
GDVIRTUAL0RC(bool, _has_valid_configuration); |
| 52 |
GDVIRTUAL0R(uint64_t, _get_configuration); |
| 53 |
}; |
| 54 |
|
| 55 |
|
| 56 |
class OpenXRSpatialEntityTracker : public XRPositionalTracker { |
| 57 |
GDCLASS(OpenXRSpatialEntityTracker, XRPositionalTracker); |
| 58 |
|
| 59 |
public: |
| 60 |
enum EntityTrackingState { |
| 61 |
ENTITY_TRACKING_STATE_STOPPED = XR_SPATIAL_ENTITY_TRACKING_STATE_STOPPED_EXT, |
| 62 |
ENTITY_TRACKING_STATE_PAUSED = XR_SPATIAL_ENTITY_TRACKING_STATE_PAUSED_EXT, |
| 63 |
ENTITY_TRACKING_STATE_TRACKING = XR_SPATIAL_ENTITY_TRACKING_STATE_TRACKING_EXT, |
| 64 |
}; |
| 65 |
|
| 66 |
OpenXRSpatialEntityTracker(); |
| 67 |
virtual ~OpenXRSpatialEntityTracker(); |
| 68 |
|
| 69 |
void set_entity(const RID &p_entity); |
| 70 |
RID get_entity() const; |
| 71 |
|
| 72 |
void set_spatial_tracking_state(const XrSpatialEntityTrackingStateEXT p_state); |
| 73 |
XrSpatialEntityTrackingStateEXT get_spatial_tracking_state() const; |
| 74 |
|
| 75 |
protected: |
| 76 |
static void _bind_methods(); |
| 77 |
|
| 78 |
private: |
| 79 |
RID spatial_entity; |
| 80 |
XrSpatialEntityTrackingStateEXT spatial_tracking_state = XR_SPATIAL_ENTITY_TRACKING_STATE_PAUSED_EXT; |
| 81 |
|
| 82 |
void _set_spatial_tracking_state(const EntityTrackingState p_state); |
| 83 |
EntityTrackingState _get_spatial_tracking_state() const; |
| 84 |
}; |
| 85 |
|
| 86 |
VARIANT_ENUM_CAST(OpenXRSpatialEntityTracker::EntityTrackingState) |
| 87 |
|
| 88 |
|
| 89 |
class OpenXRSpatialComponentData : public RefCounted { |
| 90 |
GDCLASS(OpenXRSpatialComponentData, RefCounted); |
| 91 |
|
| 92 |
protected: |
| 93 |
static void _bind_methods(); |
| 94 |
|
| 95 |
public: |
| 96 |
virtual void set_capacity(uint32_t p_capacity); |
| 97 |
virtual XrSpatialComponentTypeEXT get_component_type() const; |
| 98 |
virtual void *get_structure_data(void *p_next); |
| 99 |
|
| 100 |
GDVIRTUAL1(_set_capacity, uint32_t); |
| 101 |
GDVIRTUAL0RC(uint64_t, _get_component_type); |
| 102 |
GDVIRTUAL1RC(uint64_t, _get_structure_data, uint64_t); |
| 103 |
}; |
| 104 |
|
| 105 |
class OpenXRSpatialComponentBounded2DList : public OpenXRSpatialComponentData { |
| 106 |
GDCLASS(OpenXRSpatialComponentBounded2DList, OpenXRSpatialComponentData); |
| 107 |
|
| 108 |
protected: |
| 109 |
static void _bind_methods(); |
| 110 |
|
| 111 |
public: |
| 112 |
virtual void set_capacity(uint32_t p_capacity) override; |
| 113 |
virtual XrSpatialComponentTypeEXT get_component_type() const override; |
| 114 |
virtual void *get_structure_data(void *p_next) override; |
| 115 |
|
| 116 |
Transform3D get_center_pose(int64_t p_index) const; |
| 117 |
Vector2 get_size(int64_t p_index) const; |
| 118 |
|
| 119 |
private: |
| 120 |
Vector<XrSpatialBounded2DDataEXT> bounded2d_data; |
| 121 |
|
| 122 |
XrSpatialComponentBounded2DListEXT bounded2d_list = { XR_TYPE_SPATIAL_COMPONENT_BOUNDED_2D_LIST_EXT, nullptr, 0, nullptr }; |
| 123 |
}; |
| 124 |
|
| 125 |
class OpenXRSpatialComponentBounded3DList : public OpenXRSpatialComponentData { |
| 126 |
GDCLASS(OpenXRSpatialComponentBounded3DList, OpenXRSpatialComponentData); |
| 127 |
|
| 128 |
protected: |
| 129 |
static void _bind_methods(); |
| 130 |
|
| 131 |
public: |
| 132 |
virtual void set_capacity(uint32_t p_capacity) override; |
| 133 |
virtual XrSpatialComponentTypeEXT get_component_type() const override; |
| 134 |
virtual void *get_structure_data(void *p_next) override; |
| 135 |
|
| 136 |
Transform3D get_center_pose(int64_t p_index) const; |
| 137 |
Vector3 get_size(int64_t p_index) const; |
| 138 |
|
| 139 |
private: |
| 140 |
Vector<XrBoxf> bounded3d_data; |
| 141 |
|
| 142 |
XrSpatialComponentBounded3DListEXT bounded3d_list = { XR_TYPE_SPATIAL_COMPONENT_BOUNDED_3D_LIST_EXT, nullptr, 0, nullptr }; |
| 143 |
}; |
| 144 |
|
| 145 |
class OpenXRSpatialComponentParentList : public OpenXRSpatialComponentData { |
| 146 |
GDCLASS(OpenXRSpatialComponentParentList, OpenXRSpatialComponentData); |
| 147 |
|
| 148 |
protected: |
| 149 |
static void _bind_methods(); |
| 150 |
|
| 151 |
public: |
| 152 |
virtual void set_capacity(uint32_t p_capacity) override; |
| 153 |
virtual XrSpatialComponentTypeEXT get_component_type() const override; |
| 154 |
virtual void *get_structure_data(void *p_next) override; |
| 155 |
|
| 156 |
RID get_parent(int64_t p_index) const; |
| 157 |
|
| 158 |
private: |
| 159 |
Vector<XrSpatialEntityIdEXT> parent_data; |
| 160 |
|
| 161 |
XrSpatialComponentParentListEXT parent_list = { XR_TYPE_SPATIAL_COMPONENT_PARENT_LIST_EXT, nullptr, 0, nullptr }; |
| 162 |
}; |
| 163 |
|
| 164 |
class OpenXRSpatialComponentMesh2DList : public OpenXRSpatialComponentData { |
| 165 |
GDCLASS(OpenXRSpatialComponentMesh2DList, OpenXRSpatialComponentData); |
| 166 |
|
| 167 |
protected: |
| 168 |
static void _bind_methods(); |
| 169 |
|
| 170 |
public: |
| 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 |
Transform3D get_transform(int64_t p_index) const; |
| 176 |
PackedVector2Array get_vertices(RID p_snapshot, int64_t p_index) const; |
| 177 |
PackedInt32Array get_indices(RID p_snapshot, int64_t p_index) const; |
| 178 |
|
| 179 |
private: |
| 180 |
Vector<XrSpatialMeshDataEXT> mesh2d_data; |
| 181 |
|
| 182 |
XrSpatialComponentMesh2DListEXT mesh2d_list = { XR_TYPE_SPATIAL_COMPONENT_MESH_2D_LIST_EXT, nullptr, 0, nullptr }; |
| 183 |
}; |
| 184 |
|
| 185 |
class OpenXRSpatialComponentMesh3DList : public OpenXRSpatialComponentData { |
| 186 |
GDCLASS(OpenXRSpatialComponentMesh3DList, OpenXRSpatialComponentData); |
| 187 |
|
| 188 |
protected: |
| 189 |
static void _bind_methods(); |
| 190 |
|
| 191 |
public: |
| 192 |
virtual void set_capacity(uint32_t p_capacity) override; |
| 193 |
virtual XrSpatialComponentTypeEXT get_component_type() const override; |
| 194 |
virtual void *get_structure_data(void *p_next) override; |
| 195 |
|
| 196 |
Transform3D get_transform(int64_t p_index) const; |
| 197 |
Ref<Mesh> get_mesh(int64_t p_index) const; |
| 198 |
|
| 199 |
private: |
| 200 |
Vector<XrSpatialMeshDataEXT> mesh3d_data; |
| 201 |
|
| 202 |
XrSpatialComponentMesh3DListEXT mesh3d_list = { XR_TYPE_SPATIAL_COMPONENT_MESH_3D_LIST_EXT, nullptr, 0, nullptr }; |
| 203 |
}; |
| 204 |
|
| 205 |
class OpenXRSpatialQueryResultData : public OpenXRSpatialComponentData { |
| 206 |
GDCLASS(OpenXRSpatialQueryResultData, OpenXRSpatialComponentData); |
| 207 |
|
| 208 |
protected: |
| 209 |
static void _bind_methods(); |
| 210 |
|
| 211 |
public: |
| 212 |
virtual void set_capacity(uint32_t p_capacity) override; |
| 213 |
virtual XrSpatialComponentTypeEXT get_component_type() const override; |
| 214 |
virtual void *get_structure_data(void *p_next) override; |
| 215 |
|
| 216 |
int64_t get_capacity() const { return entity_ids.size(); } |
| 217 |
XrSpatialEntityIdEXT get_entity_id(int64_t p_index) const; |
| 218 |
XrSpatialEntityTrackingStateEXT get_entity_state(int64_t p_index) const; |
| 219 |
|
| 220 |
static String get_entity_tracking_state_name(XrSpatialEntityTrackingStateEXT p_tracking_state); |
| 221 |
|
| 222 |
private: |
| 223 |
Vector<XrSpatialEntityIdEXT> entity_ids; |
| 224 |
Vector<XrSpatialEntityTrackingStateEXT> entity_states; |
| 225 |
|
| 226 |
XrSpatialComponentDataQueryResultEXT query_result = { XR_TYPE_SPATIAL_COMPONENT_DATA_QUERY_RESULT_EXT, nullptr, 0, 0, nullptr, 0, 0, nullptr }; |
| 227 |
|
| 228 |
uint64_t _get_entity_id(int64_t p_index) const; |
| 229 |
OpenXRSpatialEntityTracker::EntityTrackingState _get_entity_state(int64_t p_index) const; |
| 230 |
}; |