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

intersectRay方法是Yuka js库的MeshGeometry中的一个函数,用于检测一个光线与几何网格的交点。该函数能够判断光线是否与几何网格进行了碰撞,并返回该碰撞点的位置信息。

语法

intersectRay( origin, direction, distance )

参数

  • origin: 光线的起点坐标,可以是一个THREE.Vector3对象或者具有x、y和z属性的对象。
  • direction: 光线的方向向量,可以是一个THREE.Vector3对象或者具有x、y和z属性的对象。
  • distance: 光线的长度,用于指定检测的最大距离。

返回值

该函数返回一个交点Info对象,用于描述与光线碰撞的几何体的位置和法线方向等信息,具体格式如下:

{
    distance: float,           // 光线与交点的距离
    point: new THREE.Vector3(),// 交点的三维坐标
    normal: new THREE.Vector3() // 交点的法线方向
}

如果光线未与几何网格进行碰撞,返回null。

示例

const meshGeometry = new YUKA.MeshGeometry( geometryData );
const origin = new THREE.Vector3( 0, 0, 0 );
const direction = new THREE.Vector3( 0, 1, 0 );
const distance = Infinity;
const intersection = meshGeometry.intersectRay( origin, direction, distance );
if ( intersection !== null ) {
    console.log( intersection.distance );
    console.log( intersection.point );
    console.log( intersection.normal );
}

以上示例为创建一个MeshGeometry对象,并使用intersectRay方法检测(0,0,0)到(0,1,0)的光线是否与几何网格进行了碰撞,如果有则返回交点的信息。