Skip to content

Commit

Permalink
ArcballControls: Expose raycaster. (#22719)
Browse files Browse the repository at this point in the history
* Use custom raycaster in ArcballControls

* Use custom raycaster in ArcballControls

* Add ArcballControls.raycaster to docs

* ArcballControls: Add getRaycaster() method
  • Loading branch information
Tirzono authored Oct 26, 2021
1 parent 431baa0 commit b27e4c8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/examples/en/controls/ArcballControls.html
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ <h3>[method:null update] ()</h3>
<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>

Expand Down
10 changes: 9 additions & 1 deletion examples/js/controls/ArcballControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
const _endEvent = {
type: 'end'
};

const _raycaster = new THREE.Raycaster();
/**
*
* @param {Camera} camera Virtual camera used in the scene
Expand Down Expand Up @@ -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 );
Expand Down
11 changes: 10 additions & 1 deletion examples/jsm/controls/ArcballControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const _changeEvent = { type: 'change' };
const _startEvent = { type: 'start' };
const _endEvent = { type: 'end' };

const _raycaster = new Raycaster();


/**
*
Expand Down Expand Up @@ -2808,6 +2810,13 @@ class ArcballControls extends Object3D {

};


getRaycaster() {

return _raycaster;

}


/**
* Unproject the cursor on the 3D object surface
Expand All @@ -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 );
Expand Down

0 comments on commit b27e4c8

Please sign in to comment.