/// <summary> /// Decimates a mesh. /// </summary> /// <param name="algorithm">The decimation algorithm.</param> /// <param name="mesh">The mesh to decimate.</param> /// <param name="targetTriangleCount">The target triangle count.</param> /// <returns>The decimated mesh.</returns> public static Mesh DecimateMesh(DecimationAlgorithm algorithm, Mesh mesh, int targetTriangleCount) { if (algorithm == null) { throw new ArgumentNullException("algorithm"); } else if (mesh == null) { throw new ArgumentNullException("mesh"); } int currentTriangleCount = mesh.TriangleCount; if (targetTriangleCount > currentTriangleCount) { targetTriangleCount = currentTriangleCount; } else if (targetTriangleCount < 0) { targetTriangleCount = 0; } algorithm.Initialize(mesh); algorithm.DecimateMesh(targetTriangleCount); return(algorithm.ToMesh()); }
/// <summary> /// Creates a specific decimation algorithm. /// </summary> /// <param name="algorithm">The desired algorithm.</param> /// <returns>The decimation algorithm.</returns> public static DecimationAlgorithm CreateAlgorithm(Algorithm algorithm) { DecimationAlgorithm alg = null; switch (algorithm) { case Algorithm.Default: case Algorithm.FastQuadricMesh: alg = new FastQuadricMeshSimplification(); break; default: throw new ArgumentException("The specified algorithm is not supported.", "algorithm"); } return(alg); }
/// <summary> /// Decimates a mesh without losing any quality. /// </summary> /// <param name="algorithm">The decimation algorithm.</param> /// <param name="mesh">The mesh to decimate.</param> /// <returns>The decimated mesh.</returns> public static Mesh DecimateMeshLossless(DecimationAlgorithm algorithm, Mesh mesh) { if (algorithm == null) { throw new ArgumentNullException("algorithm"); } else if (mesh == null) { throw new ArgumentNullException("mesh"); } int currentTriangleCount = mesh.TriangleCount; algorithm.Initialize(mesh); algorithm.DecimateMeshLossless(); return(algorithm.ToMesh()); }