Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WebXR palm joint calculation to include rotation #93614

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions modules/webxr/webxr_interface_js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,12 +740,20 @@ void WebXRInterfaceJS::_update_input_source(int p_input_source_id) {

// WebXR doesn't have a palm joint, so we calculate it by finding the middle of the middle finger metacarpal bone.
{
// 10 is the WebXR middle finger metacarpal joint, and 12 is the offset to the transform origin.
const float *start_pos = hand_joints + (10 * 16) + 12;
// 11 is the WebXR middle finger phalanx proximal joint, and 12 is the offset to the transform origin.
const float *end_pos = hand_joints + (11 * 16) + 12;
Transform3D palm_transform;
palm_transform.origin = (Vector3(start_pos[0], start_pos[1], start_pos[2]) + Vector3(end_pos[0], end_pos[1], end_pos[2])) / 2.0;
// Start by getting the middle finger metacarpal joint.
// Note: 10 is the WebXR middle finger metacarpal joint.
Transform3D palm_transform = _js_matrix_to_transform(hand_joints + (10 * 16));
palm_transform.basis *= bone_adjustment;

// Get the middle finger phalanx position.
// Note: 11 is the WebXR middle finger phalanx proximal joint and 12 is the origin offset.
const float *phalanx_pos = hand_joints + (11 * 16) + 12;
Vector3 phalanx(phalanx_pos[0], phalanx_pos[1], phalanx_pos[2]);

// Offset the palm half-way towards the phalanx joint.
palm_transform.origin = (palm_transform.origin + phalanx) / 2.0;

// Set the palm joint and the pose.
hand_tracker->set_hand_joint_transform(XRHandTracker::HAND_JOINT_PALM, palm_transform);
hand_tracker->set_pose("default", palm_transform, Vector3(), Vector3());
}
Expand Down
Loading