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

traverse是一个遍历BVH(Bouding Volume Hierarchy)树的方法,可用于检测场景中的碰撞或光线追踪。

语法

bvh.traverse(callback);

参数

  • callback:遍历每个节点时要执行的回调函数。该回调函数接收一个参数,即当前节点。

示例

var bvh = new BVH(mesh.vertices, mesh.indices);

function checkCollision(node) {
  // 检测当前节点是否与其他对象碰撞,如有碰撞,则做出相应处理
}

bvh.traverse(checkCollision);

在上述示例中,我们创建了一个BVH树,并使用traverse方法遍历每个节点。在遍历每个节点时,我们调用了名为checkCollision的回调函数,用于检测当前节点是否与其他对象碰撞。

注意事项

  • 在回调函数中,您可以访问节点的属性,例如节点的盒子范围、子节点、父节点等。
  • 如果节点已经被删除,则回调函数不会被执行。