AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

traverse

该方法用于遍历BVH树中的节点,执行函数并传递每个节点作为参数。

语法

BVHNode.traverse( callback: Function ) : void

参数

  • callback:一个函数,它将作为每个节点的处理程序,应该接收一个BVHNode作为其唯一的参数。

描述

该方法用于遍历BVH树中的节点。从根节点开始,该方法沿着树的深度优先遍历,然后对每个节点执行传递的回调函数。如果某个节点具有一个或多个子节点,则该方法将递归地遍历这些子节点。

示例

let rootNode = new BVHNode();
let childNode1 = new BVHNode();
let childNode2 = new BVHNode();

rootNode.addChild(childNode1);
rootNode.addChild(childNode2);

rootNode.traverse((node) => {
    console.log(node); //打印每个节点
});

在这个例子中,我们首先创建了一个BVH根节点rootNode和两个子节点childNode1childNode2。使用addChild方法,我们将子节点添加到根节点。接下来,我们使用traverse方法遍历树,并传递一个回调函数。该函数将被调用一次,该参数是根节点,然后两次被调用,并分别传递childNode1childNode2作为参数。最终,我们会将每个节点打印到控制台上。

参考