AddObstacle() public method

public AddObstacle ( ObstacleVertex v ) : ObstacleVertex
v ObstacleVertex
return ObstacleVertex
示例#1
0
    /** Enabled the obstacle.
     * Do not override this function
     */
    public void OnEnable()
    {
        if (addedObstacles != null)
        {
            if (sim == null)
            {
                throw new System.Exception("This should not happen! Make sure you are not overriding the OnDisable function");
            }

            for (int i = 0; i < addedObstacles.Count; i++)
            {
                sim.AddObstacle(addedObstacles[i]);
            }
        }
    }
示例#2
0
 private void AddGraphObstacles(Simulator sim, GridGraph grid)
 {
     RVONavmesh.FindAllContours(grid, delegate(Vector3[] vertices, bool cycle)
     {
         this.obstacles.Add(sim.AddObstacle(vertices, this.wallHeight, true));
     }, null);
 }
示例#3
0
        private void AddGraphObstacles(Simulator sim, INavmesh ng)
        {
            int[] uses = new int[3];
            Dictionary <int, int>  outline         = new Dictionary <int, int>();
            Dictionary <int, Int3> vertexPositions = new Dictionary <int, Int3>();
            HashSet <int>          hasInEdge       = new HashSet <int>();

            ng.GetNodes(delegate(GraphNode _node)
            {
                TriangleMeshNode triangleMeshNode = _node as TriangleMeshNode;
                uses[0] = (uses[1] = (uses[2] = 0));
                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] = 1;
                            }
                        }
                    }
                    for (int j = 0; j < 3; j++)
                    {
                        if (uses[j] == 0)
                        {
                            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);
                        }
                    }
                }
            });
            List <Vector3> vertices = ListPool <Vector3> .Claim();

            RVONavmesh.CompressContour(outline, hasInEdge, delegate(List <int> chain, bool cycle)
            {
                for (int i = 0; i < chain.Count; i++)
                {
                    vertices.Add((Vector3)vertexPositions[chain[i]]);
                }
                this.obstacles.Add(sim.AddObstacle(vertices.ToArray(), this.wallHeight, cycle));
                vertices.Clear();
            });
            ListPool <Vector3> .Release(vertices);
        }
示例#4
0
    // remove old abstacles and create new ones
    private void RemoveStaticObstaclesAndCreateNew(Pathfinding.RVO.Simulator sim)
    {
        RemoveStaticObstacles(sim);
        CreateObstacles(sim, ref _staticObstacles);

        if (null != _staticObstacles)
        {
            for (int i = 0; i < _staticObstacles.Count; i++)
            {
                sim.AddObstacle(_staticObstacles[i]);
            }
        }
    }
示例#5
0
        // Token: 0x060028F0 RID: 10480 RVA: 0x001BE988 File Offset: 0x001BCB88
        private void AddGraphObstacles(Simulator sim, GridGraph grid)
        {
            bool reverse = Vector3.Dot(grid.transform.TransformVector(Vector3.up), (sim.movementPlane == MovementPlane.XY) ? Vector3.back : Vector3.up) > 0f;

            GraphUtilities.GetContours(grid, delegate(Vector3[] vertices)
            {
                if (reverse)
                {
                    Array.Reverse(vertices);
                }
                this.obstacles.Add(sim.AddObstacle(vertices, this.wallHeight, true));
            }, this.wallHeight * 0.4f, null);
        }
示例#6
0
 // Token: 0x060028F1 RID: 10481 RVA: 0x001BEA04 File Offset: 0x001BCC04
 private void AddGraphObstacles(Simulator simulator, INavmesh navmesh)
 {
     GraphUtilities.GetContours(navmesh, delegate(List <Int3> vertices, bool cycle)
     {
         Vector3[] array = new Vector3[vertices.Count];
         for (int i = 0; i < array.Length; i++)
         {
             array[i] = (Vector3)vertices[i];
         }
         ListPool <Int3> .Release(vertices);
         this.obstacles.Add(simulator.AddObstacle(array, this.wallHeight, cycle));
     });
 }
