-
How do I get the polygon(face) of the contact point (float3 on mesh)?
-
And how can I get the material information of polygon?
-
Unlike… “UnityEngine.Physics.RaycastHit”, I found no triangle index for “Unity.Physics.ColliderCastHit”.
-
So… I would like to know how polygon, material, and color can be obtained directly from the specific coordinates of the mesh surface of Unity.Rendering.RenderMesh or inside mesh(UnityEngine.Mesh) or every way.
if (Physics.Raycast(ray, out RaycastHit hit))
{
int[] triangles = mesh.triangles;
var vertIndex1 = triangles[hit.triangleIndex * 3 + 0];
var vertIndex2 = triangles[hit.triangleIndex * 3 + 1];
var vertIndex3 = triangles[hit.triangleIndex * 3 + 2];
colorArray[vertIndex1] = Color.red;
colorArray[vertIndex2] = Color.red;
colorArray[vertIndex3] = Color.red;
mesh.colors = colorArray;