public MyNavigationMesh(MyNavgroupLinks externalLinks, int trianglePrealloc = 16, Func <long> timestampFunction = null)
     : base(128, timestampFunction)
 {
     m_triPool       = new MyDynamicObjectPool <MyNavigationTriangle>(trianglePrealloc);
     m_mesh          = new MyWingedEdgeMesh();
     m_externalLinks = externalLinks;
 }
Exemple #2
0
 public void DebugDraw(ref Matrix drawMatrix, MyWingedEdgeMesh mesh)
 {
     Dictionary <Vector3I, int> .Enumerator enumerator = this.m_outerEdgePoints.EnumerateBins();
     for (int i = 0; enumerator.MoveNext(); i++)
     {
         int binIndex = MyCestmirDebugInputComponent.BinIndex;
         if ((binIndex == this.m_outerEdgePoints.InvalidIndex) || (i == binIndex))
         {
             BoundingBoxD xd;
             BoundingBoxD xd2;
             Vector3I     key   = enumerator.Current.Key;
             int          index = enumerator.Current.Value;
             this.m_outerEdgePoints.GetLocalBinBB(ref key, out xd);
             xd2.Min = Vector3D.Transform(xd.Min, drawMatrix);
             xd2.Max = Vector3D.Transform(xd.Max, drawMatrix);
             while (true)
             {
                 if (index == this.m_outerEdgePoints.InvalidIndex)
                 {
                     MyRenderProxy.DebugDrawAABB(xd2, Color.PowderBlue, 1f, 1f, false, false, false);
                     break;
                 }
                 Vector3 point = this.m_outerEdgePoints.GetPoint(index);
                 MyWingedEdgeMesh.Edge edge = mesh.GetEdge(this.m_outerEdgePoints.GetData(index).EdgeIndex);
                 Vector3  vertexPosition    = mesh.GetVertexPosition(edge.Vertex2);
                 Vector3D pointTo           = Vector3D.Transform(point, drawMatrix);
                 MyRenderProxy.DebugDrawArrow3D(Vector3D.Transform((mesh.GetVertexPosition(edge.Vertex1) + vertexPosition) * 0.5f, drawMatrix), pointTo, Color.Yellow, new Color?(Color.Yellow), false, 0.1, null, 0.5f, false);
                 index = this.m_outerEdgePoints.GetNextBinIndex(index);
             }
         }
     }
 }
Exemple #3
0
 public MyNavigationMesh(MyNavgroupLinks externalLinks, int trianglePrealloc = 0x10, Func <long> timestampFunction = null) : base(0x80, timestampFunction)
 {
     this.m_vertexList    = new List <Vector3>();
     this.m_triPool       = new MyDynamicObjectPool <MyNavigationTriangle>(trianglePrealloc);
     this.m_mesh          = new MyWingedEdgeMesh();
     this.m_externalLinks = externalLinks;
 }
Exemple #4
0
        public void GetEdgeVertices(int index, out Vector3 pred, out Vector3 succ)
        {
            MyWingedEdgeMesh mesh = this.m_navMesh.Mesh;

            MyWingedEdgeMesh.Edge edge = mesh.GetEdge(this.GetEdgeIndex(index));
            pred = mesh.GetVertexPosition(edge.GetFacePredVertex(this.m_triIndex));
            succ = mesh.GetVertexPosition(edge.GetFaceSuccVertex(this.m_triIndex));
        }
Exemple #5
0
        public void GetEdgeVertices(int index, out Vector3 pred, out Vector3 succ)
        {
            MyWingedEdgeMesh mesh = m_navMesh.Mesh;

            int i = GetEdgeIndex(index);

            MyWingedEdgeMesh.Edge edge = mesh.GetEdge(i);
            pred = mesh.GetVertex(edge.GetFacePredVertex(m_triIndex));
            succ = mesh.GetVertex(edge.GetFaceSuccVertex(m_triIndex));
        }
