Browse Source

ArcballControls: Expose raycaster. (#22719)

* Use custom raycaster in ArcballControls

* Use custom raycaster in ArcballControls

* Add ArcballControls.raycaster to docs

* ArcballControls: Add getRaycaster() method
Sebastiaan ten Pas 3 years ago
parent
commit
b27e4c81f3

+ 8 - 0
docs/examples/en/controls/ArcballControls.html

@@ -256,6 +256,14 @@
 		<p>
 			Update the controls. Must be called after any manual changes to the camera's transform.
 		</p>
+		
+		<h3>[method:Raycaster getRaycaster] ()</h3>
+		<p>
+			Returns the [page:Raycaster] object that is used for user interaction. This object is shared between all instances of
+			ArcballControls. If you set the [page:Object3D.layers .layers] property of the [name], you will also want to
+			set the [page:Raycaster.layers .layers] property on the [page:Raycaster] with a matching value, or else the [name]
+			won't work as expected.
+		</p>
 
 		<h2>Source</h2>
 

+ 9 - 1
examples/js/controls/ArcballControls.js

@@ -40,6 +40,8 @@
 	const _endEvent = {
 		type: 'end'
 	};
+	
+	const _raycaster = new THREE.Raycaster();
 	/**
  *
  * @param {Camera} camera Virtual camera used in the scene
@@ -2321,9 +2323,15 @@
 
 			};
 
+			this.getRaycaster = () => {
+
+				return _raycaster;
+	
+			};
+
 			this.unprojectOnObj = ( cursor, camera ) => {
 
-				const raycaster = new THREE.Raycaster();
+				const raycaster = this.getRaycaster();
 				raycaster.near = camera.near;
 				raycaster.far = camera.far;
 				raycaster.setFromCamera( cursor, camera );

+ 10 - 1
examples/jsm/controls/ArcballControls.js

@@ -64,6 +64,8 @@ const _changeEvent = { type: 'change' };
 const _startEvent = { type: 'start' };
 const _endEvent = { type: 'end' };
 
+const _raycaster = new Raycaster();
+
 
 /**
  *
@@ -2808,6 +2810,13 @@ class ArcballControls extends Object3D {
 
 	};
 
+	
+	getRaycaster() {
+
+		return _raycaster;
+
+	}
+
 
 	/**
 	 * Unproject the cursor on the 3D object surface
@@ -2817,7 +2826,7 @@ class ArcballControls extends Object3D {
 	 */
 	unprojectOnObj = ( cursor, camera ) => {
 
-		const raycaster = new Raycaster();
+		const raycaster = this.getRaycaster();
 		raycaster.near = camera.near;
 		raycaster.far = camera.far;
 		raycaster.setFromCamera( cursor, camera );