Skip to content

Commit

Permalink
refactor: update camera animation stop behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Neosoulink committed Jan 21, 2024
1 parent e7efd8b commit feb110c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
16 changes: 9 additions & 7 deletions src/experiences/home/camera-animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,14 @@ export class CameraAnimation extends ExperienceBasedBlueprint {
?.updateCameraPosition(
this.positionOnCurve,
this._navigation.view.center,
Config.GSAP_ANIMATION_DURATION * 0.4
Config.GSAP_ANIMATION_DURATION * 0.3
)
.add(() => {
this._camera?.resetFov(Config.GSAP_ANIMATION_DURATION * 0.3);
}, "<")
.add(() => {
this.emit(events.STARTED, this);
});
}, `+=${Config.GSAP_ANIMATION_DURATION * 0.3}`);
}

public disable() {
Expand All @@ -139,15 +142,14 @@ export class CameraAnimation extends ExperienceBasedBlueprint {
this.enabled = false;
if (this._navigation?.view) this._navigation.view.controls = true;

return this._navigation
?.updateCameraPosition(
this.positionOnCurve.setY(this._camera?.lookAtPosition.y ?? 0),
this._navigation.view.center,
return this._camera
?.updateCameraFov(
this._camera.initialCameraFov - 2.5,
Config.GSAP_ANIMATION_DURATION * 0.2
)
.add(() => {
this.emit(events.ENDED, this);
});
}, ">");
}

public update(): void {
Expand Down
16 changes: 8 additions & 8 deletions src/experiences/home/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,32 +114,32 @@ export class Camera extends ExperienceBasedBlueprint {
}

public cameraZoomIn() {
if (!(this.instance instanceof PerspectiveCamera)) return;
if (!(this.instance instanceof PerspectiveCamera)) this._timeline;
if (this._timeline.isActive()) this.timeline.progress(1);

this._timeline.to(this.instance, {
return this._timeline.to(this.instance, {
fov: 25,
duration: Config.GSAP_ANIMATION_DURATION,
});
}

public updateCameraFov(fov: number, duration?: number) {
if (!(this.instance instanceof PerspectiveCamera)) return;
if (!(this.instance instanceof PerspectiveCamera)) return this._timeline;
if (this._timeline.isActive()) this.timeline.progress(1);

this._timeline.to(this.instance, {
return this._timeline.to(this.instance, {
fov: Number(fov),
duration: Number(duration) ?? Config.GSAP_ANIMATION_DURATION,
});
}

public resetFov() {
if (!(this.instance instanceof PerspectiveCamera)) return;
public resetFov(duration = Config.GSAP_ANIMATION_DURATION) {
if (!(this.instance instanceof PerspectiveCamera)) return this._timeline;
if (this._timeline.isActive()) this.timeline.progress(1);

this._timeline.to(this.instance, {
return this._timeline.to(this.instance, {
fov: this.initialCameraFov,
duration: Config.GSAP_ANIMATION_DURATION,
duration: duration,
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/experiences/home/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ export class Interactions extends ExperienceBasedBlueprint {
this._lastCameraTarget,
duration
)
.add(() => this._camera?.resetFov(), "<");
.add(() => {
this._camera?.resetFov();
}, "<");
}
}

Expand Down

0 comments on commit feb110c

Please sign in to comment.