@@ -70,6 +70,11 @@ void XRHandModifier3D::_get_joint_data() {
7070 return ;
7171 }
7272
73+ if (has_stored_previous_transforms) {
74+ previous_relative_transforms.clear ();
75+ has_stored_previous_transforms = false ;
76+ }
77+
7378 // Table of bone names for different rig types.
7479 static const String bone_names[XRHandTracker::HAND_JOINT_MAX] = {
7580 " Palm" ,
@@ -196,6 +201,18 @@ void XRHandModifier3D::_process_modification() {
196201
197202 // Skip if no tracking data
198203 if (!tracker->get_has_tracking_data ()) {
204+ if (!has_stored_previous_transforms) {
205+ return ;
206+ }
207+
208+ // Apply previous relative transforms if they are stored.
209+ for (int joint = 0 ; joint < XRHandTracker::HAND_JOINT_MAX; joint++) {
210+ if (bone_update == BONE_UPDATE_FULL) {
211+ skeleton->set_bone_pose_position (joints[joint].bone , previous_relative_transforms[joint].origin );
212+ }
213+
214+ skeleton->set_bone_pose_rotation (joints[joint].bone , Quaternion (previous_relative_transforms[joint].basis ));
215+ }
199216 return ;
200217 }
201218
@@ -223,6 +240,12 @@ void XRHandModifier3D::_process_modification() {
223240 return ;
224241 }
225242
243+ if (!has_stored_previous_transforms) {
244+ previous_relative_transforms.resize (XRHandTracker::HAND_JOINT_MAX);
245+ has_stored_previous_transforms = true ;
246+ }
247+ Transform3D *previous_relative_transforms_ptr = previous_relative_transforms.ptrw ();
248+
226249 for (int joint = 0 ; joint < XRHandTracker::HAND_JOINT_MAX; joint++) {
227250 // Get the skeleton bone (skip if none).
228251 const int bone = joints[joint].bone ;
@@ -233,6 +256,7 @@ void XRHandModifier3D::_process_modification() {
233256 // Calculate the relative relationship to the parent bone joint.
234257 const int parent_joint = joints[joint].parent_joint ;
235258 const Transform3D relative_transform = inv_transforms[parent_joint] * transforms[joint];
259+ previous_relative_transforms_ptr[joint] = relative_transform;
236260
237261 // Update the bone position if enabled by update mode.
238262 if (bone_update == BONE_UPDATE_FULL) {
0 commit comments