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

intersectsBVH

介绍

intersectsBVH是Yuka js库中的一种方法,它是用于判断一个ray是否与BVH树(Bounding Volume Hierarchy)相交的方法,如果相交则返回最近的交点,如果未相交则返回null。

语法

ray.intersectsBVH( bvh, intersectsBackFaces )

参数

  • bvh: BVH tree
  • intersectsBackFaces: 可选参数,默认值为false。如果为true,则允许光线与背面相交。

返回值

  • 如果光线与BVH相交,则返回最近的交点。否则返回null。

示例

下面的例子演示了如何使用intersectsBVH函数:

var bvh = new BVHTree( meshes );
var ray = new Ray( origin, direction );
var result = ray.intersectsBVH( bvh, true );
if ( result ) {
    console.log( "The ray intersects the BVH at point:", result.point );
} else {
    console.log( "The ray does not intersect the BVH." );
}

注意事项

  • BVH树必须使用BVHTree类创建,具体详情可参见Yuka js库的BVHTree文档。
  • 该函数仅适用于Mesh类型的对象。如果想判断ray是否与其他类型的物体相交,可以使用其他函数,如IntersectSphere等。

参考文献