using System.Collections.Generic; using global::System.Numerics; namespace Pilz.S3DFileParser { public class Mesh { public List Vertices { get; private set; } = new List(); public List Normals { get; private set; } = new List(); public List UVs { get; private set; } = new List(); public List VertexColors { get; private set; } = new List(); public List Faces { get; private set; } = new List(); public void CenterModel() { CenterModel(new[] { this }); } public static void CenterModel(IEnumerable meshes) { int avgX = 0; int avgY = 0; int avgZ = 0; long vertsCount = 0L; foreach (Mesh m in meshes) { foreach (Vertex v in m.Vertices) { avgX = (int)(avgX + v.X); avgY = (int)(avgY + v.Y); avgZ = (int)(avgZ + v.Z); } vertsCount += m.Vertices.Count; } var avg = new Vector3(avgX, avgY, avgZ); avg /= new Vector3(vertsCount); foreach (Mesh m in meshes) { foreach (Vertex v in m.Vertices) { v.X -= avg.X; v.Y -= avg.Y; v.Z -= avg.Z; } } } } }