示例#7
0
        /** Enabled the obstacle.
         * Do not override this function
         */
        public void OnEnable()
        {
            if (addedObstacles != null)
            {
                if (sim == null)
                {
                    throw new System.Exception("This should not happen! Make sure you are not overriding the OnDisable function");
                }

                for (int i = 0; i < addedObstacles.Count; i++)
                {
                    // Update height and layer
                    var vertex = addedObstacles[i];
                    var start  = vertex;
                    do
                    {
                        vertex.layer = layer;
                        vertex       = vertex.next;
                    } while (vertex != start);

                    sim.AddObstacle(addedObstacles[i]);
                }
            }
        }
示例#8
0
        public void AddGraphObstacles(Simulator sim, NavGraph graph)
        {
            if (this.obstacles.Count > 0 && this.lastSim != null && this.lastSim != sim)
            {
                Debug.LogError("Simulator has changed but some old obstacles are still added for the previous simulator. Deleting previous obstacles.");
                this.RemoveObstacles();
            }
            this.lastSim = sim;
            INavmesh navmesh = graph as INavmesh;

            if (navmesh == null)
            {
                return;
            }
            int[] uses = new int[20];
            navmesh.GetNodes(delegate(GraphNode _node)
            {
                TriangleMeshNode triangleMeshNode = _node as TriangleMeshNode;
                uses[0] = (uses[1] = (uses[2] = 0));
                if (triangleMeshNode != null)
                {
                    for (int i = 0; i < triangleMeshNode.connections.Length; i++)
                    {
                        TriangleMeshNode triangleMeshNode2 = triangleMeshNode.connections[i] as TriangleMeshNode;
                        if (triangleMeshNode2 != null)
                        {
                            int num = triangleMeshNode.SharedEdge(triangleMeshNode2);
                            if (num != -1)
                            {
                                uses[num] = 1;
                            }
                        }
                    }
                    for (int j = 0; j < 3; j++)
                    {
                        if (uses[j] == 0)
                        {
                            Vector3 a = (Vector3)triangleMeshNode.GetVertex(j);
                            Vector3 b = (Vector3)triangleMeshNode.GetVertex((j + 1) % triangleMeshNode.GetVertexCount());
                            float val = Math.Abs(a.y - b.y);
                            val       = Math.Max(val, 5f);
                            this.obstacles.Add(sim.AddObstacle(a, b, this.wallHeight));
                        }
                    }
                }
                return(true);
            });
        }
示例#9
0
        public void AddGraphObstacles(Simulator sim, NavGraph graph)
        {
            if (this.obstacles.get_Count() > 0 && this.lastSim != null && this.lastSim != sim)
            {
                this.RemoveObstacles();
            }
            this.lastSim = sim;
            INavmesh navmesh = graph as INavmesh;

            if (navmesh == null)
            {
                return;
            }
            int[] uses = new int[20];
            navmesh.GetNodes(delegate(GraphNode _node)
            {
                TriangleMeshNode triangleMeshNode = _node as TriangleMeshNode;
                uses[0] = (uses[1] = (uses[2] = 0));
                if (triangleMeshNode != null)
                {
                    for (int i = 0; i < triangleMeshNode.connections.Length; i++)
                    {
                        TriangleMeshNode triangleMeshNode2 = triangleMeshNode.connections[i] as TriangleMeshNode;
                        if (triangleMeshNode2 != null)
                        {
                            int num = triangleMeshNode.SharedEdge(triangleMeshNode2);
                            if (num != -1)
                            {
                                uses[num] = 1;
                            }
                        }
                    }
                    for (int j = 0; j < 3; j++)
                    {
                        if (uses[j] == 0)
                        {
                            VInt3 vertex  = triangleMeshNode.GetVertex(j);
                            VInt3 vertex2 = triangleMeshNode.GetVertex((j + 1) % triangleMeshNode.GetVertexCount());
                            this.obstacles.Add(sim.AddObstacle(vertex, vertex2, this.wallHeight));
                        }
                    }
                }
                return(true);
            });
        }
