コード例 #1
0
        private void RemoveTerrainTriangle(MyNavigationTriangle tri)
        {
            MyWingedEdgeMesh.FaceVertexEnumerator vertexEnumerator = tri.GetVertexEnumerator();
            vertexEnumerator.MoveNext();
            Vector3 current = vertexEnumerator.Current;

            vertexEnumerator.MoveNext();
            Vector3 vector2 = vertexEnumerator.Current;

            vertexEnumerator.MoveNext();
            Vector3 vector3   = vertexEnumerator.Current;
            int     edgeIndex = tri.GetEdgeIndex(0);
            int     num2      = tri.GetEdgeIndex(1);
            int     num3      = tri.GetEdgeIndex(2);
            int     num4      = edgeIndex;

            if (!this.m_connectionHelper.TryRemoveOuterEdge(ref current, ref vector2, ref num4) && (base.Mesh.GetEdge(edgeIndex).OtherFace(tri.Index) != -1))
            {
                this.m_connectionHelper.AddOuterEdgeIndex(ref vector2, ref current, edgeIndex);
            }
            num4 = num2;
            if (!this.m_connectionHelper.TryRemoveOuterEdge(ref vector2, ref vector3, ref num4) && (base.Mesh.GetEdge(num2).OtherFace(tri.Index) != -1))
            {
                this.m_connectionHelper.AddOuterEdgeIndex(ref vector3, ref vector2, num2);
            }
            num4 = num3;
            if (!this.m_connectionHelper.TryRemoveOuterEdge(ref vector3, ref current, ref num4) && (base.Mesh.GetEdge(num3).OtherFace(tri.Index) != -1))
            {
                this.m_connectionHelper.AddOuterEdgeIndex(ref current, ref vector3, num3);
            }
            base.RemoveTriangle(tri);
        }
コード例 #2
0
        private void RemoveTerrainTriangle(MyNavigationTriangle tri)
        {
            var vertices = tri.GetVertexEnumerator();

            vertices.MoveNext();
            Vector3 aPos = vertices.Current;

            vertices.MoveNext();
            Vector3 bPos = vertices.Current;

            vertices.MoveNext();
            Vector3 cPos = vertices.Current;

            int edgeAB = tri.GetEdgeIndex(0);
            int edgeBC = tri.GetEdgeIndex(1);
            int edgeCA = tri.GetEdgeIndex(2);

            int tmp;

            ProfilerShort.Begin("Handling outer edges");
            tmp = edgeAB;
            if (!m_connectionHelper.TryRemoveOuterEdge(ref aPos, ref bPos, ref tmp))
            {
                var edge = Mesh.GetEdge(edgeAB);
                if (edge.OtherFace(tri.Index) != -1)
                {
                    m_connectionHelper.AddOuterEdgeIndex(ref bPos, ref aPos, edgeAB);
                }
            }
            tmp = edgeBC;
            if (!m_connectionHelper.TryRemoveOuterEdge(ref bPos, ref cPos, ref tmp))
            {
                var edge = Mesh.GetEdge(edgeBC);
                if (edge.OtherFace(tri.Index) != -1)
                {
                    m_connectionHelper.AddOuterEdgeIndex(ref cPos, ref bPos, edgeBC);
                }
            }
            tmp = edgeCA;
            if (!m_connectionHelper.TryRemoveOuterEdge(ref cPos, ref aPos, ref tmp))
            {
                var edge = Mesh.GetEdge(edgeCA);
                if (edge.OtherFace(tri.Index) != -1)
                {
                    m_connectionHelper.AddOuterEdgeIndex(ref aPos, ref cPos, edgeCA);
                }
            }
            ProfilerShort.End();

            ProfilerShort.Begin("Removing the tri");
            RemoveTriangle(tri);
            ProfilerShort.End();
        }
