From 6cfaa4af68216b575209e36cd45b1d4ebea06a00 Mon Sep 17 00:00:00 2001 From: The-Cyber-Captain Date: Sun, 22 Sep 2024 23:45:01 +0100 Subject: [PATCH] Reworked geometric algebra, plus circumvented Basis row:column glitch, to 'correct' root and shoulders trackers. --- .gitmodules | 4 ++ .../main/cpp/extensions/.idea/indexLayout.xml | 8 +++ .../.idea/projectSettingsUpdater.xml | 7 ++ plugin/src/main/cpp/extensions/.idea/vcs.xml | 6 ++ .../main/cpp/extensions/.idea/workspace.xml | 64 +++++++++++++++++++ .../cpp/extensions/Folder.DotSettings.user | 2 + ...nxr_fb_body_tracking_extension_wrapper.cpp | 37 +++++++++-- 7 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 plugin/src/main/cpp/extensions/.idea/indexLayout.xml create mode 100644 plugin/src/main/cpp/extensions/.idea/projectSettingsUpdater.xml create mode 100644 plugin/src/main/cpp/extensions/.idea/vcs.xml create mode 100644 plugin/src/main/cpp/extensions/.idea/workspace.xml create mode 100644 plugin/src/main/cpp/extensions/Folder.DotSettings.user diff --git a/.gitmodules b/.gitmodules index 9bb7ed9a..709db278 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,7 @@ [submodule "thirdparty/godot-cpp"] path = thirdparty/godot-cpp url = https://github.com/godotengine/godot-cpp +[submodule "remote"] + branch = godot-4.3-stable +[submodule "https://github.com/godotengine/godot-cpp.git"] + branch = 4.3 diff --git a/plugin/src/main/cpp/extensions/.idea/indexLayout.xml b/plugin/src/main/cpp/extensions/.idea/indexLayout.xml new file mode 100644 index 00000000..7b08163c --- /dev/null +++ b/plugin/src/main/cpp/extensions/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/plugin/src/main/cpp/extensions/.idea/projectSettingsUpdater.xml b/plugin/src/main/cpp/extensions/.idea/projectSettingsUpdater.xml new file mode 100644 index 00000000..64af657f --- /dev/null +++ b/plugin/src/main/cpp/extensions/.idea/projectSettingsUpdater.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/plugin/src/main/cpp/extensions/.idea/vcs.xml b/plugin/src/main/cpp/extensions/.idea/vcs.xml new file mode 100644 index 00000000..bc599707 --- /dev/null +++ b/plugin/src/main/cpp/extensions/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/plugin/src/main/cpp/extensions/.idea/workspace.xml b/plugin/src/main/cpp/extensions/.idea/workspace.xml new file mode 100644 index 00000000..539d629b --- /dev/null +++ b/plugin/src/main/cpp/extensions/.idea/workspace.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + { + "associatedIndex": 2 +} + + + + { + "keyToString": { + "RunOnceActivity.ShowReadmeOnStart": "true", + "git-widget-placeholder": "master", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "settings.editor.selected.configurable": "preferences.pluginManager", + "vue.rearranger.settings.migration": "true" + } +} + + + + + 1726915431755 + + + + + + + + + \ No newline at end of file diff --git a/plugin/src/main/cpp/extensions/Folder.DotSettings.user b/plugin/src/main/cpp/extensions/Folder.DotSettings.user new file mode 100644 index 00000000..f591ba1d --- /dev/null +++ b/plugin/src/main/cpp/extensions/Folder.DotSettings.user @@ -0,0 +1,2 @@ + + INFO \ No newline at end of file diff --git a/plugin/src/main/cpp/extensions/openxr_fb_body_tracking_extension_wrapper.cpp b/plugin/src/main/cpp/extensions/openxr_fb_body_tracking_extension_wrapper.cpp index 91087e94..f0a392dd 100644 --- a/plugin/src/main/cpp/extensions/openxr_fb_body_tracking_extension_wrapper.cpp +++ b/plugin/src/main/cpp/extensions/openxr_fb_body_tracking_extension_wrapper.cpp @@ -313,27 +313,49 @@ void OpenXRFbBodyTrackingExtensionWrapper::_on_process() { // - Adjusting the left and right shoulder back so they are aligned // with how models are designed, rather than the Meta positions of // the tips of the clavicles. + if (locations.isActive) { + // Construct the root under the hips pointing forwards + // IE, +z aligns with hips & user's real-world forward. + // (Remaining, however, on the XRorigin / Global XZ plane; root's basis rotated around Y to fit) + // Get the hips transform Transform3D hips = xr_body_tracker->get_joint_transform(XRBodyTracker::JOINT_HIPS); - // Construct the root under the hips pointing forwards Vector3 root_y = Vector3(0.0, 1.0, 0.0); - Vector3 root_z = -hips.basis[Vector3::AXIS_X].cross(root_y); - Vector3 root_x = root_y.cross(root_z); + Basis hips_basis = hips.basis; + float hips_left_x = hips_basis[0][0]; + float hips_left_y = hips_basis[1][0]; + float hips_left_z = hips_basis[2][0]; + + Vector3 hips_left = Vector3(hips_left_x, hips_left_y, hips_left_z).normalized(); + + Vector3 root_x = (hips_left.slide(Vector3(0.0, 1.0, 0.0))).normalized(); + // flatten hips' left (x basis) on to real-world / global ground plane. Normalize. + Vector3 root_z = root_x.cross(root_y); + Vector3 root_o = hips.origin.slide(Vector3(0.0, 1.0, 0.0)); + // flatten hips' origin on to ground plane. + Transform3D root = Transform3D(root_x, root_y, root_z, root_o).orthonormalized(); xr_body_tracker->set_joint_transform(XRBodyTracker::JOINT_ROOT, root); - xr_body_tracker->set_pose("default", root, Vector3(), Vector3(), XRPose::XR_TRACKING_CONFIDENCE_HIGH); // Distance in meters to push the shoulder joints back from the // clavicle-position to be in-line with the upper arm joints as // required for T-Pose designed models. constexpr float shoulder_z_offset = -0.07; - // Deduce the shoulder offset from the upper chest transform + // Get the upper_chest transform Transform3D upper_chest = xr_body_tracker->get_joint_transform(XRBodyTracker::JOINT_UPPER_CHEST); - Vector3 shoulder_offset = upper_chest.basis[2] * shoulder_z_offset; + + // Deduce the shoulder offset from the upper chest transform + Basis upper_chest_basis = upper_chest.basis; + float upper_chest_fwd_x = upper_chest_basis[0][2]; + float upper_chest_fwd_y = upper_chest_basis[1][2]; + float upper_chest_fwd_z = upper_chest_basis[2][2]; + + Vector3 upper_chest_fwd = Vector3(upper_chest_fwd_x, upper_chest_fwd_y, upper_chest_fwd_z).normalized(); + Vector3 shoulder_offset = shoulder_z_offset * upper_chest_fwd; // Correct the left shoulder Transform3D left_shoulder = xr_body_tracker->get_joint_transform(XRBodyTracker::JOINT_LEFT_SHOULDER); @@ -344,6 +366,9 @@ void OpenXRFbBodyTrackingExtensionWrapper::_on_process() { Transform3D right_shoulder = xr_body_tracker->get_joint_transform(XRBodyTracker::JOINT_RIGHT_SHOULDER); right_shoulder.origin += shoulder_offset; xr_body_tracker->set_joint_transform(XRBodyTracker::JOINT_RIGHT_SHOULDER, right_shoulder); + + // Set tracker pose, velocities, confidence. Good to go. + xr_body_tracker->set_pose("default", root, Vector3(), Vector3(), XRPose::XR_TRACKING_CONFIDENCE_HIGH); } // Register the XRBodyTracker if necessary