Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

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

Discussion in 'Graphics for ECS' started by amdroid135, Jun 21, 2021.

  1. amdroid135

    amdroid135

    Joined:
    Apr 20, 2021
    Posts:
    3
    1. How do I get the polygon(face) of the contact point (float3 on mesh)?
    2. And how can I get the material information of polygon?
    • Unlike... "UnityEngine.Physics.RaycastHit", I found no triangle index for "Unity.Physics.ColliderCastHit". :confused:
    • 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. o_O
    Code (CSharp):
    1.             if (Physics.Raycast(ray, out RaycastHit hit))
    2.             {
    3.                 int[] triangles = mesh.triangles;
    4.  
    5.                 var vertIndex1 = triangles[hit.triangleIndex * 3 + 0];
    6.                 var vertIndex2 = triangles[hit.triangleIndex * 3 + 1];
    7.                 var vertIndex3 = triangles[hit.triangleIndex * 3 + 2];
    8.  
    9.                 colorArray[vertIndex1] = Color.red;
    10.                 colorArray[vertIndex2] = Color.red;
    11.                 colorArray[vertIndex3] = Color.red;
    12.  
    13.                 mesh.colors = colorArray;
     
    Last edited: Jun 21, 2021
  2. hidingspot

    hidingspot

    Joined:
    Apr 27, 2011
    Posts:
    87
    amdroid135 likes this.