Skip to content

Commit c4eb4bc

Browse files
committed
Update PlatformHandMeshVisualizer.cs
1 parent 4d05571 commit c4eb4bc

File tree

1 file changed

+39
-41
lines changed

1 file changed

+39
-41
lines changed

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

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -112,68 +112,66 @@ protected void Update()
112112
return;
113113
}
114114

115-
if (handSubsystem != null && handSubsystem.running)
115+
if (handSubsystem != null && handSubsystem.running && (handSubsystem.updateSuccessFlags & updateSuccessFlags) != 0)
116116
{
117117
XRHandMeshDataQueryParams queryParams = new()
118118
{
119119
allocator = Unity.Collections.Allocator.Temp,
120120
};
121121

122-
// Sometimes, the mesh update will fail, but that doesn't mean we don't have a valid mesh
122+
// Sometimes, the mesh retrieval will fail, but that doesn't mean we aren't being tracked
123123
// So, reuse the last mesh until the subsystem tells us we're untracked
124124
if (lastUpdatedFrame != Time.frameCount && !handSubsystem.TryGetMeshData(out result, ref queryParams))
125125
{
126126
return;
127127
}
128128

129-
if ((handSubsystem.updateSuccessFlags & updateSuccessFlags) != 0)
130-
{
131-
lastUpdatedFrame = Time.frameCount;
132-
XRHandMeshData handMeshData = HandNode == XRNode.LeftHand ? result.leftHand : result.rightHand;
133-
handRenderer.enabled = true;
134-
Mesh mesh = meshFilter.mesh;
129+
lastUpdatedFrame = Time.frameCount;
130+
XRHandMeshData handMeshData = HandNode == XRNode.LeftHand ? result.leftHand : result.rightHand;
131+
handRenderer.enabled = true;
132+
Mesh mesh = meshFilter.mesh;
135133

136-
if (handMeshData.positions.Length > 0 && handMeshData.indices.Length > 0)
134+
if (handMeshData.positions.Length > 0 && handMeshData.indices.Length > 0)
135+
{
136+
mesh.SetVertices(handMeshData.positions);
137+
Unity.Collections.NativeArray<int> indices = handMeshData.indices;
138+
// This API appears to return CCW triangles, but Unity expects CW triangles
139+
for (int i = 0; i < indices.Length; i += 3)
137140
{
138-
mesh.SetVertices(handMeshData.positions);
139-
Unity.Collections.NativeArray<int> indices = handMeshData.indices;
140-
// This API appears to return CCW triangles, but Unity expects CW triangles
141-
for (int i = 0; i < indices.Length; i += 3)
142-
{
143-
(indices[i + 1], indices[i + 2]) = (indices[i + 2], indices[i + 1]);
144-
}
145-
mesh.SetIndices(indices, MeshTopology.Triangles, 0);
146-
mesh.RecalculateBounds();
141+
(indices[i + 1], indices[i + 2]) = (indices[i + 2], indices[i + 1]);
147142
}
143+
mesh.SetIndices(indices, MeshTopology.Triangles, 0);
144+
mesh.RecalculateBounds();
145+
}
148146

149-
if (handMeshData.uvs.IsCreated && handMeshData.uvs.Length == mesh.vertexCount)
150-
{
151-
mesh.SetUVs(0, handMeshData.uvs);
152-
}
153-
else
154-
{
155-
mesh.uv = null;
156-
}
147+
if (handMeshData.uvs.IsCreated && handMeshData.uvs.Length == mesh.vertexCount)
148+
{
149+
mesh.SetUVs(0, handMeshData.uvs);
150+
}
151+
else
152+
{
153+
mesh.uv = null;
154+
}
157155

158-
if (handMeshData.normals.IsCreated && handMeshData.normals.Length == mesh.vertexCount)
159-
{
160-
mesh.SetNormals(handMeshData.normals);
161-
}
162-
else
163-
{
164-
mesh.RecalculateNormals();
165-
}
156+
if (handMeshData.normals.IsCreated && handMeshData.normals.Length == mesh.vertexCount)
157+
{
158+
mesh.SetNormals(handMeshData.normals);
159+
}
160+
else
161+
{
162+
mesh.RecalculateNormals();
163+
}
166164

167-
if (handMeshData.TryGetRootPose(out Pose rootPose))
168-
{
169-
transform.SetWorldPose(PlayspaceUtilities.TransformPose(rootPose));
170-
}
171-
UpdateHandMaterial();
172-
return;
165+
if (handMeshData.TryGetRootPose(out Pose rootPose))
166+
{
167+
transform.SetWorldPose(PlayspaceUtilities.TransformPose(rootPose));
173168
}
169+
UpdateHandMaterial();
170+
return;
174171
}
172+
175173
#if MROPENXR_PRESENT && (UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_ANDROID)
176-
else if (handMeshTracker != null
174+
if (handMeshTracker != null
177175
&& handMeshTracker.TryGetHandMesh(FrameTime.OnUpdate, meshFilter.mesh)
178176
&& handMeshTracker.TryLocateHandMesh(FrameTime.OnUpdate, out Pose pose))
179177
{

0 commit comments

Comments
 (0)