Skip to content

Commit

Permalink
fix: some tweenjs animations not triggering
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonflatval-cognite committed Sep 2, 2024
1 parent ed730ce commit d2e066b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export default class Image360VisualTestFixture extends StreamingVisualTestFixtur
function animateTransition() {
const from = { t: 0 };
const to = { t: 1 };
const anim = new TWEEN.Tween(from)
const tween = new TWEEN.Tween(from)
.to(to, 1000)
.onUpdate(() => {
const animatedPosition = new THREE.Vector3().lerpVectors(translationFrom, translationTo, from.t);
Expand All @@ -170,9 +170,10 @@ export default class Image360VisualTestFixture extends StreamingVisualTestFixtur
})
.easing(num => TWEEN.Easing.Quintic.InOut(num))
.start(TWEEN.now());
TWEEN.add(tween);

anim.onComplete(() => {
anim.stop();
tween.onComplete(() => {
tween.stop();
clearInterval(renderTrigger);
camera.position.copy(translationTo);
const cameraForward = camera.getWorldDirection(new THREE.Vector3());
Expand Down
10 changes: 8 additions & 2 deletions viewer/packages/api/src/api-helpers/Image360ApiHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ export class Image360ApiHelper {
})
.easing(num => TWEEN.Easing.Quintic.InOut(num))
.start(TWEEN.now());
TWEEN.add(tween);

return new Promise(resolve => {
tween.onComplete(() => {
Expand All @@ -420,6 +421,7 @@ export class Image360ApiHelper {
.delay(delay)
.easing(num => TWEEN.Easing.Quintic.InOut(num))
.start(TWEEN.now());
TWEEN.add(tween);

return new Promise(resolve => {
tween.onComplete(() => {
Expand Down Expand Up @@ -608,7 +610,7 @@ function moveCameraPositionTo(manager: FlexibleCameraManager, position: Vector3,
const tempPosition = new Vector3();
manager.controls.temporarilyDisableKeyboard = true;

new TWEEN.Tween(from)
const tween = new TWEEN.Tween(from)
.to(to, duration)
.onUpdate(() => {
tempPosition.set(from.x, from.y, from.z);
Expand All @@ -624,13 +626,15 @@ function moveCameraPositionTo(manager: FlexibleCameraManager, position: Vector3,
manager.controls.temporarilyDisableKeyboard = false;
})
.start(TWEEN.now());

TWEEN.add(tween);
}

function tweenCameraToDefaultFov(manager: FlexibleCameraManager, duration: number): void {
const from = { fov: manager.controls.fov };
const to = { fov: manager.controls.options.defaultFov };
const delay = duration * 0.25;
new TWEEN.Tween(from)
const tween = new TWEEN.Tween(from)
.to(to, duration * 0.5)
.onUpdate(() => {
manager.controls.setFov(from.fov);
Expand All @@ -641,4 +645,6 @@ function tweenCameraToDefaultFov(manager: FlexibleCameraManager, duration: numbe
.delay(delay)
.easing(num => TWEEN.Easing.Quintic.InOut(num))
.start(TWEEN.now());

TWEEN.add(tween);
}
2 changes: 2 additions & 0 deletions viewer/packages/camera-manager/src/Flexible/moveCamera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export function moveCameraTargetTo(manager: FlexibleCameraManager, target: Vecto
removeEventListeners();
})
.start(TWEEN.now());

TWEEN.add(tween);
}

function createTweenAnimationWithStop<T extends Record<string, any>>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class StationaryCameraManager implements CameraManager {
})
.easing(num => TWEEN.Easing.Quintic.InOut(num))
.start(TWEEN.now());
TWEEN.add(tween);

return new Promise(resolve => {
tween.onComplete(() => {
Expand Down

0 comments on commit d2e066b

Please sign in to comment.