コード例 #3
0
        private bool IsFaceTriangle(MyNavigationTriangle triangle, Vector3I cubePosition, Vector3I direction)
        {
            MyWingedEdgeMesh.FaceVertexEnumerator vertexEnumerator = triangle.GetVertexEnumerator();
            vertexEnumerator.MoveNext();
            vertexEnumerator.MoveNext();
            vertexEnumerator.MoveNext();
            cubePosition *= 0x100;
            Vector3I vectori4 = (Vector3I)(cubePosition + (direction * 0x80));
            Vector3I vectori  = Vector3I.Round(vertexEnumerator.Current * 256f) - vectori4;
            Vector3I vectori2 = Vector3I.Round(vertexEnumerator.Current * 256f) - vectori4;
            Vector3I vectori3 = Vector3I.Round(vertexEnumerator.Current * 256f) - vectori4;

            return(!((vectori * direction) != Vector3I.Zero) ? (!((vectori2 * direction) != Vector3I.Zero) ? (!((vectori3 * direction) != Vector3I.Zero) ? ((vectori.AbsMax() <= 0x80) && ((vectori2.AbsMax() <= 0x80) && (vectori3.AbsMax() <= 0x80))) : false) : false) : false);
        }
コード例 #4
0
        private void RemoveAndAddTriangle(ref Vector3I positionA, ref Vector3I positionB, int registeredEdgeIndex)
        {
            MyNavigationTriangle edgeTriangle = base.GetEdgeTriangle(registeredEdgeIndex);

            MyWingedEdgeMesh.FaceVertexEnumerator vertexEnumerator = edgeTriangle.GetVertexEnumerator();
            vertexEnumerator.MoveNext();
            Vector3 current = vertexEnumerator.Current;

            vertexEnumerator.MoveNext();
            vertexEnumerator.MoveNext();
            Vector3I cube = this.FindTriangleCube(edgeTriangle.Index, ref positionA, ref positionB);

            this.RemoveTriangle(edgeTriangle, cube);
            MyNavigationTriangle tri = this.AddTriangleInternal(current, vertexEnumerator.Current, vertexEnumerator.Current);

            this.RegisterTriangleInternal(tri, ref cube);
        }
コード例 #5
0
        private bool IsFaceTriangle(MyNavigationTriangle triangle, Vector3I cubePosition, Vector3I direction)
        {
            var e = triangle.GetVertexEnumerator();

            // Quantize the point positions to 1/256ths inside each cube (but multiplied by 256 :-) )
            e.MoveNext();
            Vector3I positionA = Vector3I.Round(e.Current * 256);

            e.MoveNext();
            Vector3I positionB = Vector3I.Round(e.Current * 256);

            e.MoveNext();
            Vector3I positionC = Vector3I.Round(e.Current * 256);

            cubePosition = cubePosition * 256;

            // Change the point coordinates to be relative to the face center
            Vector3I faceCenter = cubePosition + direction * 128;

            positionA -= faceCenter;
            positionB -= faceCenter;
            positionC -= faceCenter;

            // Discard all triangles whose points are not on the plane of the face
            if (positionA * direction != Vector3I.Zero)
            {
                return(false);
            }
            if (positionB * direction != Vector3I.Zero)
            {
                return(false);
            }
            if (positionC * direction != Vector3I.Zero)
            {
                return(false);
            }

            // Discard all triangles that are not contained inside the face's square
            return(positionA.AbsMax() <= 128 && positionB.AbsMax() <= 128 && positionC.AbsMax() <= 128);
        }
