提交 4ce5ba20 编写于 作者: M Mugen87

Raycaster: Use THREE.Layers in intersectObject().

上级 b03e2af7
......@@ -61,7 +61,8 @@
<h3>[property:Layers layers]</h3>
<p>
The layer membership of the object. The object is only visible if it has at least one
layer in common with the [page:Camera] in use.
layer in common with the [page:Camera] in use. This property can also be used to filter out
unwanted objects in ray-intersection tests when using [page:Raycaster].
</p>
<h3>[property:Matrix4 matrix]</h3>
......
......@@ -107,6 +107,18 @@
Defaults to null.
</p>
<h3>[property:Layers layers]</h3>
<p>
Used by [name] to selectively ignore 3D objects when performing intersection tests. The following code example ensures that
only 3D objects on layer *1* will be honored by the instance of [name].
<code>
raycaster.layers.set( 1 );
object.layers.enable( 1 );
</code>
</p>
<h3>[property:Object params]</h3>
<p>
An object with the following properties:
......
......@@ -59,7 +59,8 @@
<h3>[property:Layers layers]</h3>
<p>
物体的层级关系。
物体只有和一个正在使用的[page:Camera]至少在同一个层时才可见。
物体只有和一个正在使用的[page:Camera]至少在同一个层时才可见。This property can also be used to filter out
unwanted objects in ray-intersection tests when using [page:Raycaster].
</p>
<h3>[property:Matrix4 matrix]</h3>
......@@ -199,7 +200,7 @@
<h3>[method:Object3D applyQuaternion]( [param:Quaternion quaternion] )</h3>
<p>对当前物体应用由四元数所表示的变换。</p>
<h3>[method:this attach]( [param:Object3D object] )</h3>
<p>将*object*作为子级来添加到该对象中,同时保持该object的世界变换。</p>
......
......@@ -105,6 +105,18 @@
Defaults to null.
</p>
<h3>[property:Layers layers]</h3>
<p>
Used by [name] to selectively ignore 3D objects when performing intersection tests. The following code example ensures that
only 3D objects on layer *1* will be honored by the instance of [name].
<code>
raycaster.layers.set( 1 );
object.layers.enable( 1 );
</code>
</p>
<h3>[property:Object params]</h3>
<p>
具有以下属性的对象:<code>
......
......@@ -4,6 +4,7 @@ import { Object3D } from './Object3D';
import { Vector2 } from './../math/Vector2';
import { Ray } from './../math/Ray';
import { Camera } from './../cameras/Camera';
import { Layers } from './Layers';
export interface Intersection {
distance: number;
......@@ -62,6 +63,11 @@ export class Raycaster {
*/
camera: Camera;
/**
* Used by Raycaster to selectively ignore 3D objects when performing intersection tests.
*/
layers: Layers;
params: RaycasterParameters;
/**
......
import { Ray } from '../math/Ray.js';
import { Layers } from './Layers.js';
/**
* @author mrdoob / http://mrdoob.com/
......@@ -14,6 +15,7 @@ function Raycaster( origin, direction, near, far ) {
this.near = near || 0;
this.far = far || Infinity;
this.camera = null;
this.layers = new Layers();
this.params = {
Mesh: {},
......@@ -44,9 +46,11 @@ function ascSort( a, b ) {
function intersectObject( object, raycaster, intersects, recursive ) {
if ( object.visible === false ) return;
if ( object.layers.test( raycaster.layers ) ) {
object.raycast( raycaster, intersects );
object.raycast( raycaster, intersects );
}
if ( recursive === true ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册