Esempio n. 1
0
 public FaceIndex(int P1, int P2, int P3, M3D.Model.Utils.Vector3 normal)
 {
     this.P1 = P1;
     this.P2 = P2;
     this.P3 = P3;
     Normal  = normal;
 }
Esempio n. 2
0
        public void Scale(M3D.Model.Utils.Vector3 scale)
        {
            for (var index = 0; index < Verticies.Count; ++index)
            {
                Verticies[index] *= scale;
            }

            Min *= scale;
            Max *= scale;
        }
Esempio n. 3
0
        public void Translate(M3D.Model.Utils.Vector3 translate)
        {
            for (var index = 0; index < Verticies.Count; ++index)
            {
                Verticies[index] += translate;
            }

            Min += translate;
            Max += translate;
        }
Esempio n. 4
0
        private static void AssertIfNANOrNULL(M3D.Model.Utils.Vector3 p1)
        {
            if (p1 == null)
            {
                throw new NullReferenceException("Null point in loading");
            }

            if (double.IsNaN(p1.X) || double.IsNaN(p1.Y) || double.IsNaN(p1.Z))
            {
                throw new Exception("Point contains a NAN");
            }
        }
Esempio n. 5
0
        public List <M3D.Model.Utils.Vector3> CalculateHullPointsUsingTransformMatrix(Matrix4 matrix)
        {
            var vector3List = new List <M3D.Model.Utils.Vector3>(ConvexHullIndicies.Count);

            foreach (var convexHullIndicy in ConvexHullIndicies)
            {
                var vector3 = new M3D.Model.Utils.Vector3(Verticies[convexHullIndicy]);
                vector3.MatrixProduct(matrix);
                vector3List.Add(vector3);
            }
            return(vector3List);
        }
Esempio n. 6
0
        private static double GenerateSignedVolume(List <ModelData.FaceIndex> faces, List <M3D.Model.Utils.Vector3> vertices)
        {
            var num1 = 0.0;

            for (var index = 0; index < faces.Count; ++index)
            {
                M3D.Model.Utils.Vector3 vertex1 = vertices[faces[index].P1];
                M3D.Model.Utils.Vector3 vertex2 = vertices[faces[index].P2];
                M3D.Model.Utils.Vector3 vertex3 = vertices[faces[index].P3];
                var num2 = vertex1.X * (double)vertex2.Y * vertex3.Z + vertex1.Y * (double)vertex2.Z * vertex3.X + vertex1.Z * (double)vertex2.X * vertex3.Y - vertex1.Z * (double)vertex2.Y * vertex3.X - vertex1.Y * (double)vertex2.X * vertex3.Z - vertex1.X * (double)vertex2.Z * vertex3.Y;
                num1 += num2 / 6.0;
            }
            return(num1);
        }
Esempio n. 7
0
        public static M3D.Model.Utils.Vector3 CalcNormal(M3D.Model.Utils.Vector3 _a, M3D.Model.Utils.Vector3 _b, M3D.Model.Utils.Vector3 _c)
        {
            var num1  = _b.X - _a.X;
            var num2  = _b.Y - _a.Y;
            var num3  = _b.Z - _a.Z;
            var num4  = _c.X - _a.X;
            var num5  = _c.Y - _a.Y;
            var num6  = _c.Z - _a.Z;
            var num7  = num2 * (double)num6 - num3 * (double)num5;
            var num8  = (float)(num3 * (double)num4 - num1 * (double)num6);
            var num9  = (float)(num1 * (double)num5 - num2 * (double)num4);
            var num10 = (float)Math.Sqrt(num7 * num7 + num8 * (double)num8 + num9 * (double)num9);

            return(new M3D.Model.Utils.Vector3((float)num7 / num10, num8 / num10, num9 / num10));
        }
Esempio n. 8
0
        private static void GenerateOrderedList(ref LinkedList <M3D.Model.Utils.Vector3> verticesList, LinkedList <int[]> faceIndicesList)
        {
            M3D.Model.Utils.Vector3[] vector3Array = new M3D.Model.Utils.Vector3[verticesList.Count];
            LinkedListNode <M3D.Model.Utils.Vector3> linkedListNode1 = verticesList.First;

            for (var index = 0; index < verticesList.Count; ++index)
            {
                vector3Array[index] = linkedListNode1.Value;
                linkedListNode1     = linkedListNode1.Next;
            }
            verticesList.Clear();
            LinkedListNode <int[]> linkedListNode2 = faceIndicesList.First;

            while (linkedListNode2 != null)
            {
                int[] numArray = linkedListNode2.Value;
                linkedListNode2 = linkedListNode2.Next;
                switch (numArray.Length)
                {
                case 0:
                    continue;

                case 3:
                    foreach (var index in numArray)
                    {
                        verticesList.AddLast(vector3Array[index]);
                    }

                    continue;

                case 4:
                    for (var index = 0; index < 3; ++index)
                    {
                        verticesList.AddLast(vector3Array[index]);
                    }

                    for (var index = 0; index < 3; ++index)
                    {
                        verticesList.AddLast(vector3Array[index + 1]);
                    }

                    continue;

                default:
                    throw new Exception(string.Format("ExpandVertices: was give a face with {0} indicies", numArray.Length));
                }
            }
        }
