Hello, i am trying to delete a triangle from my mesh. My mesh is consisted by 3 submeshes, each one is inside the other. At first I use Raycast to get the hit.triangleIndex. Then i am manipulating the vertices. I want to delete the triangle that is intersecting my inner mesh. I dont know if its the right way, but i am using raycast from each vertex against the inner mesh.
public void RayCastDeform(int triangleIndex)
{
Vector3 p0 = vertices[triangles[triangleIndex * 3 + 0]];
Vector3 p1 = vertices[triangles[triangleIndex * 3 + 1]];
Vector3 p2 = vertices[triangles[triangleIndex * 3 + 2]];
var dir0 = dirs[triangles[triangleIndex * 3 + 0]];
var dir1 = dirs[triangles[triangleIndex * 3 + 1]];
var dir2 = dirs[triangles[triangleIndex * 3 + 2]];
p0 += dir0 * 0.1f * Time.fixedDeltaTime;
p1 += dir1 * 0.1f * Time.fixedDeltaTime;
p2 += dir2 * 0.1f * Time.fixedDeltaTime;
vertices[triangles[triangleIndex * 3 + 0]] = p0;
vertices[triangles[triangleIndex * 3 + 1]] = p1;
vertices[triangles[triangleIndex * 3 + 2]] = p2;
//Returns true if the vertex pointing at the collisionBitMask layer
var p0isPointingAtBitMask = Physics.Raycast(transform.TransformPoint(p0), transform.TransformDirection(dir0), math.INFINITY, collisionBitMask);
var p1isPointingAtBitMask = Physics.Raycast(transform.TransformPoint(p1), transform.TransformDirection(dir1), math.INFINITY, collisionBitMask);
var p2isPointingAtBitMask = Physics.Raycast(transform.TransformPoint(p2), transform.TransformDirection(dir2), math.INFINITY, collisionBitMask);
//If all vertices are not pointing at collisionBitMask layer, delete the triangle
if (!p0isPointingAtBitMask && !p1isPointingAtBitMask && !p2isPointingAtBitMask )
{
Debug.Log("Triangle crossed the Rock_Layer!");
triangles.RemoveRange(triangleIndex*3, 3);
}
else
{
Debug.Log("Triangle crossed NOT the Rock_Layer!");
}
}
The thing is that is not working correctly.
I am open to suggestions for something better than this.