Skip to content

Commit 5e329e1

Browse files
committed
Update PlatformHandMeshVisualizer.cs
1 parent ca3631d commit 5e329e1

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,38 +52,31 @@ protected override void OnEnable()
5252
base.OnEnable();
5353

5454
handRenderer.enabled = false;
55-
propertyBlock ??= new MaterialPropertyBlock();
5655

57-
// If we already found our subsystem, don't search again
58-
if (handSubsystem != null && handSubsystem.running)
56+
// Use propertyBlock as an indicator that this is our first time through OnEnable
57+
if (propertyBlock == null)
5958
{
59+
propertyBlock = new MaterialPropertyBlock();
60+
6061
updateSuccessFlags = HandNode == XRNode.LeftHand ?
6162
XRHandSubsystem.UpdateSuccessFlags.LeftHandJoints | XRHandSubsystem.UpdateSuccessFlags.LeftHandRootPose :
6263
XRHandSubsystem.UpdateSuccessFlags.RightHandJoints | XRHandSubsystem.UpdateSuccessFlags.RightHandRootPose;
6364

6465
// Since the hand mesh is likely to change every frame, we
6566
// "optimize mesh for frequent updates" by marking it dynamic
6667
meshFilter.mesh.MarkDynamic();
67-
68-
return;
6968
}
7069

70+
// If we already found our subsystem, just return
71+
if (handSubsystem != null && handSubsystem.running) { return; }
72+
7173
List<XRHandSubsystem> subsystems = XRSubsystemHelpers.GetAllSubsystems<XRHandSubsystem>();
7274
foreach (XRHandSubsystem subsystem in subsystems)
7375
{
7476
if (subsystem.GetProvider() is OpenXRHandProvider provider && provider.handMeshDataSupplier != null)
7577
{
7678
Debug.Log($"Using {provider.handMeshDataSupplier.GetType()} for hand visualization.");
7779
handSubsystem = subsystem;
78-
79-
updateSuccessFlags = HandNode == XRNode.LeftHand ?
80-
XRHandSubsystem.UpdateSuccessFlags.LeftHandJoints | XRHandSubsystem.UpdateSuccessFlags.LeftHandRootPose :
81-
XRHandSubsystem.UpdateSuccessFlags.RightHandJoints | XRHandSubsystem.UpdateSuccessFlags.RightHandRootPose;
82-
83-
// Since the hand mesh is likely to change every frame, we
84-
// "optimize mesh for frequent updates" by marking it dynamic
85-
meshFilter.mesh.MarkDynamic();
86-
8780
return;
8881
}
8982
}
@@ -94,10 +87,6 @@ protected override void OnEnable()
9487
Debug.Log($"Using XR_MSFT_hand_tracking_mesh for {HandNode} visualization.");
9588
handMeshTracker = HandNode == XRNode.LeftHand ? HandMeshTracker.Left : HandMeshTracker.Right;
9689

97-
// Since the hand mesh is likely to change every frame, we
98-
// "optimize mesh for frequent updates" by marking it dynamic
99-
meshFilter.mesh.MarkDynamic();
100-
10190
if (neutralPoseMesh == null)
10291
{
10392
neutralPoseMesh = new Mesh();

0 commit comments

Comments
 (0)