示例#10
0
    /** Adds obstacles for a graph */
    public void AddGraphObstacles(Pathfinding.RVO.Simulator sim, NavGraph graph)
    {
        if (obstacles.Count > 0 && lastSim != null && lastSim != sim)
        {
            Debug.LogError("Simulator has changed but some old obstacles are still added for the previous simulator. Deleting previous obstacles.");
            RemoveObstacles();
        }

        //Remember which simulator these obstacles were added to
        lastSim = sim;

        INavmesh ng = graph as INavmesh;

        if (ng == null)
        {
            return;
        }

        Node[] nodes = graph.nodes;

        Int3[] vertices = ng.vertices;

        int[] uses = new int[3];

        for (int i = 0; i < nodes.Length; i++)
        {
            MeshNode node = nodes[i] as MeshNode;

            uses[0] = uses[1] = uses[2] = 0;

            if (node != null)
            {
                for (int j = 0; j < node.connections.Length; j++)
                {
                    MeshNode other = node.connections[j] as MeshNode;
                    if (other == null)
                    {
                        continue;
                    }

                    int first  = -1;
                    int second = -1;

                    for (int x = 0; x < 3; x++)
                    {
                        for (int y = 0; y < 3; y++)
                        {
                            if (node[x] == other[y] && first < 0)
                            {
                                first = x;
                                break;
                            }
                            else if (node[x] == other[y])
                            {
                                second = x;
                                break;
                            }
                        }
                        if (second >= 0)
                        {
                            break;
                        }
                    }

                    //Only shared one vertex
                    if (second == -1)
                    {
                        continue;
                    }

                    if ((first + 1) % 3 == second)
                    {
                        uses[first]++;
                    }
                    else                         //if ((second+1) % 3 == first) {
                    {
                        uses[second]++;
                    }
                }
            }

            for (int j = 0; j < 3; j++)
            {
                if (uses[j] == 0)
                {
                    Vector3 v1 = (Vector3)vertices[node[j]];
                    Vector3 v2 = (Vector3)vertices[node[(j + 1) % 3]];

                    //I think node vertices always should be clockwise, but it's good to be certain
                    if (!Polygon.IsClockwise(v1, v2, (Vector3)vertices[node[(j + 2) % 3]]))
                    {
                        Vector3 tmp = v2;
                        v2 = v1;
                        v1 = tmp;
                    }

#if ASTARDEBUG
                    Debug.DrawLine(v1, v2, Color.red);
                    Debug.DrawRay(v1, Vector3.up * wallHeight, Color.red);
#endif

                    float height = System.Math.Abs(v1.y - v2.y);
                    height = System.Math.Max(height, 5);

                    obstacles.Add(sim.AddObstacle(v1, v2, wallHeight));
                }
            }
        }
    }