コード例 #6
0
        private void RemoveTerrainTriangle(MyNavigationTriangle tri)
        {
            var vertices = tri.GetVertexEnumerator();

            vertices.MoveNext();
            Vector3 aPos = vertices.Current;
            vertices.MoveNext();
            Vector3 bPos = vertices.Current;
            vertices.MoveNext();
            Vector3 cPos = vertices.Current;

            int edgeAB = tri.GetEdgeIndex(0);
            int edgeBC = tri.GetEdgeIndex(1);
            int edgeCA = tri.GetEdgeIndex(2);

            int tmp;

            ProfilerShort.Begin("Handling outer edges");
            tmp = edgeAB;
            if (!m_connectionHelper.TryRemoveOuterEdge(ref aPos, ref bPos, ref tmp))
            {
                var edge = Mesh.GetEdge(edgeAB);
                if (edge.OtherFace(tri.Index) != -1)
                    m_connectionHelper.AddOuterEdgeIndex(ref bPos, ref aPos, edgeAB);
            }
            tmp = edgeBC;
            if (!m_connectionHelper.TryRemoveOuterEdge(ref bPos, ref cPos, ref tmp))
            {
                var edge = Mesh.GetEdge(edgeBC);
                if (edge.OtherFace(tri.Index) != -1)
                    m_connectionHelper.AddOuterEdgeIndex(ref cPos, ref bPos, edgeBC);
            }
            tmp = edgeCA;
            if (!m_connectionHelper.TryRemoveOuterEdge(ref cPos, ref aPos, ref tmp))
            {
                var edge = Mesh.GetEdge(edgeCA);
                if (edge.OtherFace(tri.Index) != -1)
                    m_connectionHelper.AddOuterEdgeIndex(ref aPos, ref cPos, edgeCA);
            }
            ProfilerShort.End();

            ProfilerShort.Begin("Removing the tri");
            RemoveTriangle(tri);
            ProfilerShort.End();
        }
コード例 #7
0
        private void RemoveTriangle(MyNavigationTriangle triangle, Vector3I cube)
        {
            var e = triangle.GetVertexEnumerator();

            e.MoveNext();
            Vector3I positionA = Vector3I.Round(e.Current * 256);

            e.MoveNext();
            Vector3I positionC = Vector3I.Round(e.Current * 256); // This is not a mistake! C is swapped with B (see also: AddTriangle...)

            e.MoveNext();
            Vector3I positionB = Vector3I.Round(e.Current * 256);

            // This should be AB, BC and CA, but after swapping it's AC, CB and BA
            int triCA = triangle.GetEdgeIndex(0);
            int triBC = triangle.GetEdgeIndex(1);
            int triAB = triangle.GetEdgeIndex(2);

            int edgeAB, edgeBC, edgeCA;

            if (!m_connectionHelper.TryGetValue(new EdgeIndex(ref positionA, ref positionB), out edgeAB))
            {
                edgeAB = -1;
            }
            if (!m_connectionHelper.TryGetValue(new EdgeIndex(ref positionB, ref positionC), out edgeBC))
            {
                edgeBC = -1;
            }
            if (!m_connectionHelper.TryGetValue(new EdgeIndex(ref positionC, ref positionA), out edgeCA))
            {
                edgeCA = -1;
            }

            // Register those edges that were not registered in the connection helper.
            // They are registered counter-clockwise, because we are in fact registering the other triangle across the edges
            if (edgeAB != -1 && triAB == edgeAB)
            {
                m_connectionHelper.Remove(new EdgeIndex(ref positionA, ref positionB));
            }
            else
            {
                m_connectionHelper.Add(new EdgeIndex(positionB, positionA), triAB);
            }

            if (edgeBC != -1 && triBC == edgeBC)
            {
                m_connectionHelper.Remove(new EdgeIndex(ref positionB, ref positionC));
            }
            else
            {
                m_connectionHelper.Add(new EdgeIndex(positionC, positionB), triBC);
            }

            if (edgeCA != -1 && triCA == edgeCA)
            {
                m_connectionHelper.Remove(new EdgeIndex(ref positionC, ref positionA));
            }
            else
            {
                m_connectionHelper.Add(new EdgeIndex(positionA, positionC), triCA);
            }

            List <int> list = null;

            m_smallTriangleRegistry.TryGetValue(cube, out list);
            Debug.Assert(list != null, "Removed triangle was not registered in the registry!");
            for (int i = 0; i < list.Count; ++i)
            {
                if (list[i] == triangle.Index)
                {
                    list.RemoveAtFast(i);
                    break;
                }
            }
            if (list.Count == 0)
            {
                m_smallTriangleRegistry.Remove(cube);
            }

            RemoveTriangle(triangle);

            if (edgeAB != -1 && triAB != edgeAB)
            {
                RemoveAndAddTriangle(ref positionA, ref positionB, edgeAB);
            }
            if (edgeBC != -1 && triBC != edgeBC)
            {
                RemoveAndAddTriangle(ref positionB, ref positionC, edgeBC);
            }
            if (edgeCA != -1 && triCA != edgeCA)
            {
                RemoveAndAddTriangle(ref positionC, ref positionA, edgeCA);
            }
        }
