Skip to content

Commit 4a56774

Browse files
committed
Fixed Hand Model joints rotation
1 parent b619707 commit 4a56774

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

Packages/webxr-interactions/Runtime/Scripts/ControllerInteraction.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class ControllerInteraction : MonoBehaviour
4444
private bool loadedHandModel = false;
4545
private string loadedHandProfile = null;
4646
private Dictionary<int, Transform> handModelJoints = new Dictionary<int, Transform>();
47+
private static Quaternion quat180 = Quaternion.Euler(0, 180, 0);
4748
#endif
4849

4950
private void Awake()
@@ -291,7 +292,7 @@ private void OnHandUpdate(WebXRHandData handData)
291292
if (handModelJoints.ContainsKey(i))
292293
{
293294
handModelJoints[i].localPosition = rotationOffset * (handData.joints[i].position - handData.joints[0].position);
294-
handModelJoints[i].localRotation = rotationOffset * handData.joints[i].rotation;
295+
handModelJoints[i].localRotation = rotationOffset * handData.joints[i].rotation * quat180;
295296
}
296297
}
297298
return;
@@ -441,15 +442,15 @@ private void HandleHandModelLoaded(bool success)
441442
var inputProfileModelTransform = inputProfileHandModel.transform;
442443
inputProfileModelTransform.SetParent(inputProfileHandModelParent.transform);
443444
inputProfileModelTransform.localPosition = Vector3.zero;
444-
inputProfileModelTransform.localRotation = Quaternion.identity;
445+
inputProfileModelTransform.localRotation = quat180;
445446
inputProfileModelTransform.localScale = Vector3.one;
446447
for (int i = 0; i <= (int)WebXRHandJoint.pinky_finger_tip; i++)
447448
{
448449
handModelJoints.Add(i, inputProfileHandModel.GetChildTransform(((WebXRHandJoint)i).ToString().Replace('_','-')));
449450
// It took at least one frame with hand data, there should be hand joint transform
450451
if (handJoints.ContainsKey(i))
451452
{
452-
handModelJoints[i].SetPositionAndRotation(handJoints[i].position, handJoints[i].rotation);
453+
handModelJoints[i].SetPositionAndRotation(handJoints[i].position, handJoints[i].rotation * quat180);
453454
if (useCollidersForHandJoints)
454455
{
455456
var collider = handModelJoints[i].gameObject.AddComponent<SphereCollider>();

Packages/webxr/Runtime/Scripts/WebXRController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,6 @@ private void OnHandUpdateInternal(WebXRHandData handData)
408408
transform.localPosition = handData.joints[0].position;
409409
transform.localRotation = handData.joints[0].rotation;
410410

411-
Quaternion rotationOffset = Quaternion.Inverse(handData.joints[0].rotation);
412-
413411
trigger = handData.trigger;
414412
squeeze = handData.squeeze;
415413

0 commit comments

Comments
 (0)