Esempio n. 9
0
        private static bool VerticiesFlipped(LinkedList <M3D.Model.Utils.Vector3> linkedVertex)
        {
            var num1 = 0.0;
            LinkedListNode <M3D.Model.Utils.Vector3> linkedListNode = linkedVertex.First;

            while (linkedListNode != null)
            {
                M3D.Model.Utils.Vector3 vector3_1 = linkedListNode.Value;
                LinkedListNode <M3D.Model.Utils.Vector3> next1 = linkedListNode.Next;
                M3D.Model.Utils.Vector3 vector3_2 = next1.Value;
                LinkedListNode <M3D.Model.Utils.Vector3> next2 = next1.Next;
                M3D.Model.Utils.Vector3 vector3_3 = next2.Value;
                linkedListNode = next2.Next;
                var num2 = vector3_1.X * (double)vector3_2.Y * vector3_3.Z + vector3_1.Y * (double)vector3_2.Z * vector3_3.X + vector3_1.Z * (double)vector3_2.X * vector3_3.Y - vector3_1.Z * (double)vector3_2.Y * vector3_3.X - vector3_1.Y * (double)vector3_2.X * vector3_3.Z - vector3_1.X * (double)vector3_2.Z * vector3_3.Y;
                num1 += num2 / 6.0;
            }
            return(num1 < 0.0);
        }
Esempio n. 10
0
        private void ProcessMinMaxBounds()
        {
            var maxValue1 = float.MaxValue;
            var maxValue2 = float.MaxValue;
            var maxValue3 = float.MaxValue;
            var minValue1 = float.MinValue;
            var minValue2 = float.MinValue;
            var minValue3 = float.MinValue;
            List <M3D.Model.Utils.Vector3> convexHullVertices = GetAllConvexHullVertices();

            for (var index = 0; index < convexHullVertices.Count; ++index)
            {
                MinMaxBounds_Helper(ref maxValue1, ref minValue1, convexHullVertices[index].X);
                MinMaxBounds_Helper(ref maxValue2, ref minValue2, convexHullVertices[index].Y);
                MinMaxBounds_Helper(ref maxValue3, ref minValue3, convexHullVertices[index].Z);
            }
            Min = new M3D.Model.Utils.Vector3(maxValue1, maxValue2, maxValue3);
            Max = new M3D.Model.Utils.Vector3(minValue1, minValue2, minValue3);
        }
Esempio n. 11
0
        public void GetMinMaxWithTransform(Matrix4 matrix, out M3D.Model.Utils.Vector3 min, out M3D.Model.Utils.Vector3 max)
        {
            var maxValue1 = float.MaxValue;
            var maxValue2 = float.MaxValue;
            var maxValue3 = float.MaxValue;
            var minValue1 = float.MinValue;
            var minValue2 = float.MinValue;
            var minValue3 = float.MinValue;
            List <M3D.Model.Utils.Vector3> convexHullVertices = GetAllConvexHullVertices();

            for (var index = 0; index < convexHullVertices.Count; ++index)
            {
                var vector3 = M3D.Model.Utils.Vector3.MatrixProduct(matrix, convexHullVertices[index]);
                MinMaxBounds_Helper(ref maxValue1, ref minValue1, vector3.X);
                MinMaxBounds_Helper(ref maxValue2, ref minValue2, vector3.Y);
                MinMaxBounds_Helper(ref maxValue3, ref minValue3, vector3.Z);
            }
            min = new M3D.Model.Utils.Vector3(maxValue1, maxValue2, maxValue3);
            max = new M3D.Model.Utils.Vector3(minValue1, minValue2, minValue3);
        }
Esempio n. 12
0
 public FaceIndex(int[] faceIndicies, M3D.Model.Utils.Vector3 normal)
     : this(faceIndicies[0], faceIndicies[1], faceIndicies[2], normal)
 {
 }
Esempio n. 13
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);
        }