Skip to content

Commit

Permalink
Some XR anchoring fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maunvz committed Aug 31, 2024
1 parent d4423bd commit ebcf98f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,22 +226,19 @@ void OpenXRFbSpatialEntityStorageExtensionWrapper::stop_tracking_persistent_anch
}

void OpenXRFbSpatialEntityStorageExtensionWrapper::create_persistent_anchor(const Transform3D &transform, int request_id) {
XrTime display_time = (XrTime) get_openxr_api()->get_next_frame_time();
XrSpace play_space = (XrSpace) get_openxr_api()->get_play_space();

// First create the anchor for this session
OpenXRFbSpatialEntityExtensionWrapper::get_singleton()->create_spatial_anchor(
play_space, display_time, XrGodotUtils::transformToPose(transform),
[request_id, this](const XrEventDataSpatialAnchorCreateCompleteFB* createResult) {
if (FAILED_EVENT(createResult)) {
LOG_FAIL_EVENT(createResult, "Unable to create XrSpace");
transform,
[request_id, this](XrResult p_result, XrSpace p_space, const XrUuidEXT *p_uuid, void *p_userdata) {
if (FAILED(p_result)) {
LOG_FAIL(p_result, "Unable to create XrSpace");
emit_signal("create_persistent_anchor_failed", request_id);
return;
}
// Next enable storable
OpenXRFbSpatialEntityExtensionWrapper::get_singleton()->set_component_enabled(
createResult->space, XR_SPACE_COMPONENT_TYPE_STORABLE_FB, true,
[request_id, createResult, this](XrResult p_result, XrSpaceComponentTypeFB p_component, bool p_enabled, void *p_userdata) {
p_space, XR_SPACE_COMPONENT_TYPE_STORABLE_FB, true,
[p_uuid, p_space, request_id, this](XrResult p_result, XrSpaceComponentTypeFB p_component, bool p_enabled, void *p_userdata) {
if (FAILED(p_result)) {
LOG_FAIL(p_result, "Unable to enable XR_SPACE_COMPONENT_TYPE_STORABLE_FB for XrSpace");
emit_signal("create_persistent_anchor_failed", request_id);
Expand All @@ -252,22 +249,23 @@ void OpenXRFbSpatialEntityStorageExtensionWrapper::create_persistent_anchor(cons
XrSpaceSaveInfoFB saveInfo = {
XR_TYPE_SPACE_SAVE_INFO_FB,
nullptr,
createResult->space,
p_space,
XR_SPACE_STORAGE_LOCATION_LOCAL_FB,
XR_SPACE_PERSISTENCE_MODE_INDEFINITE_FB
};
OpenXRFbSpatialEntityStorageExtensionWrapper::get_singleton()->save_space(
&saveInfo,
[createResult, request_id, this](XrResult saveResult, void*) {
[p_uuid, request_id, this](XrResult saveResult, XrSpaceStorageLocationFB p_location, void*) {
if (FAILED(saveResult)) {
LOG_FAIL(saveResult, "Unable to save XrSpace");
emit_signal("create_persistent_anchor_failed", request_id);
return;
}
emit_signal("create_persistent_anchor", request_id, String(XrGodotUtils::uuidToString(createResult->uuid).c_str()));
emit_signal("create_persistent_anchor", request_id, String(XrGodotUtils::uuidToString(*p_uuid).c_str()));
}, nullptr);
}, nullptr);
}
},
nullptr
);
}

Expand All @@ -287,7 +285,7 @@ void OpenXRFbSpatialEntityStorageExtensionWrapper::delete_persistent_anchor(cons
XR_SPACE_STORAGE_LOCATION_LOCAL_FB, // TODO: Don't hardcode this
};

erase_space(&info, [](XrResult, void*){}, nullptr);
erase_space(&info, [](XrResult, XrSpaceStorageLocationFB, void*){}, nullptr);
} else {
// Enable storable so we can delete it
OpenXRFbSpatialEntityExtensionWrapper::get_singleton()->set_component_enabled(
Expand All @@ -305,7 +303,7 @@ void OpenXRFbSpatialEntityStorageExtensionWrapper::delete_persistent_anchor(cons
XR_SPACE_STORAGE_LOCATION_LOCAL_FB, // TODO: Don't hardcode this
};

erase_space(&info, [](XrResult, void*){}, nullptr);
erase_space(&info, [](XrResult, XrSpaceStorageLocationFB, void*){}, nullptr);
}, nullptr);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class OpenXRFbSpatialEntityExtensionWrapper : public OpenXRExtensionWrapperExten
// typedef void (*CreateSpatialAnchorCallback)(const XrEventDataSpatialAnchorCreateCompleteFB *eventData);

bool create_spatial_anchor(const Transform3D &p_transform, SpatialAnchorCreatedCallback p_callback, void *p_userdata);
void create_spatial_anchor2(const XrSpace &playSpace, const XrTime &frameTime, const XrPosef &poseInSpace, CreateSpatialAnchorCallback callback);
bool destroy_space(const XrSpace &p_space);

Vector<XrSpaceComponentTypeFB> get_support_components(const XrSpace &p_space);
Expand Down

0 comments on commit ebcf98f

Please sign in to comment.