Exemple #6
0
        public void DebugDraw(ref Matrix drawMatrix, MyWingedEdgeMesh mesh)
        {
            var binEnum = m_outerEdgePoints.EnumerateBins();
            int i       = 0;

            while (binEnum.MoveNext())
            {
                int binIndex = Sandbox.Game.Gui.MyCestmirDebugInputComponent.BinIndex;
                if (binIndex == -1 || i == binIndex)
                {
                    Vector3I position     = binEnum.Current.Key;
                    int      storageIndex = binEnum.Current.Value;

                    if (storageIndex == -1)
                    {
                        continue;
                    }

                    BoundingBoxD bb, bbTform;
                    m_outerEdgePoints.GetLocalBinBB(ref position, out bb);
                    bbTform.Min = Vector3D.Transform(bb.Min, drawMatrix);
                    bbTform.Max = Vector3D.Transform(bb.Max, drawMatrix);

                    m_outerEdgePoints.CollectStorage(storageIndex, ref m_tmpOuterEdgePointList);
                    foreach (var point in m_tmpOuterEdgePointList)
                    {
                        var     edge = mesh.GetEdge(point.EdgeIndex);
                        Vector3 v1   = mesh.GetVertex(edge.Vertex1);
                        Vector3 v2   = mesh.GetVertex(edge.Vertex2);
                        Vector3 vc   = (v1 + v2) * 0.5f;
                        Vector3 vertex;
                        if (point.FirstPoint)
                        {
                            vertex = v2 * 0.9f + vc * 0.1f;
                        }
                        else
                        {
                            vertex = v1 * 0.9f + vc * 0.1f;
                        }

                        Vector3D vertexTformed = vertex;
                        vertexTformed = Vector3D.Transform(vertexTformed, drawMatrix);

                        VRageRender.MyRenderProxy.DebugDrawSphere(vertexTformed, 0.025f, Color.Yellow, 1.0f, false);
                    }

                    VRageRender.MyRenderProxy.DebugDrawAABB(bbTform, Color.PowderBlue, 1.0f, 1.0f, false);
                }

                i++;
            }
        }
