public static DMesh3 Reduce(this DMesh3 mesh, float percent, bool project = true) { if (!mesh.CheckValidity(eFailMode: FailMode.ReturnOnly)) { return(mesh); } var r = new Reducer(mesh); if (project) { var tree = mesh.AABBTree(); r.SetProjectionTarget(new MeshProjectionTarget(tree.Mesh, tree)); // http://www.gradientspace.com/tutorials/2017/8/30/mesh-simplification // r.ProjectionMode = Reducer.TargetProjectionMode.Inline; } var target = mesh.VertexCount * percent / 100.0f; r.ReduceToVertexCount((int)target); var newMesh = r.Mesh.Compact(); var g = newMesh.ToIGeometry(); Debug.Assert(g.AreAllIndicesValid()); //Debug.Assert(g.AreAllVerticesUsed()); return(newMesh); }