Skip to content

Commit e316e74

Browse files
committed
Update to only read texture coordinates when they exist
1 parent ec3b0ad commit e316e74

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

Assets/MRTK/Core/Definitions/InputSystem/MixedRealityRaycastHit.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,44 @@ public MixedRealityRaycastHit(bool raycastValid, RaycastHit hitInfo)
3232
barycentricCoordinate = hitInfo.barycentricCoordinate;
3333
distance = hitInfo.distance;
3434
triangleIndex = hitInfo.triangleIndex;
35-
textureCoord = hitInfo.textureCoord;
35+
3636
MeshCollider meshCollider = hitInfo.collider as MeshCollider;
3737
if (meshCollider == null || meshCollider.sharedMesh.isReadable)
3838
{
39+
#if UNITY_2019_4_OR_NEWER
40+
if (meshCollider.sharedMesh.HasVertexAttribute(UnityEngine.Rendering.VertexAttribute.TexCoord0))
41+
{
42+
textureCoord = hitInfo.textureCoord;
43+
}
44+
else
45+
{
46+
textureCoord = Vector2.zero;
47+
}
48+
49+
if (meshCollider.sharedMesh.HasVertexAttribute(UnityEngine.Rendering.VertexAttribute.TexCoord1))
50+
{
51+
textureCoord2 = hitInfo.textureCoord2;
52+
lightmapCoord = hitInfo.lightmapCoord;
53+
}
54+
else
55+
{
56+
textureCoord2 = Vector2.zero;
57+
lightmapCoord = Vector2.zero;
58+
}
59+
#else
60+
textureCoord = hitInfo.textureCoord;
3961
textureCoord2 = hitInfo.textureCoord2;
62+
lightmapCoord = hitInfo.lightmapCoord;
63+
#endif
4064
}
4165
else
4266
{
67+
textureCoord = Vector2.zero;
4368
textureCoord2 = Vector2.zero;
69+
lightmapCoord = Vector2.zero;
4470
}
71+
4572
transform = hitInfo.transform;
46-
lightmapCoord = hitInfo.lightmapCoord;
4773
collider = hitInfo.collider;
4874
}
4975
else

0 commit comments

Comments
 (0)