Skip to content

Commit

Permalink
Fix camera looking back to the origin after calling move_camera() (#…
Browse files Browse the repository at this point in the history
…3920)

This PR fixes a problem introduced by PR #3544: The camera kept looking
at the origin when calling `move_camera()` with given `look_at_*`
coordinates.

The fix can be verified with the following snippet. Moving back and
forth between the spheres should not point the camera back to the
origin, an the orbit controls should orbit around the sphere which is
currently looked at:
```py
with ui.scene() as scene:
    scene.sphere().move(1, 2, 0).material('blue')
    scene.sphere().move(4, 5, 0).material('red')

ui.button('blue', on_click=lambda: scene.move_camera(*(1, 2, 3), *(1, 2, 0), *(0, 1, 0), duration=1))
ui.button('red', on_click=lambda: scene.move_camera(*(4, 5, 6), *(4, 5, 0), *(0, 1, 0), duration=0))
```
  • Loading branch information
falkoschindler authored Oct 25, 2024
1 parent 79f6d76 commit 5f9b3ff
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nicegui/elements/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ export default {
if (camera_up_changed) {
this.controls.dispose();
this.controls = new OrbitControls(this.camera, this.renderer.domElement);
this.controls.target.copy(this.look_at);
this.camera.lookAt(this.look_at);
}
})
.start();
Expand Down

0 comments on commit 5f9b3ff

Please sign in to comment.