Exemplo n.º 1
0
		/** Rebuilds the BBTree on a NavGraph.
		 * \astarpro
		 * \see NavMeshGraph.bbTree */
		public static void RebuildBBTree (NavMeshGraph graph) {
			// Build Axis Aligned Bounding Box Tree

			BBTree bbTree = graph.bbTree;
			bbTree = bbTree ?? new BBTree ();
			bbTree.RebuildFrom(graph.nodes);
			graph.bbTree = bbTree;
		}
Exemplo n.º 2
0
		public static NNInfo GetNearest (NavMeshGraph graph, GraphNode[] nodes, Vector3 position, NNConstraint constraint, bool accurateNearestNode) {
			if (nodes == null || nodes.Length == 0) {
				Debug.LogError ("NavGraph hasn't been generated yet or does not contain any nodes");
				return new NNInfo ();
			}

			if (constraint == null) constraint = NNConstraint.None;


			Int3[] vertices = graph.vertices;

			//Query BBTree

			if (graph.bbTree == null) {
				/** \todo Change method to require a navgraph */
				return GetNearestForce (graph, graph, position, constraint, accurateNearestNode);
			}

			//Searches in radiuses of 0.05 - 0.2 - 0.45 ... 1.28 times the average of the width and depth of the bbTree
			float w = (graph.bbTree.Size.width + graph.bbTree.Size.height)*0.5F*0.02F;

			NNInfo query = graph.bbTree.QueryCircle (position,w,constraint);//graph.bbTree.Query (position,constraint);

			if (query.node == null) {

				for (int i=1;i<=8;i++) {
					query = graph.bbTree.QueryCircle (position, i*i*w, constraint);

					if (query.node != null || (i-1)*(i-1)*w > AstarPath.active.maxNearestNodeDistance*2) { // *2 for a margin
						break;
					}
				}
			}

			if (query.node != null) {
				query.clampedPosition = ClosestPointOnNode (query.node as TriangleMeshNode,vertices,position);
			}

			if (query.constrainedNode != null) {
				if (constraint.constrainDistance && ((Vector3)query.constrainedNode.position - position).sqrMagnitude > AstarPath.active.maxNearestNodeDistanceSqr) {
					query.constrainedNode = null;
				} else {
					query.constClampedPosition = ClosestPointOnNode (query.constrainedNode as TriangleMeshNode, vertices, position);
				}
			}

			return query;
		}