private static List <ModelData.EdgeIndex> GenerateEndgeList(List <ModelData.FaceIndex> faceList, ref ProgressHelper progressHelper) { var hashCollection = new Dictionary <ModelData.EdgeIndex, ModelData.EdgeIndex>(); for (var index = 0; index < faceList.Count; ++index) { ModelData.FaceIndex face = faceList[index]; ModelData.AppendEdgeToHash_Helper(ref hashCollection, index, face.P1, face.P2); ModelData.AppendEdgeToHash_Helper(ref hashCollection, index, face.P2, face.P3); ModelData.AppendEdgeToHash_Helper(ref hashCollection, index, face.P1, face.P3); progressHelper.Process(index); } return(hashCollection.Values.ToList <ModelData.EdgeIndex>()); }
private static List <ModelData.VertexIndex> GenerateFaceLink_Helper(List <M3D.Model.Utils.Vector3> newVerticesList, List <ModelData.FaceIndex> newFaceList, ProgressHelper progressHelper = null) { var vertexIndexList = new List <ModelData.VertexIndex>(newFaceList.Count); foreach (M3D.Model.Utils.Vector3 newVertices in newVerticesList) { vertexIndexList.Add(new ModelData.VertexIndex(new List <int>())); } for (var index = 0; index < newFaceList.Count; ++index) { ModelData.FaceIndex newFace = newFaceList[index]; vertexIndexList[newFace.P1].Faces.Add(index); vertexIndexList[newFace.P2].Faces.Add(index); vertexIndexList[newFace.P3].Faces.Add(index); progressHelper?.Process(index); } return(vertexIndexList); }
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); }