How can I see when a FramingBehavior animation has finished?

Is there a way to check when a FramingBehavior animation has finished, like the example animation the docs have here?

2 Likes

Hey there. :slightly_smiling_face: setTarget doesn’t have a callback, but the function used to zoom on the mesh can be called directly and does have a callback parameter.

So for example, you can create the FramingBehavior object, attach it to the camera and then call zoomOnMesh manually with a callback parameter, like on the below playground. :beers:
https://playground.babylonjs.com/#6FBD14#1473

Edit: it’s a little easier now that the PR is live (a hard page refresh might be needed thou). :slight_smile:
https://playground.babylonjs.com/#5T0H6Q

2 Likes

This is perfect, thank you so much!

2 Likes

@Blake has already shared a great solution, so I just wanted to chime in and say welcome to the Babylon community, and happy developing :slight_smile: Let us know if you have more questions!

2 Likes

Thank you! The community has been really helpful in figuring out Babylon.

2 Likes

I wonder if it would be good to add a callback property to FramingBehavior that gets passed to zoomOnMesh when the target is changed?

It was only a few lines of code so I jumped in and did it with a PR, which could be used like below for example:

// setup framing behavior
camera.useFramingBehavior = true;
camera.framingBehavior.onTargetFramingAnimationEnd = () => {
    alert("Finished framing!");
};

// set target
camera.setTarget(box);

PS, let me know if an observable would be better and I can rework it. :slightly_smiling_face:

Edit: hurray the patch is live with a new observable! :beers:
https://playground.babylonjs.com/#5T0H6Q

1 Like