コード例 #8
0
        private void RemoveTriangle(MyNavigationTriangle triangle, Vector3I cube)
        {
            int num4;
            int num5;
            int num6;

            MyWingedEdgeMesh.FaceVertexEnumerator vertexEnumerator = triangle.GetVertexEnumerator();
            vertexEnumerator.MoveNext();
            Vector3I pointA = Vector3I.Round(vertexEnumerator.Current * 256f);

            vertexEnumerator.MoveNext();
            Vector3I pointB = Vector3I.Round(vertexEnumerator.Current * 256f);

            vertexEnumerator.MoveNext();
            Vector3I vectori3  = Vector3I.Round(vertexEnumerator.Current * 256f);
            int      edgeIndex = triangle.GetEdgeIndex(0);
            int      num2      = triangle.GetEdgeIndex(1);
            int      num3      = triangle.GetEdgeIndex(2);

            if (!this.m_connectionHelper.TryGetValue(new EdgeIndex(ref pointA, ref vectori3), out num4))
            {
                num4 = -1;
            }
            if (!this.m_connectionHelper.TryGetValue(new EdgeIndex(ref vectori3, ref pointB), out num5))
            {
                num5 = -1;
            }
            if (!this.m_connectionHelper.TryGetValue(new EdgeIndex(ref pointB, ref pointA), out num6))
            {
                num6 = -1;
            }
            if ((num4 == -1) || (num3 != num4))
            {
                this.m_connectionHelper.Add(new EdgeIndex(vectori3, pointA), num3);
            }
            else
            {
                this.m_connectionHelper.Remove(new EdgeIndex(ref pointA, ref vectori3));
            }
            if ((num5 == -1) || (num2 != num5))
            {
                this.m_connectionHelper.Add(new EdgeIndex(pointB, vectori3), num2);
            }
            else
            {
                this.m_connectionHelper.Remove(new EdgeIndex(ref vectori3, ref pointB));
            }
            if ((num6 == -1) || (edgeIndex != num6))
            {
                this.m_connectionHelper.Add(new EdgeIndex(pointA, pointB), edgeIndex);
            }
            else
            {
                this.m_connectionHelper.Remove(new EdgeIndex(ref pointB, ref pointA));
            }
            List <int> list = null;

            this.m_smallTriangleRegistry.TryGetValue(cube, out list);
            int index = 0;

            while (true)
            {
                if (index < list.Count)
                {
                    if (list[index] != triangle.Index)
                    {
                        index++;
                        continue;
                    }
                    list.RemoveAtFast <int>(index);
                }
                if (list.Count == 0)
                {
                    this.m_smallTriangleRegistry.Remove(cube);
                }
                base.RemoveTriangle(triangle);
                if ((num4 != -1) && (num3 != num4))
                {
                    this.RemoveAndAddTriangle(ref pointA, ref vectori3, num4);
                }
                if ((num5 != -1) && (num2 != num5))
                {
                    this.RemoveAndAddTriangle(ref vectori3, ref pointB, num5);
                }
                if ((num6 != -1) && (edgeIndex != num6))
                {
                    this.RemoveAndAddTriangle(ref pointB, ref pointA, num6);
                }
                return;
            }
        }
