GetVertexCount() public method

public GetVertexCount ( ) : int
return int
        // Token: 0x0600229B RID: 8859 RVA: 0x00190E64 File Offset: 0x0018F064
        public static void GetContours(INavmesh navmesh, Action <List <Int3>, bool> results)
        {
            bool[] uses = new bool[3];
            Dictionary <int, int>  outline         = new Dictionary <int, int>();
            Dictionary <int, Int3> vertexPositions = new Dictionary <int, Int3>();
            HashSet <int>          hasInEdge       = new HashSet <int>();

            navmesh.GetNodes(delegate(GraphNode _node)
            {
                TriangleMeshNode triangleMeshNode = _node as TriangleMeshNode;
                uses[0] = (uses[1] = (uses[2] = false));
                if (triangleMeshNode != null)
                {
                    for (int i = 0; i < triangleMeshNode.connections.Length; i++)
                    {
                        TriangleMeshNode triangleMeshNode2 = triangleMeshNode.connections[i].node as TriangleMeshNode;
                        if (triangleMeshNode2 != null)
                        {
                            int num = triangleMeshNode.SharedEdge(triangleMeshNode2);
                            if (num != -1)
                            {
                                uses[num] = true;
                            }
                        }
                    }
                    for (int j = 0; j < 3; j++)
                    {
                        if (!uses[j])
                        {
                            int i2 = j;
                            int i3 = (j + 1) % triangleMeshNode.GetVertexCount();
                            outline[triangleMeshNode.GetVertexIndex(i2)] = triangleMeshNode.GetVertexIndex(i3);
                            hasInEdge.Add(triangleMeshNode.GetVertexIndex(i3));
                            vertexPositions[triangleMeshNode.GetVertexIndex(i2)] = triangleMeshNode.GetVertex(i2);
                            vertexPositions[triangleMeshNode.GetVertexIndex(i3)] = triangleMeshNode.GetVertex(i3);
                        }
                    }
                }
            });
            Polygon.TraceContours(outline, hasInEdge, delegate(List <int> chain, bool cycle)
            {
                List <Int3> list = ListPool <Int3> .Claim();
                for (int i = 0; i < chain.Count; i++)
                {
                    list.Add(vertexPositions[chain[i]]);
                }
                results(list, cycle);
            });
        }
        public bool GetPortal(GraphNode _other, System.Collections.Generic.List <Vector3> left, System.Collections.Generic.List <Vector3> right, bool backwards, out int aIndex, out int bIndex)
        {
            aIndex = -1;
            bIndex = -1;

            //If the nodes are in different graphs, this function has no idea on how to find a shared edge.
            if (_other.GraphIndex != GraphIndex)
            {
                return(false);
            }

            TriangleMeshNode other = _other as TriangleMeshNode;

            if (!backwards)
            {
                int first  = -1;
                int second = -1;

                int av = GetVertexCount();
                int bv = other.GetVertexCount();

                /** \todo Maybe optimize with pa=av-1 instead of modulus... */
                for (int a = 0; a < av; a++)
                {
                    int va = GetVertexIndex(a);
                    for (int b = 0; b < bv; b++)
                    {
                        if (va == other.GetVertexIndex((b + 1) % bv) && GetVertexIndex((a + 1) % av) == other.GetVertexIndex(b))
                        {
                            first  = a;
                            second = b;
                            a      = av;
                            break;
                        }
                    }
                }

                aIndex = first;
                bIndex = second;

                if (first != -1)
                {
                    if (left != null)
                    {
                        //All triangles should be clockwise so second is the rightmost vertex (seen from this node)
                        left.Add((Vector3)GetVertex(first));
                        right.Add((Vector3)GetVertex((first + 1) % av));
                    }
                }
                else
                {
                    for (int i = 0; i < connections.Length; i++)
                    {
                        if (connections[i].GraphIndex != GraphIndex)
                        {
                            NodeLink3Node mid = connections[i] as NodeLink3Node;
                            if (mid != null && mid.GetOther(this) == other)
                            {
                                // We have found a node which is connected through a NodeLink3Node

                                if (left != null)
                                {
                                    mid.GetPortal(other, left, right, false);
                                    return(true);
                                }
                            }
                        }
                    }
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 3
0
        public static bool Linecast(INavmesh graph, Vector3 tmp_origin, Vector3 tmp_end, GraphNode hint, out GraphHitInfo hit, List <GraphNode> trace)
        {
            Int3 @int = (Int3)tmp_end;
            Int3 int2 = (Int3)tmp_origin;

            hit = default(GraphHitInfo);
            if (float.IsNaN(tmp_origin.x + tmp_origin.y + tmp_origin.z))
            {
                throw new ArgumentException("origin is NaN");
            }
            if (float.IsNaN(tmp_end.x + tmp_end.y + tmp_end.z))
            {
                throw new ArgumentException("end is NaN");
            }
            TriangleMeshNode triangleMeshNode = hint as TriangleMeshNode;

            if (triangleMeshNode == null)
            {
                triangleMeshNode = ((graph as NavGraph).GetNearest(tmp_origin, NNConstraint.None).node as TriangleMeshNode);
                if (triangleMeshNode == null)
                {
                    Debug.LogError("Could not find a valid node to start from");
                    hit.point = tmp_origin;
                    return(true);
                }
            }
            if (int2 == @int)
            {
                hit.node = triangleMeshNode;
                return(false);
            }
            int2       = (Int3)triangleMeshNode.ClosestPointOnNode((Vector3)int2);
            hit.origin = (Vector3)int2;
            if (!triangleMeshNode.Walkable)
            {
                hit.point         = (Vector3)int2;
                hit.tangentOrigin = (Vector3)int2;
                return(true);
            }
            List <Vector3> list = ListPool <Vector3> .Claim();

            List <Vector3> list2 = ListPool <Vector3> .Claim();

            int num = 0;

            while (true)
            {
                num++;
                if (num > 2000)
                {
                    break;
                }
                TriangleMeshNode triangleMeshNode2 = null;
                if (trace != null)
                {
                    trace.Add(triangleMeshNode);
                }
                if (triangleMeshNode.ContainsPoint(@int))
                {
                    goto Block_9;
                }
                for (int i = 0; i < triangleMeshNode.connections.Length; i++)
                {
                    if (triangleMeshNode.connections[i].GraphIndex == triangleMeshNode.GraphIndex)
                    {
                        list.Clear();
                        list2.Clear();
                        if (triangleMeshNode.GetPortal(triangleMeshNode.connections[i], list, list2, false))
                        {
                            Vector3 vector  = list[0];
                            Vector3 vector2 = list2[0];
                            if (Polygon.LeftNotColinear(vector, vector2, hit.origin) || !Polygon.LeftNotColinear(vector, vector2, tmp_end))
                            {
                                float num2;
                                float num3;
                                if (Polygon.IntersectionFactor(vector, vector2, hit.origin, tmp_end, out num2, out num3))
                                {
                                    if (num3 >= 0f)
                                    {
                                        if (num2 >= 0f && num2 <= 1f)
                                        {
                                            triangleMeshNode2 = (triangleMeshNode.connections[i] as TriangleMeshNode);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (triangleMeshNode2 == null)
                {
                    goto Block_18;
                }
                triangleMeshNode = triangleMeshNode2;
            }
            Debug.LogError("Linecast was stuck in infinite loop. Breaking.");
            ListPool <Vector3> .Release(list);

            ListPool <Vector3> .Release(list2);

            return(true);

Block_9:
            ListPool <Vector3> .Release(list);

            ListPool <Vector3> .Release(list2);

            return(false);

Block_18:
            int vertexCount = triangleMeshNode.GetVertexCount();

            for (int j = 0; j < vertexCount; j++)
            {
                Vector3 vector3 = (Vector3)triangleMeshNode.GetVertex(j);
                Vector3 vector4 = (Vector3)triangleMeshNode.GetVertex((j + 1) % vertexCount);
                if (Polygon.LeftNotColinear(vector3, vector4, hit.origin) || !Polygon.LeftNotColinear(vector3, vector4, tmp_end))
                {
                    float num4;
                    float num5;
                    if (Polygon.IntersectionFactor(vector3, vector4, hit.origin, tmp_end, out num4, out num5))
                    {
                        if (num5 >= 0f)
                        {
                            if (num4 >= 0f && num4 <= 1f)
                            {
                                Vector3 point = vector3 + (vector4 - vector3) * num4;
                                hit.point         = point;
                                hit.node          = triangleMeshNode;
                                hit.tangent       = vector4 - vector3;
                                hit.tangentOrigin = vector3;
                                ListPool <Vector3> .Release(list);

                                ListPool <Vector3> .Release(list2);

                                return(true);
                            }
                        }
                    }
                }
            }
            Debug.LogWarning("Linecast failing because point not inside node, and line does not hit any edges of it");
            ListPool <Vector3> .Release(list);

            ListPool <Vector3> .Release(list2);

            return(false);
        }
Exemplo n.º 4
0
        public bool GetPortal(GraphNode _other, System.Collections.Generic.List <Vector3> left, System.Collections.Generic.List <Vector3> right, bool backwards, out int aIndex, out int bIndex)
        {
            aIndex = -1;
            bIndex = -1;

            //If the nodes are in different graphs, this function has no idea on how to find a shared edge.
            if (_other.GraphIndex != GraphIndex)
            {
                return(false);
            }

            TriangleMeshNode other = _other as TriangleMeshNode;

            //Get tile indices
            int tileIndex  = (GetVertexIndex(0) >> RecastGraph.TileIndexOffset) & RecastGraph.TileIndexMask;
            int tileIndex2 = (other.GetVertexIndex(0) >> RecastGraph.TileIndexOffset) & RecastGraph.TileIndexMask;

            //When the nodes are in different tiles, the edges might not be completely identical
            //so another technique is needed
            //Only do this on recast graphs
            if (tileIndex != tileIndex2 && (GetNavmeshHolder(GraphIndex) is RecastGraph))
            {
                for (int i = 0; i < connections.Length; i++)
                {
                    if (connections[i].GraphIndex != GraphIndex)
                    {
#if !ASTAR_NO_POINT_GRAPH
                        NodeLink3Node mid = connections[i] as NodeLink3Node;
                        if (mid != null && mid.GetOther(this) == other)
                        {
                            // We have found a node which is connected through a NodeLink3Node

                            if (left != null)
                            {
                                mid.GetPortal(other, left, right, false);
                                return(true);
                            }
                        }
#endif
                    }
                }

                //Get the tile coordinates, from them we can figure out which edge is going to be shared
                int            x1, x2, z1, z2;
                int            coord;
                INavmeshHolder nm = GetNavmeshHolder(GraphIndex);
                nm.GetTileCoordinates(tileIndex, out x1, out z1);
                nm.GetTileCoordinates(tileIndex2, out x2, out z2);

                if (System.Math.Abs(x1 - x2) == 1)
                {
                    coord = 0;
                }
                else if (System.Math.Abs(z1 - z2) == 1)
                {
                    coord = 2;
                }
                else
                {
                    throw new System.Exception("Tiles not adjacent (" + x1 + ", " + z1 + ") (" + x2 + ", " + z2 + ")");
                }

                int av = GetVertexCount();
                int bv = other.GetVertexCount();

                //Try the X and Z coordinate. For one of them the coordinates should be equal for one of the two nodes' edges
                //The midpoint between the tiles is the only place where they will be equal

                int first = -1, second = -1;

                //Find the shared edge
                for (int a = 0; a < av; a++)
                {
                    int va = GetVertex(a)[coord];
                    for (int b = 0; b < bv; b++)
                    {
                        if (va == other.GetVertex((b + 1) % bv)[coord] && GetVertex((a + 1) % av)[coord] == other.GetVertex(b)[coord])
                        {
                            first  = a;
                            second = b;
                            a      = av;
                            break;
                        }
                    }
                }

                aIndex = first;
                bIndex = second;

                if (first != -1)
                {
                    Int3 a = GetVertex(first);
                    Int3 b = GetVertex((first + 1) % av);

                    //The coordinate which is not the same for the vertices
                    int ocoord = coord == 2 ? 0 : 2;

                    //When the nodes are in different tiles, they might not share exactly the same edge
                    //so we clamp the portal to the segment of the edges which they both have.
                    int mincoord = System.Math.Min(a[ocoord], b[ocoord]);
                    int maxcoord = System.Math.Max(a[ocoord], b[ocoord]);

                    mincoord = System.Math.Max(mincoord, System.Math.Min(other.GetVertex(second)[ocoord], other.GetVertex((second + 1) % bv)[ocoord]));
                    maxcoord = System.Math.Min(maxcoord, System.Math.Max(other.GetVertex(second)[ocoord], other.GetVertex((second + 1) % bv)[ocoord]));

                    if (a[ocoord] < b[ocoord])
                    {
                        a[ocoord] = mincoord;
                        b[ocoord] = maxcoord;
                    }
                    else
                    {
                        a[ocoord] = maxcoord;
                        b[ocoord] = mincoord;
                    }

                    if (left != null)
                    {
                        //All triangles should be clockwise so second is the rightmost vertex (seen from this node)
                        left.Add((Vector3)a);
                        right.Add((Vector3)b);
                    }
                    return(true);
                }
            }
            else
            if (!backwards)
            {
                int first  = -1;
                int second = -1;

                int av = GetVertexCount();
                int bv = other.GetVertexCount();

                /** \todo Maybe optimize with pa=av-1 instead of modulus... */
                for (int a = 0; a < av; a++)
                {
                    int va = GetVertexIndex(a);
                    for (int b = 0; b < bv; b++)
                    {
                        if (va == other.GetVertexIndex((b + 1) % bv) && GetVertexIndex((a + 1) % av) == other.GetVertexIndex(b))
                        {
                            first  = a;
                            second = b;
                            a      = av;
                            break;
                        }
                    }
                }

                aIndex = first;
                bIndex = second;

                if (first != -1)
                {
                    if (left != null)
                    {
                        //All triangles should be clockwise so second is the rightmost vertex (seen from this node)
                        left.Add((Vector3)GetVertex(first));
                        right.Add((Vector3)GetVertex((first + 1) % av));
                    }
                }
                else
                {
                    for (int i = 0; i < connections.Length; i++)
                    {
                        if (connections[i].GraphIndex != GraphIndex)
                        {
#if !ASTAR_NO_POINT_GRAPH
                            NodeLink3Node mid = connections[i] as NodeLink3Node;
                            if (mid != null && mid.GetOther(this) == other)
                            {
                                // We have found a node which is connected through a NodeLink3Node

                                if (left != null)
                                {
                                    mid.GetPortal(other, left, right, false);
                                    return(true);
                                }
                            }
#endif
                        }
                    }
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 5
0
        public bool GetPortal(GraphNode _other, List <VInt3> left, List <VInt3> right, bool backwards, out int aIndex, out int bIndex)
        {
            aIndex = -1;
            bIndex = -1;
            if (_other.GraphIndex != base.GraphIndex)
            {
                return(false);
            }
            TriangleMeshNode node = _other as TriangleMeshNode;
            int tileIndex         = (this.GetVertexIndex(0) >> 12) & 0x7ffff;
            int num2 = (node.GetVertexIndex(0) >> 12) & 0x7ffff;

            if ((tileIndex != num2) && (GetNavmeshHolder(base.DataGroupIndex, base.GraphIndex) is RecastGraph))
            {
                int            num3;
                int            num4;
                int            num5;
                int            num6;
                int            num7;
                INavmeshHolder navmeshHolder = GetNavmeshHolder(base.DataGroupIndex, base.GraphIndex);
                navmeshHolder.GetTileCoordinates(tileIndex, out num3, out num5);
                navmeshHolder.GetTileCoordinates(num2, out num4, out num6);
                if (Math.Abs((int)(num3 - num4)) == 1)
                {
                    num7 = 0;
                }
                else if (Math.Abs((int)(num5 - num6)) == 1)
                {
                    num7 = 2;
                }
                else
                {
                    object[] objArray1 = new object[] { "Tiles not adjacent (", num3, ", ", num5, ") (", num4, ", ", num6, ")" };
                    throw new Exception(string.Concat(objArray1));
                }
                int vertexCount = this.GetVertexCount();
                int num9        = node.GetVertexCount();
                int i           = -1;
                int num11       = -1;
                for (int j = 0; j < vertexCount; j++)
                {
                    int num13 = this.GetVertex(j)[num7];
                    for (int k = 0; k < num9; k++)
                    {
                        if ((num13 == node.GetVertex((k + 1) % num9)[num7]) && (this.GetVertex((j + 1) % vertexCount)[num7] == node.GetVertex(k)[num7]))
                        {
                            i     = j;
                            num11 = k;
                            j     = vertexCount;
                            break;
                        }
                    }
                }
                aIndex = i;
                bIndex = num11;
                if (i != -1)
                {
                    VInt3 vertex = this.GetVertex(i);
                    VInt3 item   = this.GetVertex((i + 1) % vertexCount);
                    int   num17  = (num7 != 2) ? 2 : 0;
                    int   num18  = Math.Min(vertex[num17], item[num17]);
                    int   num19  = Math.Max(vertex[num17], item[num17]);
                    num18 = Math.Max(num18, Math.Min(node.GetVertex(num11)[num17], node.GetVertex((num11 + 1) % num9)[num17]));
                    num19 = Math.Min(num19, Math.Max(node.GetVertex(num11)[num17], node.GetVertex((num11 + 1) % num9)[num17]));
                    if (vertex[num17] < item[num17])
                    {
                        vertex[num17] = num18;
                        item[num17]   = num19;
                    }
                    else
                    {
                        vertex[num17] = num19;
                        item[num17]   = num18;
                    }
                    if (left != null)
                    {
                        left.Add(vertex);
                        right.Add(item);
                    }
                    return(true);
                }
            }
            else if (!backwards)
            {
                int num20 = -1;
                int num21 = -1;
                int num22 = this.GetVertexCount();
                int num23 = node.GetVertexCount();
                for (int m = 0; m < num22; m++)
                {
                    int vertexIndex = this.GetVertexIndex(m);
                    for (int n = 0; n < num23; n++)
                    {
                        if ((vertexIndex == node.GetVertexIndex((n + 1) % num23)) && (this.GetVertexIndex((m + 1) % num22) == node.GetVertexIndex(n)))
                        {
                            num20 = m;
                            num21 = n;
                            m     = num22;
                            break;
                        }
                    }
                }
                aIndex = num20;
                bIndex = num21;
                if (num20 == -1)
                {
                    return(false);
                }
                if (left != null)
                {
                    left.Add(this.GetVertex(num20));
                    right.Add(this.GetVertex((num20 + 1) % num22));
                }
            }
            return(true);
        }
Exemplo n.º 6
0
 public static bool Linecast(INavmesh graph, VInt3 tmp_origin, VInt3 tmp_end, GraphNode hint, out GraphHitInfo hit, List<GraphNode> trace)
 {
     VInt3 vInt = tmp_end;
     VInt3 vInt2 = tmp_origin;
     hit = default(GraphHitInfo);
     if (float.IsNaN((float)(tmp_origin.x + tmp_origin.y + tmp_origin.z)))
     {
         throw new ArgumentException("origin is NaN");
     }
     if (float.IsNaN((float)(tmp_end.x + tmp_end.y + tmp_end.z)))
     {
         throw new ArgumentException("end is NaN");
     }
     TriangleMeshNode triangleMeshNode = hint as TriangleMeshNode;
     if (triangleMeshNode == null)
     {
         triangleMeshNode = ((graph as NavGraph).GetNearest(tmp_origin, NNConstraint.None).node as TriangleMeshNode);
         if (triangleMeshNode == null)
         {
             Debug.LogError("Could not find a valid node to start from");
             hit.point = tmp_origin;
             return true;
         }
     }
     if (vInt2 == vInt)
     {
         hit.node = triangleMeshNode;
         return false;
     }
     vInt2 = (VInt3)triangleMeshNode.ClosestPointOnNode((Vector3)vInt2);
     hit.origin = vInt2;
     if (!triangleMeshNode.Walkable)
     {
         hit.point = vInt2;
         hit.tangentOrigin = vInt2;
         return true;
     }
     List<VInt3> list = ListPool<VInt3>.Claim();
     List<VInt3> list2 = ListPool<VInt3>.Claim();
     int num = 0;
     while (true)
     {
         num++;
         if (num > 2000)
         {
             break;
         }
         TriangleMeshNode triangleMeshNode2 = null;
         if (trace != null)
         {
             trace.Add(triangleMeshNode);
         }
         if (triangleMeshNode.ContainsPoint(vInt))
         {
             goto Block_9;
         }
         for (int i = 0; i < triangleMeshNode.connections.Length; i++)
         {
             if (triangleMeshNode.connections[i].GraphIndex == triangleMeshNode.GraphIndex)
             {
                 list.Clear();
                 list2.Clear();
                 if (triangleMeshNode.GetPortal(triangleMeshNode.connections[i], list, list2, false))
                 {
                     VInt3 vInt3 = list.get_Item(0);
                     VInt3 vInt4 = list2.get_Item(0);
                     if (Polygon.LeftNotColinear(vInt3, vInt4, hit.origin) || !Polygon.LeftNotColinear(vInt3, vInt4, tmp_end))
                     {
                         float num2;
                         float num3;
                         if (Polygon.IntersectionFactor(vInt3, vInt4, hit.origin, tmp_end, out num2, out num3))
                         {
                             if (num3 >= 0f)
                             {
                                 if (num2 >= 0f && num2 <= 1f)
                                 {
                                     triangleMeshNode2 = (triangleMeshNode.connections[i] as TriangleMeshNode);
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (triangleMeshNode2 == null)
         {
             goto Block_18;
         }
         triangleMeshNode = triangleMeshNode2;
     }
     Debug.LogError("Linecast was stuck in infinite loop. Breaking.");
     ListPool<VInt3>.Release(list);
     ListPool<VInt3>.Release(list2);
     return true;
     Block_9:
     ListPool<VInt3>.Release(list);
     ListPool<VInt3>.Release(list2);
     return false;
     Block_18:
     int vertexCount = triangleMeshNode.GetVertexCount();
     for (int j = 0; j < vertexCount; j++)
     {
         VInt3 vertex = triangleMeshNode.GetVertex(j);
         VInt3 vertex2 = triangleMeshNode.GetVertex((j + 1) % vertexCount);
         if (Polygon.LeftNotColinear(vertex, vertex2, hit.origin) || !Polygon.LeftNotColinear(vertex, vertex2, tmp_end))
         {
             VFactor vFactor;
             VFactor vFactor2;
             if (Polygon.IntersectionFactor(vertex, vertex2, hit.origin, tmp_end, out vFactor, out vFactor2))
             {
                 if (!vFactor2.IsNegative)
                 {
                     if (!vFactor.IsNegative && vFactor.nom / vFactor.den <= 1L)
                     {
                         VInt3 vInt5 = (vertex2 - vertex) * (float)vFactor.nom;
                         vInt5 = IntMath.Divide(vInt5, vFactor.den);
                         vInt5 += vertex;
                         hit.point = vInt5;
                         hit.node = triangleMeshNode;
                         hit.tangent = vertex2 - vertex;
                         hit.tangentOrigin = vertex;
                         ListPool<VInt3>.Release(list);
                         ListPool<VInt3>.Release(list2);
                         return true;
                     }
                 }
             }
         }
     }
     Debug.LogWarning("Linecast failing because point not inside node, and line does not hit any edges of it");
     ListPool<VInt3>.Release(list);
     ListPool<VInt3>.Release(list2);
     return false;
 }
Exemplo n.º 7
0
        public bool GetPortal(GraphNode _other, List <Vector3> left, List <Vector3> right, bool backwards, out int aIndex, out int bIndex)
        {
            aIndex = -1;
            bIndex = -1;
            if (_other.GraphIndex != base.GraphIndex)
            {
                return(false);
            }
            TriangleMeshNode triangleMeshNode = _other as TriangleMeshNode;
            int num  = this.GetVertexIndex(0) >> 12 & 524287;
            int num2 = triangleMeshNode.GetVertexIndex(0) >> 12 & 524287;

            if (num != num2 && TriangleMeshNode.GetNavmeshHolder(base.GraphIndex) is RecastGraph)
            {
                for (int i = 0; i < this.connections.Length; i++)
                {
                    if (this.connections[i].GraphIndex != base.GraphIndex)
                    {
                        NodeLink3Node nodeLink3Node = this.connections[i] as NodeLink3Node;
                        if (nodeLink3Node != null && nodeLink3Node.GetOther(this) == triangleMeshNode && left != null)
                        {
                            nodeLink3Node.GetPortal(triangleMeshNode, left, right, false);
                            return(true);
                        }
                    }
                }
                INavmeshHolder navmeshHolder = TriangleMeshNode.GetNavmeshHolder(base.GraphIndex);
                int            num3;
                int            num4;
                navmeshHolder.GetTileCoordinates(num, out num3, out num4);
                int num5;
                int num6;
                navmeshHolder.GetTileCoordinates(num2, out num5, out num6);
                int num7;
                if (Math.Abs(num3 - num5) == 1)
                {
                    num7 = 0;
                }
                else
                {
                    if (Math.Abs(num4 - num6) != 1)
                    {
                        throw new Exception(string.Concat(new object[]
                        {
                            "Tiles not adjacent (",
                            num3,
                            ", ",
                            num4,
                            ") (",
                            num5,
                            ", ",
                            num6,
                            ")"
                        }));
                    }
                    num7 = 2;
                }
                int vertexCount  = this.GetVertexCount();
                int vertexCount2 = triangleMeshNode.GetVertexCount();
                int num8         = -1;
                int num9         = -1;
                for (int j = 0; j < vertexCount; j++)
                {
                    int num10 = this.GetVertex(j)[num7];
                    for (int k = 0; k < vertexCount2; k++)
                    {
                        if (num10 == triangleMeshNode.GetVertex((k + 1) % vertexCount2)[num7] && this.GetVertex((j + 1) % vertexCount)[num7] == triangleMeshNode.GetVertex(k)[num7])
                        {
                            num8 = j;
                            num9 = k;
                            j    = vertexCount;
                            break;
                        }
                    }
                }
                aIndex = num8;
                bIndex = num9;
                if (num8 != -1)
                {
                    Int3 vertex  = this.GetVertex(num8);
                    Int3 vertex2 = this.GetVertex((num8 + 1) % vertexCount);
                    int  i2      = (num7 != 2) ? 2 : 0;
                    int  num11   = Math.Min(vertex[i2], vertex2[i2]);
                    int  num12   = Math.Max(vertex[i2], vertex2[i2]);
                    num11 = Math.Max(num11, Math.Min(triangleMeshNode.GetVertex(num9)[i2], triangleMeshNode.GetVertex((num9 + 1) % vertexCount2)[i2]));
                    num12 = Math.Min(num12, Math.Max(triangleMeshNode.GetVertex(num9)[i2], triangleMeshNode.GetVertex((num9 + 1) % vertexCount2)[i2]));
                    if (vertex[i2] < vertex2[i2])
                    {
                        vertex[i2]  = num11;
                        vertex2[i2] = num12;
                    }
                    else
                    {
                        vertex[i2]  = num12;
                        vertex2[i2] = num11;
                    }
                    if (left != null)
                    {
                        left.Add((Vector3)vertex);
                        right.Add((Vector3)vertex2);
                    }
                    return(true);
                }
            }
            else if (!backwards)
            {
                int num13        = -1;
                int num14        = -1;
                int vertexCount3 = this.GetVertexCount();
                int vertexCount4 = triangleMeshNode.GetVertexCount();
                for (int l = 0; l < vertexCount3; l++)
                {
                    int vertexIndex = this.GetVertexIndex(l);
                    for (int m = 0; m < vertexCount4; m++)
                    {
                        if (vertexIndex == triangleMeshNode.GetVertexIndex((m + 1) % vertexCount4) && this.GetVertexIndex((l + 1) % vertexCount3) == triangleMeshNode.GetVertexIndex(m))
                        {
                            num13 = l;
                            num14 = m;
                            l     = vertexCount3;
                            break;
                        }
                    }
                }
                aIndex = num13;
                bIndex = num14;
                if (num13 == -1)
                {
                    for (int n = 0; n < this.connections.Length; n++)
                    {
                        if (this.connections[n].GraphIndex != base.GraphIndex)
                        {
                            NodeLink3Node nodeLink3Node2 = this.connections[n] as NodeLink3Node;
                            if (nodeLink3Node2 != null && nodeLink3Node2.GetOther(this) == triangleMeshNode && left != null)
                            {
                                nodeLink3Node2.GetPortal(triangleMeshNode, left, right, false);
                                return(true);
                            }
                        }
                    }
                    return(false);
                }
                if (left != null)
                {
                    left.Add((Vector3)this.GetVertex(num13));
                    right.Add((Vector3)this.GetVertex((num13 + 1) % vertexCount3));
                }
            }
            return(true);
        }
Exemplo n.º 8
0
        /** Generate connections between the two tiles.
         * The tiles must be adjacent.
         */
        protected void ConnectTiles(NavmeshTile tile1, NavmeshTile tile2)
        {
            if (tile1 == null)
            {
                return;                           //throw new System.ArgumentNullException ("tile1");
            }
            if (tile2 == null)
            {
                return;                           //throw new System.ArgumentNullException ("tile2");
            }
            if (tile1.nodes == null)
            {
                throw new System.ArgumentException("tile1 does not contain any nodes");
            }
            if (tile2.nodes == null)
            {
                throw new System.ArgumentException("tile2 does not contain any nodes");
            }

            int t1x = Mathf.Clamp(tile2.x, tile1.x, tile1.x + tile1.w - 1);
            int t2x = Mathf.Clamp(tile1.x, tile2.x, tile2.x + tile2.w - 1);
            int t1z = Mathf.Clamp(tile2.z, tile1.z, tile1.z + tile1.d - 1);
            int t2z = Mathf.Clamp(tile1.z, tile2.z, tile2.z + tile2.d - 1);

            int coord, altcoord;
            int t1coord, t2coord;

            float tcs;

            if (t1x == t2x)
            {
                coord    = 2;
                altcoord = 0;
                t1coord  = t1z;
                t2coord  = t2z;
                tcs      = tileSizeZ * cellSize;
            }
            else if (t1z == t2z)
            {
                coord    = 0;
                altcoord = 2;
                t1coord  = t1x;
                t2coord  = t2x;
                tcs      = tileSizeX * cellSize;
            }
            else
            {
                throw new System.ArgumentException("Tiles are not adjacent (neither x or z coordinates match)");
            }

            if (Math.Abs(t1coord - t2coord) != 1)
            {
                EB.Debug.Log("{0} {1} {2} {3}\n{5} {6} {7} {8}\n{9} {10} {11} {12}", tile1.x, tile1.z, tile1.w, tile1.d,
                             tile2.x, tile2.z, tile2.w, tile2.d, t1x, t1z, t2x, t2z);
                throw new System.ArgumentException("Tiles are not adjacent (tile coordinates must differ by exactly 1. Got '" + t1coord + "' and '" + t2coord + "')");
            }

            //Midpoint between the two tiles
            int midpoint = (int)Math.Round((Math.Max(t1coord, t2coord) * tcs + forcedBounds.min[coord]) * Int3.Precision);

#if ASTARDEBUG
            Vector3 v1 = new Vector3(-100, 0, -100);
            Vector3 v2 = new Vector3(100, 0, 100);
            v1[coord] = midpoint * Int3.PrecisionFactor;
            v2[coord] = midpoint * Int3.PrecisionFactor;

            Debug.DrawLine(v1, v2, Color.magenta);
#endif

#if BNICKSON_UPDATED
            // different triangle link height tolerance based on whether we're linking tiles generated for random levels or not
            float heightToleranceSquared = generateFromInputMesh ? GameUtils.Square(heightZoneLinkTolerance) : GameUtils.Square(walkableClimb);
#endif
            TriangleMeshNode[] nodes1 = tile1.nodes;
            TriangleMeshNode[] nodes2 = tile2.nodes;

            //Find adjacent nodes on the border between the tiles
            for (int i = 0; i < nodes1.Length; i++)
            {
                TriangleMeshNode node = nodes1[i];
                int av = node.GetVertexCount();

                for (int a = 0; a < av; a++)
                {
                    Int3 ap1 = node.GetVertex(a);
                    Int3 ap2 = node.GetVertex((a + 1) % av);
#if BNICKSON_UPDATED
                    if (ap1[coord] == midpoint && ap2[coord] == midpoint)                     // this could be given a little bit of tolerance
#else
                    if (Math.Abs(ap1[coord] - midpoint) < 2 && Math.Abs(ap2[coord] - midpoint) < 2)
#endif
                    {
#if ASTARDEBUG
                        Debug.DrawLine((Vector3)ap1, (Vector3)ap2, Color.red);
#endif

                        int minalt = Math.Min(ap1[altcoord], ap2[altcoord]);
                        int maxalt = Math.Max(ap1[altcoord], ap2[altcoord]);

                        //Degenerate edge
                        if (minalt == maxalt)
                        {
                            continue;
                        }

                        for (int j = 0; j < nodes2.Length; j++)
                        {
                            TriangleMeshNode other = nodes2[j];
                            int bv = other.GetVertexCount();
                            for (int b = 0; b < bv; b++)
                            {
                                Int3 bp1 = other.GetVertex(b);
                                Int3 bp2 = other.GetVertex((b + 1) % av);
#if BNICKSON_UPDATED
                                if (bp1[coord] == midpoint && bp2[coord] == midpoint)                                 // this could be given a little bit of tolerance
#else
                                if (Math.Abs(bp1[coord] - midpoint) < 2 && Math.Abs(bp2[coord] - midpoint) < 2)
#endif
                                {
                                    int minalt2 = Math.Min(bp1[altcoord], bp2[altcoord]);
                                    int maxalt2 = Math.Max(bp1[altcoord], bp2[altcoord]);

                                    //Degenerate edge
                                    if (minalt2 == maxalt2)
                                    {
                                        continue;
                                    }

                                    if (maxalt > minalt2 && minalt < maxalt2)
                                    {
                                        //Adjacent

                                        //Test shortest distance between the segments (first test if they are equal since that is much faster)
                                        if ((ap1 == bp1 && ap2 == bp2) || (ap1 == bp2 && ap2 == bp1) ||
#if BNICKSON_UPDATED
                                            VectorMath.SqrDistanceSegmentSegment((Vector3)ap1, (Vector3)ap2, (Vector3)bp1, (Vector3)bp2) < heightToleranceSquared)                                             // different height tolerances based on generating from input mesh or not
#else
                                            VectorMath.SqrDistanceSegmentSegment((Vector3)ap1, (Vector3)ap2, (Vector3)bp1, (Vector3)bp2) < walkableClimb * walkableClimb)
#endif
                                        {
                                            uint cost = (uint)(node.position - other.position).costMagnitude;

                                            node.AddConnection(other, cost);
                                            other.AddConnection(node, cost);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        // Token: 0x060025FE RID: 9726 RVA: 0x001A6C10 File Offset: 0x001A4E10
        public bool GetPortal(GraphNode toNode, List <Vector3> left, List <Vector3> right, bool backwards, out int aIndex, out int bIndex)
        {
            aIndex = -1;
            bIndex = -1;
            if (backwards || toNode.GraphIndex != base.GraphIndex)
            {
                return(false);
            }
            TriangleMeshNode triangleMeshNode = toNode as TriangleMeshNode;
            int num = this.SharedEdge(triangleMeshNode);

            if (num == 255)
            {
                return(false);
            }
            if (num == -1)
            {
                for (int i = 0; i < this.connections.Length; i++)
                {
                    if (this.connections[i].node.GraphIndex != base.GraphIndex)
                    {
                        NodeLink3Node nodeLink3Node = this.connections[i].node as NodeLink3Node;
                        if (nodeLink3Node != null && nodeLink3Node.GetOther(this) == triangleMeshNode)
                        {
                            nodeLink3Node.GetPortal(triangleMeshNode, left, right, false);
                            return(true);
                        }
                    }
                }
                return(false);
            }
            aIndex = num;
            bIndex = (num + 1) % this.GetVertexCount();
            Int3 vertex  = this.GetVertex(num);
            Int3 vertex2 = this.GetVertex((num + 1) % this.GetVertexCount());
            int  num2    = this.GetVertexIndex(0) >> 12 & 524287;
            int  num3    = triangleMeshNode.GetVertexIndex(0) >> 12 & 524287;

            if (num2 != num3)
            {
                INavmeshHolder navmeshHolder = TriangleMeshNode.GetNavmeshHolder(base.GraphIndex);
                int            num4;
                int            num5;
                navmeshHolder.GetTileCoordinates(num2, out num4, out num5);
                int num6;
                int num7;
                navmeshHolder.GetTileCoordinates(num3, out num6, out num7);
                int i2;
                if (Math.Abs(num4 - num6) == 1)
                {
                    i2 = 2;
                }
                else
                {
                    if (Math.Abs(num5 - num7) != 1)
                    {
                        return(false);
                    }
                    i2 = 0;
                }
                int num8 = triangleMeshNode.SharedEdge(this);
                if (num8 == 255)
                {
                    throw new Exception("Connection used edge in one direction, but not in the other direction. Has the wrong overload of AddConnection been used?");
                }
                if (num8 != -1)
                {
                    int  num9    = Math.Min(vertex[i2], vertex2[i2]);
                    int  num10   = Math.Max(vertex[i2], vertex2[i2]);
                    Int3 vertex3 = triangleMeshNode.GetVertex(num8);
                    Int3 vertex4 = triangleMeshNode.GetVertex((num8 + 1) % triangleMeshNode.GetVertexCount());
                    num9  = Math.Max(num9, Math.Min(vertex3[i2], vertex4[i2]));
                    num10 = Math.Min(num10, Math.Max(vertex3[i2], vertex4[i2]));
                    if (vertex[i2] < vertex2[i2])
                    {
                        vertex[i2]  = num9;
                        vertex2[i2] = num10;
                    }
                    else
                    {
                        vertex[i2]  = num10;
                        vertex2[i2] = num9;
                    }
                }
            }
            if (left != null)
            {
                left.Add((Vector3)vertex);
                right.Add((Vector3)vertex2);
            }
            return(true);
        }
Exemplo n.º 10
0
        public bool GetPortal(GraphNode _other, List <Vector3> left, List <Vector3> right, bool backwards, out int aIndex, out int bIndex)
        {
            aIndex = -1;
            bIndex = -1;
            if (_other.GraphIndex != base.GraphIndex)
            {
                return(false);
            }
            TriangleMeshNode other = _other as TriangleMeshNode;
            int tileIndex          = (this.GetVertexIndex(0) >> 12) & 0x7ffff;
            int num2 = (other.GetVertexIndex(0) >> 12) & 0x7ffff;

            if ((tileIndex != num2) && (GetNavmeshHolder(base.GraphIndex) is RecastGraph))
            {
                int num4;
                int num5;
                int num6;
                int num7;
                int num8;
                for (int i = 0; i < base.connections.Length; i++)
                {
                    if (base.connections[i].GraphIndex != base.GraphIndex)
                    {
                        NodeLink3Node node2 = base.connections[i] as NodeLink3Node;
                        if (((node2 != null) && (node2.GetOther(this) == other)) && (left != null))
                        {
                            node2.GetPortal(other, left, right, false);
                            return(true);
                        }
                    }
                }
                INavmeshHolder navmeshHolder = GetNavmeshHolder(base.GraphIndex);
                navmeshHolder.GetTileCoordinates(tileIndex, out num4, out num6);
                navmeshHolder.GetTileCoordinates(num2, out num5, out num7);
                if (Math.Abs((int)(num4 - num5)) == 1)
                {
                    num8 = 0;
                }
                else if (Math.Abs((int)(num6 - num7)) == 1)
                {
                    num8 = 2;
                }
                else
                {
                    object[] objArray1 = new object[] { "Tiles not adjacent (", num4, ", ", num6, ") (", num5, ", ", num7, ")" };
                    throw new Exception(string.Concat(objArray1));
                }
                int vertexCount = this.GetVertexCount();
                int num10       = other.GetVertexCount();
                int num11       = -1;
                int num12       = -1;
                for (int j = 0; j < vertexCount; j++)
                {
                    int num14 = this.GetVertex(j)[num8];
                    for (int k = 0; k < num10; k++)
                    {
                        if ((num14 == other.GetVertex((k + 1) % num10)[num8]) && (this.GetVertex((j + 1) % vertexCount)[num8] == other.GetVertex(k)[num8]))
                        {
                            num11 = j;
                            num12 = k;
                            j     = vertexCount;
                            break;
                        }
                    }
                }
                aIndex = num11;
                bIndex = num12;
                if (num11 != -1)
                {
                    Int3 vertex = this.GetVertex(num11);
                    Int3 num17  = this.GetVertex((num11 + 1) % vertexCount);
                    int  num18  = (num8 != 2) ? 2 : 0;
                    int  num19  = Math.Min(vertex[num18], num17[num18]);
                    int  num20  = Math.Max(vertex[num18], num17[num18]);
                    num19 = Math.Max(num19, Math.Min(other.GetVertex(num12)[num18], other.GetVertex((num12 + 1) % num10)[num18]));
                    num20 = Math.Min(num20, Math.Max(other.GetVertex(num12)[num18], other.GetVertex((num12 + 1) % num10)[num18]));
                    if (vertex[num18] < num17[num18])
                    {
                        vertex[num18] = num19;
                        num17[num18]  = num20;
                    }
                    else
                    {
                        vertex[num18] = num20;
                        num17[num18]  = num19;
                    }
                    if (left != null)
                    {
                        left.Add((Vector3)vertex);
                        right.Add((Vector3)num17);
                    }
                    return(true);
                }
            }
            else if (!backwards)
            {
                int num21 = -1;
                int num22 = -1;
                int num23 = this.GetVertexCount();
                int num24 = other.GetVertexCount();
                for (int m = 0; m < num23; m++)
                {
                    int vertexIndex = this.GetVertexIndex(m);
                    for (int n = 0; n < num24; n++)
                    {
                        if ((vertexIndex == other.GetVertexIndex((n + 1) % num24)) && (this.GetVertexIndex((m + 1) % num23) == other.GetVertexIndex(n)))
                        {
                            num21 = m;
                            num22 = n;
                            m     = num23;
                            break;
                        }
                    }
                }
                aIndex = num21;
                bIndex = num22;
                if (num21 == -1)
                {
                    for (int num28 = 0; num28 < base.connections.Length; num28++)
                    {
                        if (base.connections[num28].GraphIndex != base.GraphIndex)
                        {
                            NodeLink3Node node3 = base.connections[num28] as NodeLink3Node;
                            if (((node3 != null) && (node3.GetOther(this) == other)) && (left != null))
                            {
                                node3.GetPortal(other, left, right, false);
                                return(true);
                            }
                        }
                    }
                    return(false);
                }
                if (left != null)
                {
                    left.Add((Vector3)this.GetVertex(num21));
                    right.Add((Vector3)this.GetVertex((num21 + 1) % num23));
                }
            }
            return(true);
        }
Exemplo n.º 11
0
        public bool GetPortal(GraphNode _other, List <VInt3> left, List <VInt3> right, bool backwards, out int aIndex, out int bIndex)
        {
            aIndex = -1;
            bIndex = -1;
            if (_other.GraphIndex != base.GraphIndex)
            {
                return(false);
            }
            TriangleMeshNode triangleMeshNode = _other as TriangleMeshNode;
            int num  = this.GetVertexIndex(0) >> 12 & 524287;
            int num2 = triangleMeshNode.GetVertexIndex(0) >> 12 & 524287;

            if (num != num2 && TriangleMeshNode.GetNavmeshHolder(this.DataGroupIndex, base.GraphIndex) is RecastGraph)
            {
                INavmeshHolder navmeshHolder = TriangleMeshNode.GetNavmeshHolder(this.DataGroupIndex, base.GraphIndex);
                int            num3;
                int            num4;
                navmeshHolder.GetTileCoordinates(num, out num3, out num4);
                int num5;
                int num6;
                navmeshHolder.GetTileCoordinates(num2, out num5, out num6);
                int num7;
                if (Math.Abs(num3 - num5) == 1)
                {
                    num7 = 0;
                }
                else
                {
                    if (Math.Abs(num4 - num6) != 1)
                    {
                        throw new Exception(string.Concat(new object[]
                        {
                            "Tiles not adjacent (",
                            num3,
                            ", ",
                            num4,
                            ") (",
                            num5,
                            ", ",
                            num6,
                            ")"
                        }));
                    }
                    num7 = 2;
                }
                int vertexCount  = this.GetVertexCount();
                int vertexCount2 = triangleMeshNode.GetVertexCount();
                int num8         = -1;
                int num9         = -1;
                for (int i = 0; i < vertexCount; i++)
                {
                    int num10 = this.GetVertex(i)[num7];
                    for (int j = 0; j < vertexCount2; j++)
                    {
                        if (num10 == triangleMeshNode.GetVertex((j + 1) % vertexCount2)[num7] && this.GetVertex((i + 1) % vertexCount)[num7] == triangleMeshNode.GetVertex(j)[num7])
                        {
                            num8 = i;
                            num9 = j;
                            i    = vertexCount;
                            break;
                        }
                    }
                }
                aIndex = num8;
                bIndex = num9;
                if (num8 != -1)
                {
                    VInt3 vertex  = this.GetVertex(num8);
                    VInt3 vertex2 = this.GetVertex((num8 + 1) % vertexCount);
                    int   i2      = (num7 == 2) ? 0 : 2;
                    int   num11   = Math.Min(vertex[i2], vertex2[i2]);
                    int   num12   = Math.Max(vertex[i2], vertex2[i2]);
                    num11 = Math.Max(num11, Math.Min(triangleMeshNode.GetVertex(num9)[i2], triangleMeshNode.GetVertex((num9 + 1) % vertexCount2)[i2]));
                    num12 = Math.Min(num12, Math.Max(triangleMeshNode.GetVertex(num9)[i2], triangleMeshNode.GetVertex((num9 + 1) % vertexCount2)[i2]));
                    if (vertex[i2] < vertex2[i2])
                    {
                        vertex[i2]  = num11;
                        vertex2[i2] = num12;
                    }
                    else
                    {
                        vertex[i2]  = num12;
                        vertex2[i2] = num11;
                    }
                    if (left != null)
                    {
                        left.Add(vertex);
                        right.Add(vertex2);
                    }
                    return(true);
                }
            }
            else if (!backwards)
            {
                int num13        = -1;
                int num14        = -1;
                int vertexCount3 = this.GetVertexCount();
                int vertexCount4 = triangleMeshNode.GetVertexCount();
                for (int k = 0; k < vertexCount3; k++)
                {
                    int vertexIndex = this.GetVertexIndex(k);
                    for (int l = 0; l < vertexCount4; l++)
                    {
                        if (vertexIndex == triangleMeshNode.GetVertexIndex((l + 1) % vertexCount4) && this.GetVertexIndex((k + 1) % vertexCount3) == triangleMeshNode.GetVertexIndex(l))
                        {
                            num13 = k;
                            num14 = l;
                            k     = vertexCount3;
                            break;
                        }
                    }
                }
                aIndex = num13;
                bIndex = num14;
                if (num13 == -1)
                {
                    return(false);
                }
                if (left != null)
                {
                    left.Add(this.GetVertex(num13));
                    right.Add(this.GetVertex((num13 + 1) % vertexCount3));
                }
            }
            return(true);
        }