Beispiel #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);
        }
        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();
        }
        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();
        }
        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);
            }
        }
Beispiel #5
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;
            }
        }
        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);
        }