internal static ModelData Create(LinkedList <M3D.Model.Utils.Vector3> verticies, LinkedList <int[]> triangleIndecies = null, ProgressHelper.PercentageDelagate percentageDeligate = null) { var stopwatch = new Stopwatch(); stopwatch.Start(); var progressHelper = new ProgressHelper(percentageDeligate, 3); if (triangleIndecies != null) { ModelData.GenerateOrderedList(ref verticies, triangleIndecies); } if (verticies.Count % 3 != 0) { return(null); } progressHelper.SetStage(verticies.Count <M3D.Model.Utils.Vector3>()); if (!ModelData.HashVertexesAndFaces_Helper(verticies, ref progressHelper, out List <Utils.Vector3> newVerticesList, out List <FaceIndex> newFaceList)) { return(null); } progressHelper.SetStage(newFaceList.Count <ModelData.FaceIndex>()); List <ModelData.VertexIndex> faceLinkHelper = ModelData.GenerateFaceLink_Helper(newVerticesList, newFaceList, progressHelper); var modelData = new ModelData(newFaceList, newVerticesList, faceLinkHelper); modelData.InitalizeConvexHull(modelData.GetAllVertexs()); modelData.ProcessMinMaxBounds(); stopwatch.Stop(); if (percentageDeligate == null) { return(modelData); } percentageDeligate(100); return(modelData); }
public static ModelData Stitch(List <ModelTransform> modelTransforms) { var capacity1 = 0; var capacity2 = 0; foreach (ModelTransform modelTransform in modelTransforms) { capacity1 += modelTransform.data.GetFaceCount(); capacity2 += modelTransform.data.GetVertexCount(); } var newFaceList = new List <ModelData.FaceIndex>(capacity1); var newVerticesList = new List <M3D.Model.Utils.Vector3>(capacity2); var num1 = 0; var num2 = 0; foreach (ModelTransform modelTransform in modelTransforms) { var faceCount = modelTransform.data.GetFaceCount(); var vertexCount = modelTransform.data.GetVertexCount(); for (var index = 0; index < faceCount; ++index) { ModelData.Face face = modelTransform.data.GetFace(index); newFaceList.Add(new ModelData.FaceIndex(face.Index1 + num2, face.Index2 + num2, face.Index3 + num2, face.Normal)); } for (var index = 0; index < vertexCount; ++index) { var vector3 = Utils.Vector3.MatrixProduct(modelTransform.transformMatrix, modelTransform.data[index]); newVerticesList.Add(vector3); } num1 += faceCount; num2 += vertexCount; } List <ModelData.VertexIndex> faceLinkHelper = ModelData.GenerateFaceLink_Helper(newVerticesList, newFaceList, null); return(new ModelData(newFaceList, newVerticesList, faceLinkHelper)); }