Skip to content

Commit f70b0e7

Browse files
committed
Only call sharedMesh once
1 parent 5827127 commit f70b0e7

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

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

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,41 +40,45 @@ public MixedRealityRaycastHit(bool raycastValid, RaycastHit hitInfo)
4040
textureCoord2 = hitInfo.textureCoord2;
4141
lightmapCoord = hitInfo.lightmapCoord;
4242
}
43-
else if (meshCollider.sharedMesh.isReadable)
43+
else
4444
{
45-
#if UNITY_2019_4_OR_NEWER
46-
if (meshCollider.sharedMesh.HasVertexAttribute(UnityEngine.Rendering.VertexAttribute.TexCoord0))
47-
{
48-
textureCoord = hitInfo.textureCoord;
49-
}
50-
else
45+
Mesh sharedMesh = meshCollider.sharedMesh;
46+
if (sharedMesh != null && sharedMesh.isReadable)
5147
{
52-
textureCoord = Vector2.zero;
53-
}
48+
#if UNITY_2019_4_OR_NEWER
49+
if (sharedMesh.HasVertexAttribute(UnityEngine.Rendering.VertexAttribute.TexCoord0))
50+
{
51+
textureCoord = hitInfo.textureCoord;
52+
}
53+
else
54+
{
55+
textureCoord = Vector2.zero;
56+
}
5457

55-
// This checks for TexCoord1, since textureCoord2 and lightmapCoord both query that index
56-
// via CalculateRaycastTexCoord(collider, m_UV, m_Point, m_FaceID, 1); (the last parameter is the index)
57-
if (meshCollider.sharedMesh.HasVertexAttribute(UnityEngine.Rendering.VertexAttribute.TexCoord1))
58-
{
58+
// This checks for TexCoord1, since textureCoord2 and lightmapCoord both query that index
59+
// via CalculateRaycastTexCoord(collider, m_UV, m_Point, m_FaceID, 1); (the last parameter is the index)
60+
if (sharedMesh.HasVertexAttribute(UnityEngine.Rendering.VertexAttribute.TexCoord1))
61+
{
62+
textureCoord2 = hitInfo.textureCoord2;
63+
lightmapCoord = hitInfo.lightmapCoord;
64+
}
65+
else
66+
{
67+
textureCoord2 = Vector2.zero;
68+
lightmapCoord = Vector2.zero;
69+
}
70+
#else
71+
textureCoord = hitInfo.textureCoord;
5972
textureCoord2 = hitInfo.textureCoord2;
6073
lightmapCoord = hitInfo.lightmapCoord;
74+
#endif
6175
}
6276
else
6377
{
78+
textureCoord = Vector2.zero;
6479
textureCoord2 = Vector2.zero;
6580
lightmapCoord = Vector2.zero;
6681
}
67-
#else
68-
textureCoord = hitInfo.textureCoord;
69-
textureCoord2 = hitInfo.textureCoord2;
70-
lightmapCoord = hitInfo.lightmapCoord;
71-
#endif
72-
}
73-
else
74-
{
75-
textureCoord = Vector2.zero;
76-
textureCoord2 = Vector2.zero;
77-
lightmapCoord = Vector2.zero;
7882
}
7983

8084
transform = hitInfo.transform;

0 commit comments

Comments
 (0)