GodotVR / godot_openxr_vendors

Godot 4 wrapper for OpenXR vendors loaders and extensions
MIT License
83 stars 17 forks source link

Add a developer-facing API for interacting with scene anchors #107

Closed dsnopek closed 3 months ago

dsnopek commented 4 months ago

This builds on the work from PR https://github.com/GodotVR/godot_openxr_vendors/pull/66 which added extension wrappers for XR_FB_scene and all the related extensions, but didn't expose a nice developer-facing API.

This PR adds that API!

It's centered around a new OpenXRFbSceneManager node, where you configure scenes to be instantiated for each scene anchor depending on it's semantic labels:

Selection_124

For each scene anchor that it discovers, it creates an XRAnchor3D node (which gets its position from an XRPositionTracker) <-- this is the generic support for anchors already built into Godot, which is also used by the ARKit plugin

And then depending on the semantic labels of the scene anchor, it instantiates the given scene and makes it a child of the XRAnchor3D, and calls a method on it with an OpenXRFbSpatialEntity object, which the developer can use to query any information they want about the anchor, for example, including easily creating a MeshInstance3D or CollisionShape3D.

The demo project uses this to place some boxes and labels in the room based on the captured scene data:

e56d0a2a027db5dfb386cf3db8561067 Press the Y button to toggle on/off passthrough (the scene anchors will only be shown when in passthrough) and the Menu button to do scene capture.

I also took the opportunity to make a friendlier way to access the scene capture API. Rather than calling OpenXRFbSceneCaptureExtensionWrapper.request_scene_capture(), this PR adds a similar method on the OpenXRFbSceneManager node, so developers should be able to do everything related to scene anchors via that node (never having to interact with the singletons).

This PR was already getting huge, so there's a couple things I've left out for now, which I plan to add in follow-ups: