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)); }
public ModelTransform(ModelData data, Matrix4 transformMatrix) { this.data = data; this.transformMatrix = transformMatrix; }
internal Vertex(ModelData ModelData, int index) { this.ModelData = ModelData; this.index = index; }
internal Face(ModelData ModelData, int index) { this.ModelData = ModelData; this.index = index; }
private static bool VerticiesFlipped(List <ModelData.FaceIndex> faces, List <M3D.Model.Utils.Vector3> vertices) { return(ModelData.GenerateSignedVolume(faces, vertices) < 0.0); }
private static bool HashVertexesAndFaces_Helper(LinkedList <M3D.Model.Utils.Vector3> verticies, ref ProgressHelper progressHelper, out List <M3D.Model.Utils.Vector3> newVerticesList, out List <ModelData.FaceIndex> newFaceList) { newVerticesList = null; newFaceList = null; var num1 = 0; var num2 = 0; var source = new Dictionary <M3D.Model.Utils.Vector3, int>(); var faceIndexSet = new HashSet <ModelData.FaceIndex>(); var flag = ModelData.VerticiesFlipped(verticies); while (verticies.First != null) { M3D.Model.Utils.Vector3 vector3_1 = verticies.First.Value; ModelData.AssertIfNANOrNULL(vector3_1); verticies.RemoveFirst(); M3D.Model.Utils.Vector3 vector3_2 = verticies.First.Value; ModelData.AssertIfNANOrNULL(vector3_2); verticies.RemoveFirst(); M3D.Model.Utils.Vector3 vector3_3 = verticies.First.Value; ModelData.AssertIfNANOrNULL(vector3_3); verticies.RemoveFirst(); if (flag) { M3D.Model.Utils.Vector3 vector3_4 = vector3_1; vector3_1 = vector3_3; vector3_3 = vector3_4; } M3D.Model.Utils.Vector3 normal = ModelData.CalcNormal(vector3_1, vector3_2, vector3_3); if (!double.IsNaN(normal.X) && !double.IsNaN(normal.Y) && !double.IsNaN(normal.Z)) { int[] faceIndicies = new int[3]; M3D.Model.Utils.Vector3[] vector3Array = new M3D.Model.Utils.Vector3[3] { vector3_1, vector3_2, vector3_3 }; for (var index = 0; index < 3; ++index) { M3D.Model.Utils.Vector3 key = vector3Array[index]; int num3; if (source.ContainsKey(key)) { num3 = source[key]; } else { source.Add(key, num1); num3 = num1++; } faceIndicies[index] = num3; } for (var index1 = 0; index1 < 3; ++index1) { for (var index2 = index1 + 1; index2 < 3; ++index2) { if (faceIndicies[index1] == faceIndicies[index2]) { return(false); } } } var faceIndex = new FaceIndex(faceIndicies, normal); if (!faceIndexSet.Contains(faceIndex)) { faceIndexSet.Add(faceIndex); } progressHelper.Process(num2 += 3); } } IEnumerable <M3D.Model.Utils.Vector3> collection = source.OrderBy <KeyValuePair <M3D.Model.Utils.Vector3, int>, int>(pair => pair.Value).Select <KeyValuePair <M3D.Model.Utils.Vector3, int>, M3D.Model.Utils.Vector3>(pair => pair.Key); newVerticesList = new List <M3D.Model.Utils.Vector3>(collection); source.Clear(); newFaceList = new List <ModelData.FaceIndex>(faceIndexSet); faceIndexSet.Clear(); return(true); }