Dok11 / easy-prop-animation

EasyPropAnimation is a helpful class for Babylon.js that allows you easy to runs a property animations
MIT License
3 stars 0 forks source link

Feature request: animation abort controller #2

Open Link2Twenty opened 1 year ago

Link2Twenty commented 1 year ago

Hi, when animation a camera position I would love to have an abort controller support so I can relinquish camera control to the user if they start trying to move the view.

Currently I use my own camera moving scripts and do this

const controller = new AbortController();
const canvas = scene.getEngine().getRenderingCanvas();

const onFocus = () => controller.abort();

canvas?.addEventListener('focus', onFocus);
canvas?.addEventListener('wheel', onFocus);

// move camera
await Promise.all([
  animateCameraTo(camera, scene, controller.signal),
  animateCameraTo({ ...camTarget, prop: 'target', duration: 500 }, scene, controller.signal),
]);

canvas?.removeEventListener('focus', onFocus);
canvas?.removeEventListener('wheel', onFocus);

and I think it would be a great addition to the run function.

Dok11 commented 1 year ago

You can save result of animation and stop them when it need.

this.pointAnimatables = EasyPropAnimation.run(camera, {
  target: newTarget,
  transition: 'all 1s linear',
});

private stopPointAnimation(): void {
  this.pointAnimatables?.forEach((animatable) => animatable.stop());
}