Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix zoom not working #678

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export class ControlsManager {
private perspectiveControls: OrbitControls;
/** Orbit controls for the orthographic view. */
private orthographicControls: OrbitControls;
/** Pairs of camera and their animation for zoom controls. */
private zoomCameraAnimPairs: { camera: Camera; anim: any }[];

/**
* Constructor for setting up all the controls.
Expand Down Expand Up @@ -92,8 +90,6 @@ export class ControlsManager {
this.transformSync();
this.updateSync();
});
// Initialize the zoom controls
this.initializeZoomControls();
// Modify camera(s) on window resize
this.setupResize(rendererElement);
}
Expand Down Expand Up @@ -263,29 +259,31 @@ export class ControlsManager {
* @param zoomTime The time it takes for a zoom animation to complete.
*/
public zoomTo(zoomFactor: number, zoomTime: number) {
for (const zoomCameraAnimPair of this.zoomCameraAnimPairs) {
const camera: any = zoomCameraAnimPair.camera;
const anim = zoomCameraAnimPair.anim;
if (camera.isOrthographicCamera) {
anim.to(
{
zoom: camera.zoom * (1 / zoomFactor),
},
zoomTime,
);
for (const camera of this.getAllCameras()) {
if (camera instanceof OrthographicCamera) {
const animation = new Tween(camera);
animation
.to(
{
zoom: camera.zoom * (1 / zoomFactor),
},
zoomTime,
)
.start();
camera.updateProjectionMatrix();
} else {
const cameraPosition = camera.position;
anim.to(
{
x: cameraPosition.x * zoomFactor,
y: cameraPosition.y * zoomFactor,
z: cameraPosition.z * zoomFactor,
},
zoomTime,
);
const animation = new Tween(camera.position);
animation
.to(
{
x: camera.position.x * zoomFactor,
y: camera.position.y * zoomFactor,
z: camera.position.z * zoomFactor,
},
zoomTime,
)
.start();
}
anim.start();
}
}

Expand Down Expand Up @@ -408,23 +406,6 @@ export class ControlsManager {
});
}

/**
* Initialize the zoom controls by setting up the camera and their animations as pairs.
*/
private initializeZoomControls() {
const allCameras: any[] = this.getAllCameras();
this.zoomCameraAnimPairs = [];
for (const camera of allCameras) {
const animation = camera.isOrthographicCamera
? new Tween(camera)
: new Tween(camera.position);
this.zoomCameraAnimPairs.push({
camera: camera,
anim: animation,
});
}
}

/**
* Synchronously update position of the orbit controls.
* @param controls Orbit controls whose position is to be updated.
Expand Down
Loading