using System.Numerics; namespace Engine.Graphics; /// /// Shared mesh math utilities used by loaders and procedural generators. /// public static class MeshMath { /// /// Compute a flat face normal from three vertex positions. /// Falls back to Vector3.UnitY for degenerate (zero-area) triangles. /// public static Vector3 ComputeFaceNormal(Vector3 a, Vector3 b, Vector3 c) { var ab = b - a; var ac = c - a; // Cross(ac, ab) instead of Cross(ab, ac) to match CW winding in typical OBJ files var normal = Vector3.Cross(ac, ab); if (normal.LengthSquared() > 0.00001f) normal = Vector3.Normalize(normal); else normal = Vector3.UnitY; return normal; } }