I am looking for a way to calculate surface area of a 3D mesh object and found this code from a Unity forum:
public float Area(Mesh m)
{
Vector3[] mVertices = m.vertices;
Vector3 result = Vector3.zero;
for (int p = mVertices.Length - 1, q = 0; q < mVertices.Length; p = q++)
{
result += Vector3.Cross(mVertices[q], mVertices[p]);
}
Debug.Log(result);
result *= 0.5f;
return result.magnitude;
}
But the problem is that it is not providing the correct area as I have found from testing the fbx with Revit. Revit is showing a different surface area from what this code shows.
Here is a sample mesh
Front
Its surface area as calculated by the function above is 97.4913,
while in Revit it's actually 52.811 \$m^2\$.
I don't know how revit calculate it but it provide area and volume information automatically (i have no idea how even revit works).