Skip to content

Commit fdb1fab

Browse files
committed
Update PlatformHandMeshVisualizer.cs
1 parent 36ec371 commit fdb1fab

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,39 +119,43 @@ protected void Update()
119119
allocator = Unity.Collections.Allocator.Temp,
120120
};
121121

122-
Debug.Log($"Success?? {HandNode} | {Time.frameCount} | {handSubsystem.updateSuccessFlags} | {updateSuccessFlags} | {(handSubsystem.updateSuccessFlags & updateSuccessFlags) != 0}");
123122
if ((handSubsystem.updateSuccessFlags & updateSuccessFlags) != 0
124123
&& (lastUpdatedFrame == Time.frameCount || handSubsystem.TryGetMeshData(out result, ref queryParams)))
125124
{
126125
lastUpdatedFrame = Time.frameCount;
127126
XRHandMeshData handMeshData = HandNode == XRNode.LeftHand ? result.leftHand : result.rightHand;
128127
handRenderer.enabled = true;
128+
Mesh mesh = meshFilter.mesh;
129129

130-
if (handMeshData.positions.IsCreated && handMeshData.indices.IsCreated)
130+
if (handMeshData.positions.Length > 0 && handMeshData.indices.Length > 0)
131131
{
132-
meshFilter.mesh.SetVertices(handMeshData.positions);
132+
mesh.SetVertices(handMeshData.positions);
133133
Unity.Collections.NativeArray<int> indices = handMeshData.indices;
134134
// This API appears to return CCW triangles, but Unity expects CW triangles
135135
for (int i = 0; i < indices.Length; i += 3)
136136
{
137137
(indices[i + 1], indices[i + 2]) = (indices[i + 2], indices[i + 1]);
138138
}
139-
meshFilter.mesh.SetIndices(indices, MeshTopology.Triangles, 0);
140-
meshFilter.mesh.RecalculateBounds();
139+
mesh.SetIndices(indices, MeshTopology.Triangles, 0);
140+
mesh.RecalculateBounds();
141141
}
142142

143-
if (handMeshData.uvs.IsCreated)
143+
if (handMeshData.uvs.IsCreated && handMeshData.uvs.Length == mesh.vertexCount)
144144
{
145-
meshFilter.mesh.SetUVs(0, handMeshData.uvs);
145+
mesh.SetUVs(0, handMeshData.uvs);
146+
}
147+
else
148+
{
149+
mesh.uv = null;
146150
}
147151

148-
if (handMeshData.normals.IsCreated)
152+
if (handMeshData.normals.IsCreated && handMeshData.normals.Length == mesh.vertexCount)
149153
{
150-
meshFilter.mesh.SetNormals(handMeshData.normals);
154+
mesh.SetNormals(handMeshData.normals);
151155
}
152156
else
153157
{
154-
meshFilter.mesh.RecalculateNormals();
158+
mesh.RecalculateNormals();
155159
}
156160

157161
if (handMeshData.TryGetRootPose(out Pose rootPose))

0 commit comments

Comments
 (0)