Browse Source

Fix orbit controls of `ui.scene` after changing the camera's up vector (#3544)

* Remove hardcoded z-up for scene orbit controls

* Revert "Remove hardcoded z-up for scene orbit controls"

This reverts commit 8c80453c1f9b90b8ba74f0253bb23ebad0864ae2.

* Reset OrbitControls after camera up changed

---------

Co-authored-by: Andreas Voigt <andreas.voigt@optonic.com>
Voigta 8 months ago
parent
commit
d136bfaac2
1 changed files with 7 additions and 0 deletions
  1. 7 0
      nicegui/elements/scene.js

+ 7 - 0
nicegui/elements/scene.js

@@ -401,6 +401,7 @@ export default {
     },
     },
     move_camera(x, y, z, look_at_x, look_at_y, look_at_z, up_x, up_y, up_z, duration) {
     move_camera(x, y, z, look_at_x, look_at_y, look_at_z, up_x, up_y, up_z, duration) {
       if (this.camera_tween) this.camera_tween.stop();
       if (this.camera_tween) this.camera_tween.stop();
+      const camera_up_changed = up_x !== null || up_y !== null || up_z !== null;
       this.camera_tween = new TWEEN.Tween([
       this.camera_tween = new TWEEN.Tween([
         this.camera.position.x,
         this.camera.position.x,
         this.camera.position.y,
         this.camera.position.y,
@@ -433,6 +434,12 @@ export default {
           this.camera.lookAt(p[6], p[7], p[8]);
           this.camera.lookAt(p[6], p[7], p[8]);
           this.controls.target.set(p[6], p[7], p[8]);
           this.controls.target.set(p[6], p[7], p[8]);
         })
         })
+        .onComplete(() => {
+          if (camera_up_changed) {
+            this.controls.dispose();
+            this.controls = new OrbitControls(this.camera, this.renderer.domElement);
+          }
+        })
         .start();
         .start();
     },
     },
     get_camera() {
     get_camera() {