瀏覽代碼

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 月之前
父節點
當前提交
d136bfaac2
共有 1 個文件被更改,包括 7 次插入0 次删除
  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) {
       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.position.x,
         this.camera.position.y,
@@ -433,6 +434,12 @@ export default {
           this.camera.lookAt(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();
     },
     get_camera() {