コード例 #9
0
        private MyNavigationTriangle GetClosestNavigationTriangle(ref Vector3 point, ref float closestDistSq)
        {
            Vector3I vectori;

            Vector3I.Round(ref point, out vectori);
            MyNavigationTriangle   triangle = null;
            Vector3I               start    = vectori - new Vector3I(4, 4, 4);
            Vector3I               end      = (Vector3I)(vectori + new Vector3I(4, 4, 4));
            Vector3I_RangeIterator iterator = new Vector3I_RangeIterator(ref start, ref end);

            while (iterator.IsValid())
            {
                List <int> list;
                this.m_smallTriangleRegistry.TryGetValue(start, out list);
                if (list != null)
                {
                    foreach (int num in list)
                    {
                        MyNavigationTriangle triangle2 = base.GetTriangle(num);
                        MyWingedEdgeMesh.FaceVertexEnumerator vertexEnumerator = triangle2.GetVertexEnumerator();
                        vertexEnumerator.MoveNext();
                        Vector3 current = vertexEnumerator.Current;
                        vertexEnumerator.MoveNext();
                        Vector3 vector2 = vertexEnumerator.Current;
                        vertexEnumerator.MoveNext();
                        Vector3 vector3 = vertexEnumerator.Current;
                        Vector3 vector4 = ((current + vector2) + vector3) / 3f;
                        Vector3 vector5 = vector2 - current;
                        Vector3 vector6 = vector3 - vector2;
                        float   num2    = Vector3.DistanceSquared(vector4, point);
                        if (num2 < (vector5.LengthSquared() + vector6.LengthSquared()))
                        {
                            Vector3 vector7 = Vector3.Cross(vector5, vector6);
                            vector7.Normalize();
                            vector5 = Vector3.Cross(vector5, vector7);
                            vector6 = Vector3.Cross(vector6, vector7);
                            float   num3    = -Vector3.Dot(vector5, current);
                            float   num4    = -Vector3.Dot(vector6, vector2);
                            Vector3 vector1 = Vector3.Cross(current - vector3, vector7);
                            float   num5    = -Vector3.Dot(vector1, vector3);
                            float   num6    = Vector3.Dot(vector5, point) + num3;
                            float   num7    = Vector3.Dot(vector6, point) + num4;
                            float   num8    = Vector3.Dot(vector1, point) + num5;
                            num2  = Vector3.Dot(vector7, point) - Vector3.Dot(vector7, vector4);
                            num2 *= num2;
                            if (num6 > 0f)
                            {
                                if (num7 <= 0f)
                                {
                                    num2 = (num8 <= 0f) ? (num2 + Vector3.DistanceSquared(vector3, point)) : (num2 + (num7 * num7));
                                }
                                else if (num8 < 0f)
                                {
                                    num2 += num8 * num8;
                                }
                            }
                            else if (num7 > 0f)
                            {
                                num2 = (num8 <= 0f) ? (num2 + Vector3.DistanceSquared(current, point)) : (num2 + (num6 * num6));
                            }
                            else if (num8 > 0f)
                            {
                                num2 += Vector3.DistanceSquared(vector2, point);
                            }
                        }
                        if (num2 < closestDistSq)
                        {
                            triangle      = triangle2;
                            closestDistSq = num2;
                        }
                    }
                }
                iterator.GetNext(out start);
            }
            return(triangle);
        }
