Skip to content

Commit 8c5b307

Browse files
committed
This PR modifies how the WebXR palm joint transform is calculated so it also has the correct rotation.
1 parent 6b281c0 commit 8c5b307

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

modules/webxr/webxr_interface_js.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -740,12 +740,20 @@ void WebXRInterfaceJS::_update_input_source(int p_input_source_id) {
740740

741741
// WebXR doesn't have a palm joint, so we calculate it by finding the middle of the middle finger metacarpal bone.
742742
{
743-
// 10 is the WebXR middle finger metacarpal joint, and 12 is the offset to the transform origin.
744-
const float *start_pos = hand_joints + (10 * 16) + 12;
745-
// 11 is the WebXR middle finger phalanx proximal joint, and 12 is the offset to the transform origin.
746-
const float *end_pos = hand_joints + (11 * 16) + 12;
747-
Transform3D palm_transform;
748-
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;
743+
// Start by getting the middle finger metacarpal joint.
744+
// Note: 10 is the WebXR middle finger metacarpal joint.
745+
Transform3D palm_transform = _js_matrix_to_transform(hand_joints + (10 * 16));
746+
palm_transform.basis *= bone_adjustment;
747+
748+
// Get the middle finger phalanx position.
749+
// Note: 11 is the WebXR middle finger phalanx proximal joint and 12 is the origin offset.
750+
const float *phalanx_pos = hand_joints + (11 * 16) + 12;
751+
Vector3 phalanx(phalanx_pos[0], phalanx_pos[1], phalanx_pos[2]);
752+
753+
// Offset the palm half-way towards the phalanx joint.
754+
palm_transform.origin = (palm_transform.origin + phalanx) / 2.0;
755+
756+
// Set the palm joint and the pose.
749757
hand_tracker->set_hand_joint_transform(XRHandTracker::HAND_JOINT_PALM, palm_transform);
750758
hand_tracker->set_pose("default", palm_transform, Vector3(), Vector3());
751759
}

0 commit comments

Comments
 (0)