From aecb1e93bf541ac0beb9c2e849b7a090643aad28 Mon Sep 17 00:00:00 2001 From: Sebastiaan ten Pas Date: Thu, 21 Oct 2021 16:22:37 +0100 Subject: [PATCH 1/4] Use custom raycaster in ArcballControls --- examples/jsm/controls/ArcballControls.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/jsm/controls/ArcballControls.js b/examples/jsm/controls/ArcballControls.js index 0372d6210ecd69..8d92698c366f85 100644 --- a/examples/jsm/controls/ArcballControls.js +++ b/examples/jsm/controls/ArcballControls.js @@ -80,6 +80,7 @@ class ArcballControls extends Object3D { this.domElement = domElement; this.scene = scene; this.target = new Vector3( 0, 0, 0 ); + this.raycaster = new Raycaster(); this.mouseActions = []; this._mouseOp = null; @@ -2817,12 +2818,11 @@ class ArcballControls extends Object3D { */ unprojectOnObj = ( cursor, camera ) => { - const raycaster = new Raycaster(); - raycaster.near = camera.near; - raycaster.far = camera.far; - raycaster.setFromCamera( cursor, camera ); + this.raycaster.near = camera.near; + this.raycaster.far = camera.far; + this.raycaster.setFromCamera( cursor, camera ); - const intersect = raycaster.intersectObjects( this.scene.children, true ); + const intersect = this.raycaster.intersectObjects( this.scene.children, true ); for ( let i = 0; i < intersect.length; i ++ ) { From b62839d69f20061f3750ddd83c37789ad9f6c35b Mon Sep 17 00:00:00 2001 From: Sebastiaan ten Pas Date: Thu, 21 Oct 2021 16:24:26 +0100 Subject: [PATCH 2/4] Use custom raycaster in ArcballControls --- examples/js/controls/ArcballControls.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/js/controls/ArcballControls.js b/examples/js/controls/ArcballControls.js index 0be11b6fbee06f..745d535536d266 100644 --- a/examples/js/controls/ArcballControls.js +++ b/examples/js/controls/ArcballControls.js @@ -2323,11 +2323,10 @@ this.unprojectOnObj = ( cursor, camera ) => { - const raycaster = new THREE.Raycaster(); - raycaster.near = camera.near; - raycaster.far = camera.far; - raycaster.setFromCamera( cursor, camera ); - const intersect = raycaster.intersectObjects( this.scene.children, true ); + this.raycaster.near = camera.near; + this.raycaster.far = camera.far; + this.raycaster.setFromCamera( cursor, camera ); + const intersect = this.raycaster.intersectObjects( this.scene.children, true ); for ( let i = 0; i < intersect.length; i ++ ) { @@ -2681,6 +2680,7 @@ this.domElement = domElement; this.scene = scene; this.target = new THREE.Vector3( 0, 0, 0 ); + this.raycaster = new Raycaster(); this.mouseActions = []; this._mouseOp = null; //global vectors and matrices that are used in some operations to avoid creating new objects every time (e.g. every time cursor moves) From 5cbb9c5fe6afa569465381649fa3b5975500dd04 Mon Sep 17 00:00:00 2001 From: Sebastiaan ten Pas Date: Fri, 22 Oct 2021 10:14:45 +0100 Subject: [PATCH 3/4] Add ArcballControls.raycaster to docs --- docs/examples/en/controls/ArcballControls.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/examples/en/controls/ArcballControls.html b/docs/examples/en/controls/ArcballControls.html index f91c9986e99fdf..6d9ae2597c988f 100644 --- a/docs/examples/en/controls/ArcballControls.html +++ b/docs/examples/en/controls/ArcballControls.html @@ -189,6 +189,11 @@

[property:Float wMax]

Maximum angular velocity allowed on rotation animation start.

+

[property:Raycaster raycaster]

+

+ The raycaster used to intersect objects for focusing. +

+

Methods

From 5ed443f1a173beb52c108e4c616c4a2bf3592809 Mon Sep 17 00:00:00 2001 From: Sebastiaan ten Pas Date: Mon, 25 Oct 2021 11:20:45 +0100 Subject: [PATCH 4/4] ArcballControls: Add getRaycaster() method --- .../examples/en/controls/ArcballControls.html | 13 ++++++++----- examples/js/controls/ArcballControls.js | 18 +++++++++++++----- examples/jsm/controls/ArcballControls.js | 19 ++++++++++++++----- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/docs/examples/en/controls/ArcballControls.html b/docs/examples/en/controls/ArcballControls.html index 6d9ae2597c988f..74aa19858e8c54 100644 --- a/docs/examples/en/controls/ArcballControls.html +++ b/docs/examples/en/controls/ArcballControls.html @@ -189,11 +189,6 @@

[property:Float wMax]

Maximum angular velocity allowed on rotation animation start.

-

[property:Raycaster raycaster]

-

- The raycaster used to intersect objects for focusing. -

-

Methods

@@ -261,6 +256,14 @@

[method:null update] ()

Update the controls. Must be called after any manual changes to the camera's transform.

+ +

[method:Raycaster getRaycaster] ()

+

+ 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. +

Source

diff --git a/examples/js/controls/ArcballControls.js b/examples/js/controls/ArcballControls.js index 745d535536d266..ffa192d875ef93 100644 --- a/examples/js/controls/ArcballControls.js +++ b/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,12 +2323,19 @@ }; + this.getRaycaster = () => { + + return _raycaster; + + }; + this.unprojectOnObj = ( cursor, camera ) => { - this.raycaster.near = camera.near; - this.raycaster.far = camera.far; - this.raycaster.setFromCamera( cursor, camera ); - const intersect = this.raycaster.intersectObjects( this.scene.children, true ); + const raycaster = this.getRaycaster(); + raycaster.near = camera.near; + raycaster.far = camera.far; + raycaster.setFromCamera( cursor, camera ); + const intersect = raycaster.intersectObjects( this.scene.children, true ); for ( let i = 0; i < intersect.length; i ++ ) { @@ -2680,7 +2689,6 @@ this.domElement = domElement; this.scene = scene; this.target = new THREE.Vector3( 0, 0, 0 ); - this.raycaster = new Raycaster(); this.mouseActions = []; this._mouseOp = null; //global vectors and matrices that are used in some operations to avoid creating new objects every time (e.g. every time cursor moves) diff --git a/examples/jsm/controls/ArcballControls.js b/examples/jsm/controls/ArcballControls.js index 8d92698c366f85..85e913678be6ec 100644 --- a/examples/jsm/controls/ArcballControls.js +++ b/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(); + /** * @@ -80,7 +82,6 @@ class ArcballControls extends Object3D { this.domElement = domElement; this.scene = scene; this.target = new Vector3( 0, 0, 0 ); - this.raycaster = new Raycaster(); this.mouseActions = []; this._mouseOp = null; @@ -2809,6 +2810,13 @@ class ArcballControls extends Object3D { }; + + getRaycaster() { + + return _raycaster; + + } + /** * Unproject the cursor on the 3D object surface @@ -2818,11 +2826,12 @@ class ArcballControls extends Object3D { */ unprojectOnObj = ( cursor, camera ) => { - this.raycaster.near = camera.near; - this.raycaster.far = camera.far; - this.raycaster.setFromCamera( cursor, camera ); + const raycaster = this.getRaycaster(); + raycaster.near = camera.near; + raycaster.far = camera.far; + raycaster.setFromCamera( cursor, camera ); - const intersect = this.raycaster.intersectObjects( this.scene.children, true ); + const intersect = raycaster.intersectObjects( this.scene.children, true ); for ( let i = 0; i < intersect.length; i ++ ) {