diff --git a/docs/api/en/core/Object3D.html b/docs/api/en/core/Object3D.html index 2bef4dfa941a2..9f31fce8eb3e8 100644 --- a/docs/api/en/core/Object3D.html +++ b/docs/api/en/core/Object3D.html @@ -61,7 +61,8 @@
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].
+ 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].
+
+
+ raycaster.layers.set( 1 );
+ object.layers.enable( 1 );
+
+
+
An object with the following properties: diff --git a/docs/api/zh/core/Object3D.html b/docs/api/zh/core/Object3D.html index f74b814deb956..194408c8a945e 100644 --- a/docs/api/zh/core/Object3D.html +++ b/docs/api/zh/core/Object3D.html @@ -59,7 +59,8 @@
物体的层级关系。 - 物体只有和一个正在使用的[page:Camera]至少在同一个层时才可见。 + 物体只有和一个正在使用的[page:Camera]至少在同一个层时才可见。This property can also be used to filter out + unwanted objects in ray-intersection tests when using [page:Raycaster].
对当前物体应用由四元数所表示的变换。
- +将*object*作为子级来添加到该对象中,同时保持该object的世界变换。
diff --git a/docs/api/zh/core/Raycaster.html b/docs/api/zh/core/Raycaster.html index 1c733f9ff7dfc..941745623ecf4 100644 --- a/docs/api/zh/core/Raycaster.html +++ b/docs/api/zh/core/Raycaster.html @@ -105,6 +105,18 @@
+ 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].
+
+
+ raycaster.layers.set( 1 );
+ object.layers.enable( 1 );
+
+
+
具有以下属性的对象:
diff --git a/src/core/Raycaster.d.ts b/src/core/Raycaster.d.ts
index 1639e178c80cd..df1e812a796b8 100644
--- a/src/core/Raycaster.d.ts
+++ b/src/core/Raycaster.d.ts
@@ -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;
/**
diff --git a/src/core/Raycaster.js b/src/core/Raycaster.js
index f04d516436562..2f171546a5932 100644
--- a/src/core/Raycaster.js
+++ b/src/core/Raycaster.js
@@ -1,4 +1,5 @@
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 ) {