private UnityEngine.Mesh ConvertMesh(MeshDecimator.Mesh fatMesh) { if (fatMesh.VertexCount == 0) { return(new UnityEngine.Mesh()); } // Merge Same Verts Dictionary <MeshDecimator.Math.Vector3d, int> newVertIndexes = new Dictionary <MeshDecimator.Math.Vector3d, int>(); List <MeshDecimator.Math.Vector3d> newVerts = new List <MeshDecimator.Math.Vector3d>(); int[] newIndicies = new int[fatMesh.Indices.Length]; for (int i = 0; i < fatMesh.Vertices.Length; i++) { if (!newVertIndexes.ContainsKey(fatMesh.Vertices[i])) { newVerts.Add(fatMesh.Vertices[i]); newVertIndexes[fatMesh.Vertices[i]] = newVerts.Count - 1; } } for (int i = 0; i < fatMesh.Indices.Length; i++) { MeshDecimator.Math.Vector3d v = fatMesh.Vertices[fatMesh.Indices[i]]; newIndicies[i] = newVertIndexes[v]; } MeshDecimator.Mesh mergedMesh = new MeshDecimator.Mesh(newVerts.ToArray(), newIndicies); UnityEngine.Mesh result = MeshDecimator.Unity.MeshDecimatorUtility.DecimateMeshBasic(mergedMesh, Matrix4x4.identity, m_decimatePct, true, Callback); result.RecalculateBounds(); result.RecalculateNormals(); Vector2[] uv = Unwrapping.GeneratePerTriangleUV(result); MeshUtility.SetPerTriangleUV2(result, uv); // Unwrapping.GenerateSecondaryUVSet(result); return(result); }