three.js Ray

2023-02-16 17:46 更新

射線由一個(gè)原點(diǎn)向一個(gè)確定的方向發(fā)射。它被Raycaster(光線投射)所使用, 以用于輔助raycasting。 光線投射用于在各個(gè)物體之間進(jìn)行拾?。ó?dāng)鼠標(biāo)經(jīng)過三維空間中的物體/對(duì)象時(shí)進(jìn)行拾?。?。

構(gòu)造函數(shù)

Ray( origin : Vector3, direction : Vector3 )

origin - (可選)Ray(射線)的原點(diǎn),默認(rèn)值是一個(gè)位于(0, 0, 0)的Vector3。
direction - Vector3 Ray(射線)的方向。該向量必須經(jīng)過標(biāo)準(zhǔn)化(使用Vector3.normalize),這樣才能使方法正常運(yùn)行。 默認(rèn)值是一個(gè)位于(0, 0, -1)的Vector3。

創(chuàng)建一個(gè)新的Ray。

屬性

.origin : Vector3

Ray(射線)的原點(diǎn),默認(rèn)值是一個(gè)位于(0, 0, 0)的Vector3。

.direction : Vector3

Ray(射線)的方向。該向量必須經(jīng)過標(biāo)準(zhǔn)化(使用Vector3.normalize),這樣才能使方法正常運(yùn)行。 默認(rèn)值是一個(gè)位于(0, 0, -1)的Vector3。

方法

.applyMatrix4 ( matrix4 : Matrix4 ) : this

matrix4 - 將被用于這個(gè)Ray的Matrix4。

使用傳入的Matrix4來變換這個(gè)Ray。

.at ( t : Float, target : Vector3 ) : Vector3

t - 使用這一傳入的距離,在Ray上確定一個(gè)位置。
target — 結(jié)果將復(fù)制到這一Vector3中。

獲得這一Ray上給定距離處的Vector3。

.clone () : Ray

創(chuàng)建一個(gè)新的和這個(gè)Ray具有相同origin和direction的Ray。

.closestPointToPoint ( point : Vector3, target : Vector3 ) : Vector3

point - 獲得距離射線上的點(diǎn)最接近的點(diǎn)。
target — 結(jié)果將復(fù)制到這一Vector3中。

沿著Ray,獲得與所傳入Vector3最接近的點(diǎn)。

.copy ( ray : Ray ) : this

復(fù)制所傳入Ray的origin和direction屬性到這個(gè)Ray上。

.distanceSqToPoint ( point : Vector3 ) : Float

point - 將被用于計(jì)算到其距離的 Vector3。

獲得Ray與傳入的Vector3之間最近的平方距離。

.distanceSqToSegment ( v0 : Vector3, v1 : Vector3, optionalPointOnRay : Vector3, optionalPointOnSegment : Vector3 ) : Float

v0 - 線段的起點(diǎn)。
v1 - 線段的終點(diǎn)。
optionalPointOnRay - (可選)若這個(gè)值被給定,它將接收在Ray(射線)上距離線段最近的點(diǎn)。
optionalPointOnSegment - (可選)若這個(gè)值被給定,它將接收在線段上距離Ray(射線)最近的點(diǎn)。

獲取Ray(射線)與線段之間的平方距離。

.distanceToPlane ( plane : Plane ) : Float

plane - 將要獲取射線原點(diǎn)到該平面的距離的平面。

獲取射線原點(diǎn)(origin)到平面(Plane)之間的距離。若射線(Ray)不與平面(Plane)相交,則將返回null。

.distanceToPoint ( point : Vector3 ) : Float

point - Vector3 將被用于計(jì)算到其距離的Vector3。

獲得Ray(射線)到所傳入point之間最接近的距離。

.equals ( ray : Ray ) : Boolean

ray - 用于比較的Ray。

如果所傳入的ray具有和當(dāng)前Ray相同的origin和direction則返回true。

.intersectBox ( box : Box3, target : Vector3 ) : Vector3

box - 將會(huì)與之相交的Box3。
target — 結(jié)果將會(huì)被復(fù)制到這一Vector3中。

將Ray(射線)與一個(gè)Box3相交,并返回交點(diǎn),倘若沒有交點(diǎn)將返回null。

.intersectPlane ( plane : Plane, target : Vector3 ) : Vector3

plane - 將會(huì)與之相交的Plane。
target — 結(jié)果將會(huì)被復(fù)制到這一Vector3中。

將Ray(射線)與一個(gè)Plane相交,并返回交點(diǎn),倘若沒有交點(diǎn)將返回null。

.intersectSphere ( sphere : Sphere, target : Vector3 ) : Vector3

sphere - 將會(huì)與之相交的Sphere。
target — 結(jié)果將會(huì)被復(fù)制到這一Vector3中。

將Ray(射線)與一個(gè)Sphere(球)相交,并返回交點(diǎn),倘若沒有交點(diǎn)將返回null。

.intersectTriangle ( a : Vector3, b : Vector3, c : Vector3, backfaceCulling : Boolean, target : Vector3 ) : Vector3

a, b, c - 組成三角形的三個(gè)Vector3。
backfaceCulling - 是否使用背面剔除。
target — 結(jié)果將會(huì)被復(fù)制到這一Vector3中。

將Ray(射線)與一個(gè)三角形相交,并返回交點(diǎn),倘若沒有交點(diǎn)將返回null。

.intersectsBox ( box : Box3 ) : Boolean

box - 將被檢查是否與之相交的Box3。

若這一射線與Box3相交,則將返回true。

.intersectsPlane ( plane : Plane ) : Boolean

plane - 將被檢查是否與之相交的Plane。

若這一射線與Plane相交,則將返回true。

.intersectsSphere ( sphere : Sphere ) : Boolean

sphere - 將被檢查是否與之相交的Sphere。

若這一射線與Sphere相交,則將返回true。

.lookAt ( v : Vector3 ) : this

v - 將要“直視”的Vector3

調(diào)整光線的方向到世界坐標(biāo)中該向量所指代的點(diǎn)。

.recast ( t : Float ) : this

t - 沿著Ray進(jìn)行插值的距離。

將Ray(射線)的原點(diǎn)沿著其方向移動(dòng)給定的距離。

.set ( origin : Vector3, direction : Vector3 ) : this

origin - Ray(射線)的origin(原點(diǎn))。
origin - Ray(射線)的direction(方向)。 該向量必須經(jīng)過標(biāo)準(zhǔn)化(使用Vector3.normalize),這樣才能使方法正常運(yùn)行。

根據(jù)參數(shù)設(shè)置該射線的 origin 和 direction 。

源代碼

src/math/Ray.js


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)