- Home /
Question by
Navy_Seals · Sep 30, 2021 at 05:27 AM ·
meshmathtrianglesmeshfiltermesh vertices
How to detect a flat area in a mesh?
I'm trying to get the flat surface of a mesh. Basically, I will raycast to the mesh and get a particular point. First thing, I need to get the surface area like a square on the given mesh where I am raycasting, then I need to calculate if that area is flat or not.
I got this below code for detecting at least one flat surface in a mesh.
bool HasFlatshadedSurface(Mesh m)
{
Vector3[] normals = m.normals;
int[] indices = m.triangles;
int triangleCount = indices.Length / 3;
for (int i = 0; i < triangleCount; i++)
{
Vector3 n1 = normals[indices[i * 3]];
Vector3 n2 = normals[indices[i * 3 + 1]];
Vector3 n3 = normals[indices[i * 3 + 2]];
if (n1 == n2 && n1 == n3)
return true;
}
return false;
}
But, my case is different where as I am trying to get a particular area which I need to scan and get if it is flat or not. How can I do this?
Comment
Your answer
Follow this Question
Related Questions
2d custom mesh triangulator problem 1 Answer
How to manipulate(flatten) the Mesh of an object 0 Answers
Generated Mesh Triangles not Being Made/Visible? 1 Answer
Save only visible part of mesh 1 Answer
How to recalculate mesh triangles 0 Answers