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

intersectRay

该方法用于计算BVHNode和射线的交点,并返回距离最近的交点。

语法

intersectRay(ray, tmin, tmax)

参数

  • ray:类型为Ray的对象,表示射线。
  • tmin:类型为数字的参数,表示射线起点到BVHNode的最小距离。
  • tmax:类型为数字的参数,表示射线起点到BVHNode的最大距离。

返回值

该方法返回距离射线起点最近的交点,如果没有交点则返回null

示例

var BVHNode = require('yuka').BVHNode;
var Ray = require('yuka').Ray;

var node = new BVHNode();
var ray = new Ray();

var intersection = node.intersectRay(ray, 0, Infinity);

if(intersection) {
    console.log('Intersection point:', intersection.point.x, intersection.point.y, intersection.point.z);
    console.log('Distance to intersection point:', intersection.distance);
} else {
    console.log('No intersection found.');
}

说明

该方法使用射线与BVHNode的包围盒进行相交测试,如果相交,则递归测试其子节点。当找到距离射线起点最近的最小包围盒时,使用该节点内的所有网格测试射线的交点,返回距离射线起点最近的交点。如果没有找到任何交点,则返回null