コード例 #10
0
        private void RemoveTriangle(MyNavigationTriangle triangle, Vector3I cube)
        {
            var e = triangle.GetVertexEnumerator();
            e.MoveNext();
            Vector3I positionA = Vector3I.Round(e.Current * 256);
            e.MoveNext();
            Vector3I positionC = Vector3I.Round(e.Current * 256); // This is not a mistake! C is swapped with B (see also: AddTriangle...)
            e.MoveNext();
            Vector3I positionB = Vector3I.Round(e.Current * 256);

            // This should be AB, BC and CA, but after swapping it's AC, CB and BA
            int triCA = triangle.GetEdgeIndex(0);
            int triBC = triangle.GetEdgeIndex(1);
            int triAB = triangle.GetEdgeIndex(2);

            int edgeAB, edgeBC, edgeCA;
            if (!m_connectionHelper.TryGetValue(new EdgeIndex(ref positionA, ref positionB), out edgeAB)) edgeAB = -1;
            if (!m_connectionHelper.TryGetValue(new EdgeIndex(ref positionB, ref positionC), out edgeBC)) edgeBC = -1;
            if (!m_connectionHelper.TryGetValue(new EdgeIndex(ref positionC, ref positionA), out edgeCA)) edgeCA = -1;

            // Register those edges that were not registered in the connection helper.
            // They are registered counter-clockwise, because we are in fact registering the other triangle across the edges
            if (edgeAB != -1 && triAB == edgeAB)
                m_connectionHelper.Remove(new EdgeIndex(ref positionA, ref positionB));
            else
                m_connectionHelper.Add(new EdgeIndex(positionB, positionA), triAB);

            if (edgeBC != -1 && triBC == edgeBC)
                m_connectionHelper.Remove(new EdgeIndex(ref positionB, ref positionC));
            else
                m_connectionHelper.Add(new EdgeIndex(positionC, positionB), triBC);

            if (edgeCA != -1 && triCA == edgeCA)
                m_connectionHelper.Remove(new EdgeIndex(ref positionC, ref positionA));
            else
                m_connectionHelper.Add(new EdgeIndex(positionA, positionC), triCA);

            List<int> list = null;
            m_smallTriangleRegistry.TryGetValue(cube, out list);
            Debug.Assert(list != null, "Removed triangle was not registered in the registry!");
            for (int i = 0; i < list.Count; ++i)
            {
                if (list[i] == triangle.Index)
                {
                    list.RemoveAtFast(i);
                    break;
                }
            }
            if (list.Count == 0)
                m_smallTriangleRegistry.Remove(cube);

            RemoveTriangle(triangle);

            if (edgeAB != -1 && triAB != edgeAB)
                RemoveAndAddTriangle(ref positionA, ref positionB, edgeAB);
            if (edgeBC != -1 && triBC != edgeBC)
                RemoveAndAddTriangle(ref positionB, ref positionC, edgeBC);
            if (edgeCA != -1 && triCA != edgeCA)
                RemoveAndAddTriangle(ref positionC, ref positionA, edgeCA);
        }
コード例 #11
0
        private bool IsFaceTriangle(MyNavigationTriangle triangle, Vector3I cubePosition, Vector3I direction)
        {
            var e = triangle.GetVertexEnumerator();

            // Quantize the point positions to 1/256ths inside each cube (but multiplied by 256 :-) )
            e.MoveNext();
            Vector3I positionA = Vector3I.Round(e.Current * 256);
            e.MoveNext();
            Vector3I positionB = Vector3I.Round(e.Current * 256);
            e.MoveNext();
            Vector3I positionC = Vector3I.Round(e.Current * 256);
            cubePosition = cubePosition * 256;

            // Change the point coordinates to be relative to the face center
            Vector3I faceCenter = cubePosition + direction * 128;
            positionA -= faceCenter;
            positionB -= faceCenter;
            positionC -= faceCenter;

            // Discard all triangles whose points are not on the plane of the face
            if (positionA * direction != Vector3I.Zero) return false;
            if (positionB * direction != Vector3I.Zero) return false;
            if (positionC * direction != Vector3I.Zero) return false;

            // Discard all triangles that are not contained inside the face's square
            return (positionA.AbsMax() <= 128 && positionB.AbsMax() <= 128 && positionC.AbsMax() <= 128);
        }