Hi.
There are some issues with animated objects because of skeletal animation.
Main issue is that absolute position and bounding box of original mesh are not updated on every frame, which quite makes sense for performance reasons.
Problems arise when you try to target camera to a moving object, or to pick animated object.
Solutions are:
mesh.alwaysSelectAsActiveMesh = trueto make it always visiblemesh.refreshBoundingInfo({ applySkeleton: true});to recalculate bounding info (but not absolute position)
They affect performance, so it makes sense to only apply them when animation started/stopped/paused.
When refreshing bounding info, something unde the hood is calculated in render loop,
so it’s not available immediately, but like this:
scene.onAfterRenderObservable.addOnce(() => {
mesh.refreshBoundingInfo({ applySkeleton: true });
})
Here is my overcomplicated snippet:
The target is a transform node corresponding to an animated bone (and it is not root bone for some reason).
The mesh is the actual mesh, affected by animation.
Picking is set up on pointerdown events. You can try to pick during animation, if speed ratio is low enough.
On the cockpit:
- “target” led indicates if the target node is in camera frustum
- “mesh” led indicates if the original mesh is in camera frustum
- yellow dot on radar shows the target position
- orange dot shows the mesh position
- blue dot shows picked point
- cyan dot shows bounding sphere of picked mesh
Note, that during animation:
- the original mesh (orange dot) remains at original position and falls out of camera view frustum
- picking does not work on the animated mesh, but only when stopped/paused
- instead, picking works on an empty space where the plane used to be, or where animation was paused last time