Example #1
0
        public SpatialNode Rebuild(RebuildRequest[] obstacleRequests)
        {
            SpatialNode           rootCopy     = root;
            HashSet <SpatialNode> currentNodes = new HashSet <SpatialNode>();
            List <Vector3>        allVertices  = new List <Vector3>();

            foreach (var o in obstacleRequests)
            {
                List <Vector3> worldSpaceVertices = new List <Vector3>(o.vertices);
                for (int i = 0; i < o.vertices.Count; i++)
                {
                    currentNodes.Add((SpatialNode)rootCopy.NodeAt(o.position + o.rotation * o.vertices[i]));
                    worldSpaceVertices[i] = o.position + o.rotation * o.vertices[i];
                }
                allVertices.AddRange(worldSpaceVertices);
            }
            HashSet <SpatialNode> newNodes = new HashSet <SpatialNode>(currentNodes);

            newNodes.ExceptWith(nodeBuffer);
            HashSet <SpatialNode> old = new HashSet <SpatialNode>(nodeBuffer);

            old.ExceptWith(currentNodes);

            newNodes.UnionWith(old);
            HashSet <SpatialNode> parents = new HashSet <SpatialNode>();

            foreach (var n in newNodes)
            {
                parents.Add(LargestNonStaticParent(n));
            }

            foreach (var n in parents)
            {
                n.Rebuild(allVertices);
            }

            currentNodes = new HashSet <SpatialNode>();
            foreach (var o in obstacleRequests)
            {
                for (int i = 0; i < o.vertices.Count; i++)
                {
                    currentNodes.Add((SpatialNode)rootCopy.NodeAt(o.position + o.rotation * o.vertices[i]));
                }
                allVertices.AddRange(o.vertices);
            }
            nodeBuffer = currentNodes;
            return(rootCopy);
        }
Example #2
0
 public INavigable NodeAt(Vector3 position)
 {
     return(root.NodeAt(position));
 }