question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problems with ArcballControls

See original GitHub issue

scale

TypeError
Cannot assign to read only property 'scale' of object '#<ArcballControls>'
new ArcballControls
/src/ArcballControls.js:66:48
  63 |  * @param {Scene} scene The scene to be rendered
  64 |  */
  65 | class ArcballControls extends Object3D {
> 66 |   constructor(camera, domElement, scene = null) {

It extends Object3D which has made scale a configured prop that can’t be replaced, but then it defines a scale function. It should be renamed setScale as it is in conflict with the base class (O3D).

target

current arcball can’t be controlled generically from outside like other controls. this is because exposing this.target was not enough. it has a setTarget function that sets gizmos, and for some reason the update function takes the gizmo position into account, not the target.

changeset

i have made the necessary changes in three-stdlib but for the sake of coherency maybe it would be good to bring them over.

@@ -189,6 +189,8 @@ class ArcballControls extends Object3D {
 
     //trackball parameters
     this.target = new Vector3(0, 0, 0)
+    this._currentTarget = new Vector3(0, 0, 0)
+
     this._tbRadius = 1
 
-  /**
-   * Set the trackball's center point
-   * @param {Number} x X coordinate
-   * @param {Number} y Y coordinate
-   * @param {Number} z Z coordinate
-   */
-  setTarget = (x, y, z) => {
-    this.target.set(x, y, z)
-    this._gizmos.position.set(x, y, z) //for correct radius calculation
-    this._tbRadius = this.calculateTbRadius(this.camera)
-
-    this.makeGizmos(this.target, this._tbRadius)
-    this.camera.lookAt(this.target)
-  }
-
   /**
    * Set values in transformation object
    * @param {Matrix4} camera Transformation to be applied to the camera
@@ -2497,12 +2484,23 @@ class ArcballControls extends Object3D {
   update = () => {
     const EPS = 0.000001
 
+    if (!this.target.equals(this._currentTarget)) {
+      this._gizmos.position.set(this.target.x, this.target.y, this.target.z) //for correct radius calculation
+      this._tbRadius = this.calculateTbRadius(this.camera)
+      this.makeGizmos(this.target, this._tbRadius)
+      this._currentTarget.copy(this.target)
+    }
+

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
drcmdacommented, Nov 12, 2021

no problem. will do it … just working on some other arcball issues i’m profiling right now, but will come back to this.

1reaction
Mugen87commented, Dec 17, 2021

Feel free to create another PR with your fixes. However, removing setTarget() makes the controls more similar to the others so we wanted to do this anway.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TrackballControls not working - Questions - three.js forum
Hi I'm tring to use TrackballControls but it is not working. I can't zoom in / out or rotate things. When i use...
Read more >
Trackball controls behaving oddly - Stack Overflow
I put together a fiddle which demonstrates the issue. Simply pan away from the ball (right click + mouse move). Then zoom out....
Read more >
TrackballControls don't work if camera.position is on the y-axis
I think this is a problem with TrackballControls , and is due to its sensitivity to camera.up , which defaults to the y-axis....
Read more >
threejs-facade TrackBallControls noob problem - Google Groups
I'm trying the TrackBallControls (https://github.com/antonkulaga/threejs-facade/blob/master/facade/src/main/scala/org/denigma/threejs/extras/TrackBallControls.
Read more >
Adding Trackball Controls to a Three.js Scene with Sprites
Today I want to add the ability to zoom, rotate and pan my mind map to take an important step in that direction...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found