示例#11
0
        /** Adds obstacles for a graph */
        public void AddGraphObstacles(Pathfinding.RVO.Simulator sim, NavGraph graph)
        {
            if (obstacles.Count > 0 && lastSim != null && lastSim != sim)
            {
                Debug.LogError("Simulator has changed but some old obstacles are still added for the previous simulator. Deleting previous obstacles.");
                RemoveObstacles();
            }

            //Remember which simulator these obstacles were added to
            lastSim = sim;

            INavmesh ng = graph as INavmesh;

            if (ng == null)
            {
                return;
            }

            //Assume less than 20 vertices per node (actually assumes 3, but I will change that some day)
            int[] uses = new int[20];

            ng.GetNodes(delegate(GraphNode _node) {
                TriangleMeshNode node = _node as TriangleMeshNode;

                uses[0] = uses[1] = uses[2] = 0;

                if (node != null)
                {
                    //Find out which edges are shared with other nodes
                    for (int j = 0; j < node.connections.Length; j++)
                    {
                        TriangleMeshNode other = node.connections[j] as TriangleMeshNode;

                        // Not necessarily a TriangleMeshNode
                        if (other != null)
                        {
                            int a = node.SharedEdge(other);
                            if (a != -1)
                            {
                                uses[a] = 1;
                            }
                        }
                    }

                    //Loop through all edges on the node
                    for (int j = 0; j < 3; j++)
                    {
                        //The edge is not shared with any other node
                        //I.e it is an exterior edge on the mesh
                        if (uses[j] == 0)
                        {
                            //The two vertices of the edge
                            Vector3 v1 = (Vector3)node.GetVertex(j);
                            Vector3 v2 = (Vector3)node.GetVertex((j + 1) % node.GetVertexCount());

                            //I think node vertices always should be clockwise, but it's good to be certain

                            /*if (!Polygon.IsClockwise (v1,v2,(Vector3)node.GetVertex((j+2) % node.GetVertexCount()))) {
                             *      Vector3 tmp = v2;
                             *      v2 = v1;
                             *      v1 = tmp;
                             * }*/

                #if ASTARDEBUG
                            Debug.DrawLine(v1, v2, Color.red);
                            Debug.DrawRay(v1, Vector3.up * wallHeight, Color.red);
                #endif

                            //Find out the height of the wall/obstacle we are about to add
                            float height = System.Math.Abs(v1.y - v2.y);
                            height       = System.Math.Max(height, 5);

                            //Add the edge as a line obstacle
                            obstacles.Add(sim.AddObstacle(v1, v2, wallHeight));
                        }
                    }
                }

                return(true);
            });
        }
示例#12
0
        public void AddGraphObstacles(Simulator sim, INavmesh ng)
        {
            if (this.obstacles.Count > 0 && this.lastSim != null && this.lastSim != sim)
            {
                Debug.LogError("Simulator has changed but some old obstacles are still added for the previous simulator. Deleting previous obstacles.");
                this.RemoveObstacles();
            }
            this.lastSim = sim;
            int[] uses = new int[20];
            Dictionary <int, int>  outline         = new Dictionary <int, int>();
            Dictionary <int, Int3> vertexPositions = new Dictionary <int, Int3>();
            HashSet <int>          hasInEdge       = new HashSet <int>();

            ng.GetNodes(delegate(GraphNode _node)
            {
                TriangleMeshNode triangleMeshNode = _node as TriangleMeshNode;
                uses[0] = (uses[1] = (uses[2] = 0));
                if (triangleMeshNode != null)
                {
                    for (int j = 0; j < triangleMeshNode.connections.Length; j++)
                    {
                        TriangleMeshNode triangleMeshNode2 = triangleMeshNode.connections[j] as TriangleMeshNode;
                        if (triangleMeshNode2 != null)
                        {
                            int num3 = triangleMeshNode.SharedEdge(triangleMeshNode2);
                            if (num3 != -1)
                            {
                                uses[num3] = 1;
                            }
                        }
                    }
                    for (int k = 0; k < 3; k++)
                    {
                        if (uses[k] == 0)
                        {
                            int i2 = k;
                            int i3 = (k + 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);
                        }
                    }
                }
                return(true);
            });
            for (int i = 0; i < 2; i++)
            {
                bool flag = i == 1;
                foreach (int num in new List <int>(outline.Keys))
                {
                    if (flag || !hasInEdge.Contains(num))
                    {
                        int            key  = num;
                        List <Vector3> list = new List <Vector3>();
                        list.Add((Vector3)vertexPositions[key]);
                        while (outline.ContainsKey(key))
                        {
                            int num2 = outline[key];
                            outline.Remove(key);
                            Vector3 item = (Vector3)vertexPositions[num2];
                            list.Add(item);
                            if (num2 == num)
                            {
                                break;
                            }
                            key = num2;
                        }
                        if (list.Count > 1)
                        {
                            sim.AddObstacle(list.ToArray(), this.wallHeight, flag);
                        }
                    }
                }
            }
        }