@@ -32,18 +32,56 @@ public MixedRealityRaycastHit(bool raycastValid, RaycastHit hitInfo)
32
32
barycentricCoordinate = hitInfo . barycentricCoordinate ;
33
33
distance = hitInfo . distance ;
34
34
triangleIndex = hitInfo . triangleIndex ;
35
- textureCoord = hitInfo . textureCoord ;
35
+
36
36
MeshCollider meshCollider = hitInfo . collider as MeshCollider ;
37
- if ( meshCollider == null || meshCollider . sharedMesh . isReadable )
37
+ if ( meshCollider == null )
38
38
{
39
+ textureCoord = hitInfo . textureCoord ;
39
40
textureCoord2 = hitInfo . textureCoord2 ;
41
+ lightmapCoord = hitInfo . lightmapCoord ;
40
42
}
41
43
else
42
44
{
43
- textureCoord2 = Vector2 . zero ;
45
+ Mesh sharedMesh = meshCollider . sharedMesh ;
46
+ if ( sharedMesh != null && sharedMesh . isReadable )
47
+ {
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
+ }
57
+
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 ;
72
+ textureCoord2 = hitInfo . textureCoord2 ;
73
+ lightmapCoord = hitInfo . lightmapCoord ;
74
+ #endif
75
+ }
76
+ else
77
+ {
78
+ textureCoord = Vector2 . zero ;
79
+ textureCoord2 = Vector2 . zero ;
80
+ lightmapCoord = Vector2 . zero ;
81
+ }
44
82
}
83
+
45
84
transform = hitInfo . transform ;
46
- lightmapCoord = hitInfo . lightmapCoord ;
47
85
collider = hitInfo . collider ;
48
86
}
49
87
else
0 commit comments