Skip to content

Commit a1a0993

Browse files
committed
Update PlatformHandMeshVisualizer.cs
Update PlatformHandMeshVisualizer.cs
1 parent 80b9c34 commit a1a0993

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

org.mixedrealitytoolkit.input/Visualizers/PlatformHandVisualizer/PlatformHandMeshVisualizer.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ protected override void OnEnable()
5454
{
5555
if (subsystem.subsystemDescriptor.id == "AndroidXRHandMeshProvider")
5656
{
57+
Debug.Log($"Using XR_ANDROID_hand_mesh for {HandNode} visualization.");
5758
meshSubsystem = subsystem;
5859
break;
5960
}
@@ -62,6 +63,7 @@ protected override void OnEnable()
6263
else if (UnityEngine.XR.OpenXR.OpenXRRuntime.IsExtensionEnabled("XR_MSFT_hand_tracking_mesh"))
6364
{
6465
#if MROPENXR_PRESENT && (UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_ANDROID)
66+
Debug.Log($"Using XR_MSFT_hand_tracking_mesh for {HandNode} visualization.");
6567
handMeshTracker = HandNode == XRNode.LeftHand ? HandMeshTracker.Left : HandMeshTracker.Right;
6668
#endif
6769
}
@@ -84,24 +86,30 @@ protected void Update()
8486
return;
8587
}
8688

87-
if (meshSubsystem != null &&
88-
meshSubsystem.TryGetMeshInfos(meshInfos))
89+
if (meshSubsystem != null
90+
&& meshSubsystem.running
91+
&& meshSubsystem.TryGetMeshInfos(meshInfos))
8992
{
9093
int handMeshIndex = HandNode == XRNode.LeftHand ? 0 : 1;
9194

92-
if (meshInfos[handMeshIndex].ChangeState == MeshChangeState.Added
93-
|| meshInfos[handMeshIndex].ChangeState == MeshChangeState.Updated)
95+
MeshInfo meshInfo = meshInfos[handMeshIndex];
96+
if (meshInfo.ChangeState == MeshChangeState.Added
97+
|| meshInfo.ChangeState == MeshChangeState.Updated)
9498
{
95-
meshSubsystem.GenerateMeshAsync(meshInfos[handMeshIndex].MeshId, meshFilter.mesh,
99+
handRenderer.enabled = true;
100+
101+
meshSubsystem.GenerateMeshAsync(meshInfo.MeshId, meshFilter.mesh,
96102
null, MeshVertexAttributes.Normals, result => { });
97103

98-
handRenderer.enabled = true;
104+
// This hand mesh is provided pre-translated from the world origin,
105+
// so we want to ensure the mesh is "centered" at the world origin
106+
transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);
99107
}
100108
}
101109
#if MROPENXR_PRESENT && (UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_ANDROID)
102-
else if (handMeshTracker != null &&
103-
handMeshTracker.TryGetHandMesh(FrameTime.OnUpdate, meshFilter.mesh) &&
104-
handMeshTracker.TryLocateHandMesh(FrameTime.OnUpdate, out Pose pose))
110+
else if (handMeshTracker != null
111+
&& handMeshTracker.TryGetHandMesh(FrameTime.OnUpdate, meshFilter.mesh)
112+
&& handMeshTracker.TryLocateHandMesh(FrameTime.OnUpdate, out Pose pose))
105113
{
106114
handRenderer.enabled = true;
107115

0 commit comments

Comments
 (0)