Skip to content

Commit

Permalink
Fix orbit controls of ui.scene after changing the camera's up vector (
Browse files Browse the repository at this point in the history
#3544)

* Remove hardcoded z-up for scene orbit controls

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

This reverts commit 8c80453.

* Reset OrbitControls after camera up changed

---------

Co-authored-by: Andreas Voigt <andreas.voigt@optonic.com>
  • Loading branch information
voigta and Andreas Voigt committed Sep 6, 2024
1 parent e6f12ce commit d136bfa
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions nicegui/elements/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit d136bfa

Please sign in to comment.