Exemple #7
0
        public bool IsEdgeVertexDangerous(int index, bool predVertex)
        {
            MyWingedEdgeMesh mesh = this.m_navMesh.Mesh;
            int edgeIndex         = this.GetEdgeIndex(index);

            MyWingedEdgeMesh.Edge edge = mesh.GetEdge(edgeIndex);
            int vertexIndex            = predVertex ? edge.GetFacePredVertex(this.m_triIndex) : edge.GetFaceSuccVertex(this.m_triIndex);

            while (!IsTriangleDangerous(edge.VertexLeftFace(vertexIndex)))
            {
                int nextVertexEdge = edge.GetNextVertexEdge(vertexIndex);
                edge = mesh.GetEdge(nextVertexEdge);
                if (nextVertexEdge == edgeIndex)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #8
0
        public MyNavigationEdge GetNavigationEdge(int index)
        {
            MyWingedEdgeMesh mesh = this.m_navMesh.Mesh;
            int edgeIndex         = this.GetEdgeIndex(index);

            MyWingedEdgeMesh.Edge edge = mesh.GetEdge(edgeIndex);
            MyNavigationTriangle  triA = null;
            MyNavigationTriangle  triB = null;

            if (edge.LeftFace != -1)
            {
                triA = mesh.GetFace(edge.LeftFace).GetUserData <MyNavigationTriangle>();
            }
            if (edge.RightFace != -1)
            {
                triB = mesh.GetFace(edge.RightFace).GetUserData <MyNavigationTriangle>();
            }
            MyNavigationEdge.Static.Init(triA, triB, edgeIndex);
            return(MyNavigationEdge.Static);
        }
Exemple #9
0
        /// <summary>
        /// Whether it's dangerous for the bot to navigate close to this edge
        /// </summary>
        public bool IsEdgeVertexDangerous(int index, bool predVertex)
        {
            MyWingedEdgeMesh mesh = m_navMesh.Mesh;
            int i = GetEdgeIndex(index);
            int e = i;

            MyWingedEdgeMesh.Edge edge = mesh.GetEdge(e);
            int v = predVertex ? edge.GetFacePredVertex(m_triIndex) : edge.GetFaceSuccVertex(m_triIndex);

            do
            {
                if (IsTriangleDangerous(edge.VertexLeftFace(v)))
                {
                    return(true);
                }
                e    = edge.GetNextVertexEdge(v);
                edge = mesh.GetEdge(e);
            } while (e != i);

            return(false);
        }
        public void DebugDraw(ref Matrix drawMatrix, MyWingedEdgeMesh mesh)
        {
            var binEnum = m_outerEdgePoints.EnumerateBins();
            int i       = 0;

            while (binEnum.MoveNext())
            {
                int binIndex = Sandbox.Game.Gui.MyCestmirDebugInputComponent.BinIndex;
                if (binIndex == m_outerEdgePoints.InvalidIndex || i == binIndex)
                {
                    Vector3I position     = binEnum.Current.Key;
                    int      storageIndex = binEnum.Current.Value;

                    BoundingBoxD bb, bbTform;
                    m_outerEdgePoints.GetLocalBinBB(ref position, out bb);
                    bbTform.Min = Vector3D.Transform(bb.Min, drawMatrix);
                    bbTform.Max = Vector3D.Transform(bb.Max, drawMatrix);

                    while (storageIndex != m_outerEdgePoints.InvalidIndex)
                    {
                        Vector3 p    = m_outerEdgePoints.GetPoint(storageIndex);
                        var     edge = mesh.GetEdge(m_outerEdgePoints.GetData(storageIndex).EdgeIndex);
                        Vector3 v1   = mesh.GetVertexPosition(edge.Vertex1);
                        Vector3 v2   = mesh.GetVertexPosition(edge.Vertex2);
                        Vector3 vc   = (v1 + v2) * 0.5f;

                        Vector3D vcTformed = Vector3D.Transform((Vector3D)vc, drawMatrix);
                        Vector3D pTformed  = Vector3D.Transform((Vector3D)p, drawMatrix);

                        VRageRender.MyRenderProxy.DebugDrawArrow3D(vcTformed, pTformed, Color.Yellow, Color.Yellow, false);

                        storageIndex = m_outerEdgePoints.GetNextBinIndex(storageIndex);
                    }

                    VRageRender.MyRenderProxy.DebugDrawAABB(bbTform, Color.PowderBlue, 1.0f, 1.0f, false);
                }

                i++;
            }
        }
        public void DebugDraw(ref Matrix drawMatrix, MyWingedEdgeMesh mesh)
        {
            var binEnum = m_outerEdgePoints.EnumerateBins();
            int i = 0;
            while (binEnum.MoveNext())
            {
                int binIndex = Sandbox.Game.Gui.MyCestmirDebugInputComponent.BinIndex;
                if (binIndex == -1 || i == binIndex)
                {
                    Vector3I position = binEnum.Current.Key;
                    int storageIndex = binEnum.Current.Value;

                    if (storageIndex == -1) continue;

                    BoundingBoxD bb, bbTform;
                    m_outerEdgePoints.GetLocalBinBB(ref position, out bb);
                    bbTform.Min = Vector3D.Transform(bb.Min, drawMatrix);
                    bbTform.Max = Vector3D.Transform(bb.Max, drawMatrix);

                    m_outerEdgePoints.CollectStorage(storageIndex, ref m_tmpOuterEdgePointList);
                    foreach (var point in m_tmpOuterEdgePointList)
                    {
                        var edge = mesh.GetEdge(point.EdgeIndex);
                        Vector3 v1 = mesh.GetVertex(edge.Vertex1);
                        Vector3 v2 = mesh.GetVertex(edge.Vertex2);
                        Vector3 vc = (v1 + v2) * 0.5f;
                        Vector3 vertex;
                        if (point.FirstPoint)
                            vertex = v2 * 0.9f + vc * 0.1f;
                        else
                            vertex = v1 * 0.9f + vc * 0.1f;

                        Vector3D vertexTformed = vertex;
                        vertexTformed = Vector3D.Transform(vertexTformed, drawMatrix);

                        VRageRender.MyRenderProxy.DebugDrawSphere(vertexTformed, 0.025f, Color.Yellow, 1.0f, false);
                    }

                    VRageRender.MyRenderProxy.DebugDrawAABB(bbTform, Color.PowderBlue, 1.0f, 1.0f, false);
                }

                i++;
            }
        }