OpenXR: Add support for spatial entities extension#107391
OpenXR: Add support for spatial entities extension#107391Repiteo merged 1 commit intogodotengine:masterfrom
Conversation
2d29a99 to
38e51ea
Compare
|
Note: Seeing we're pretty much in feature freeze for Godot 4.5, this PR is currently set for inclusion in Godot 4.6. However if consensus is met in time, I'm hoping we can merge this as an experimental feature in Godot 4.5 as the functionality should not impact any users that do not enable it. This is worth further discussion. |
38e51ea to
d70cbbb
Compare
dsnopek
left a comment
There was a problem hiding this comment.
Thanks, this is great! I wish I could test it :-)
I skimmed through the code (I didn't look at the docs), and only have a few minor comments
| GDCLASS(OpenXRSpatialEntityExtension, OpenXRExtensionWrapper); | ||
|
|
||
| public: | ||
| // Enums that mirror important relevant OpenXR enums (should see if we can macro this) |
There was a problem hiding this comment.
Macroing would be nice. If we could static_assert() that the values are the same that would also be good (in the rendering code it does this for some enums that mirror Vulkan)
There was a problem hiding this comment.
I created a XR_BIND_ENUM_CONSTANTS macro that will bind all entries for an OpenXR enum using OpenXRs reflection :)
| // TODO Q maybe register all spatial entity enums here, | ||
| // currently we define a few in various components and capabilities. |
There was a problem hiding this comment.
Putting all the enums in a central place that all can access could make sense!
There was a problem hiding this comment.
I'm still unsure about this. The logical place would be to add these to OpenXRInterface or OpenXRSpatialEntityExtension, but most places that need to use these constants, will be defined before we define these classes. So we have a dependency issue.
That said, if I can expose the OpenXR enums directly to ClassDB instead of creating mirror enums, this may become a none issue.
There was a problem hiding this comment.
As mentioned this elsewhere, now using a macro to expose OpenXRs own enums directly, but not putting them in a single place because I'm having dependency issues. So up for further debate :)
modules/openxr/extensions/spatial_entities/openxr_spatial_anchor.cpp
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_anchor.cpp
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_entities.cpp
Outdated
Show resolved
Hide resolved
| static void _bind_methods(); | ||
|
|
||
| public: | ||
| enum OpenXrSpatialEntityTrackingState { // this should mirror XrSpatialEntityTrackingStateEXT exactly! |
There was a problem hiding this comment.
Per similar comment above, it would be nice to static_assert() that the enum values match. But not necessary if it's tricky to do in a developer friendly way
modules/openxr/extensions/spatial_entities/openxr_spatial_entity_extension.cpp
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_entity_extension.cpp
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_entity_extension.cpp
Outdated
Show resolved
Hide resolved
| <return type="void" /> | ||
| <param index="0" name="anchor_tracker" type="OpenXRAnchorTracker" /> | ||
| <description> | ||
| Remove an anchor previously created with [method create_new_anchor]. If this anchor was persistent you must first call [method make_anchor_unpersistent] and await its callback. |
There was a problem hiding this comment.
If this anchor was persistent you must first call [method make_anchor_unpersistent] and await its callback.
Isn't something we could do automatically?
There was a problem hiding this comment.
I thought about that but it has problems because making an anchor no longer persistent, is an async method. Especially if removing anchors is part of some cleanup logic, we potentially need to ensure the user delays part of their cleanup.
I'm on the fence though. We could make removing an anchor an asynchronous method on our side, even if it would be immediate if the anchor is not persistent and deal with it that way.
modules/openxr/doc_classes/OpenXRSpatialCapabilityConfigurationPlaneTracking.xml
Outdated
Show resolved
Hide resolved
modules/openxr/doc_classes/OpenXRSpatialMarkerTrackingCapability.xml
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_anchor.cpp
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_anchor.cpp
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_anchor.cpp
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_anchor.cpp
Outdated
Show resolved
Hide resolved
2c9e967 to
5bdb4c9
Compare
|
Ok, fixed a bunch of things, marker tracking now works including live tracking the marker.
|
f061e41 to
315422d
Compare
| OpenXRSpatialEntityExtension *se_extension = OpenXRSpatialEntityExtension::get_singleton(); | ||
| ERR_FAIL_NULL_V(se_extension, PackedVector2Array()); | ||
|
|
||
| return se_extension->get_vector2_buffer(p_snapshot, buffer.bufferId); |
There was a problem hiding this comment.
Just as a reminder to myself, I'll probably do this in a follow up.
Currently we retrieve this data and check in set_mesh_data if it has changed, which we should keep as a fallback.
However feedback from the OpenXR WG suggests that we can add an extra check here. We should cache buffer.bufferId in our calling logic, if it is unchanged from the last time, the data is unchanged and we don't need to call this getter.
When new data is available, we should always have a new buffer id.
This applies to our other buffer getter functions as well.
315422d to
18ec575
Compare
18ec575 to
5c53518
Compare
|
XR Meeting: this is ready to merge, if there are any more tweaks we can PR them separately but everything seems to be working well. |
dsnopek
left a comment
There was a problem hiding this comment.
Thanks!
I've done one last round of testing, and everything seems to be working well. I have a couple notes that I think should get handled, but they can come in follow-up PRs
modules/openxr/extensions/spatial_entities/openxr_spatial_anchor.cpp
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_plane_tracking.h
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_marker_tracking.h
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_entity_extension.h
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_entity_extension.h
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_entity_extension.cpp
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_entity_extension.cpp
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_anchor.cpp
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_anchor.cpp
Outdated
Show resolved
Hide resolved
modules/openxr/extensions/spatial_entities/openxr_spatial_anchor.cpp
Outdated
Show resolved
Hide resolved
|
Needs rebase |
5c53518 to
8412b38
Compare
8ab4695 to
221bd10
Compare
221bd10 to
eeac570
Compare
|
@AThousandShips I did most of your clean up suggestions, there are one or two outstanding questions and I didn't do all the changes away from I suggest that whatever is left we do as a separate PR, that was a LOT to get through :) |
|
Thanks! Great work covering all those bases! |
| print_verbose("OpenXR: xrEnumerateSpatialPersistenceScopesEXT is not supported, falling back to xrEnumerateSpatialPersistenceStoresEXT!") | ||
| xr_result = openxr_api->get_instance_proc_addr("xrEnumerateSpatialPersistenceStoresEXT", (PFN_xrVoidFunction *)&xrEnumerateSpatialPersistenceScopesEXT_ptr); |
There was a problem hiding this comment.
You're missing a semicolon on the print_verbose line, so clang-format decided to incorrectly indent the following line.
The OpenXR Spatial entities extension was introduced to standardise obtaining and interacting with information about the users real world environment.
It defines a core extension for how to query and interact with spatial entities, and defines additional extensions that detail out specific uses of these entities.
Currently the core specification has support for:
The spatial entities system is designed to be incredibly modular with future plans for additional (vendor) extensions to unlock further functionality. The core of the implementation in Godot therefor exposes a fair amount of underlying features that can be used in GDExtension plugins to implement such extensions or for users to fully customize the setup.
However, in plain vanila mode all this logic comes built in and can be enabled in project settings. Using the built in logic all spatial entities are recorded as Anchor trackers with the XR Server and can be consumed through a simple manager script.
While the implementation is deemed complete based on the published specification, runtime implementations are still being worked upon and some tweaking will be expected.
Documentation can be found here: godotengine/godot-docs#11015
Demo project can be found here: https://github.com/BastiaanOlij/spatial-entities-demo
For testing sadly there are no public runtime implementations yet, however myself, David and Fredia have access to betas and have tested this.
Contributed by Khronos Group through the Godot Integration Project