How do i get the polygon(face) on the contact point(float3) of mesh?

  • 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”. :face_with_spiral_eyes:

  • 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. :eyes:

            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;

I haven’t needed this feature myself so can’t give too much help, but the documentation makes it sound possible:
https://docs.unity3d.com/Packages/com.unity.physics@0.6/manual/collision_queries.html#using-collider-keys

1 Like