Animations outside frumstrum

Hi, some time ago i testes animation perfomance in my game. During debug that i saw problem with many animations of enemies outside frumstrum. What that mean? That mean… When i play animation and mesh is not visible engine still animate it. Is excepted behavior?

Now i checking it like that:

setInterval(function() {
let activeEnemies = 0;
game.enemies.forEach(function(enemy) {
if(enemy.isDeath) {
return;
}

            let isActiveMesh = gameCamera.isInFrustum(enemy.mesh);
            if(isActiveMesh) {
                activeEnemies = 1;
            }

            if(!enemy.animation && isActiveMesh) {
                enemy.runAnimationStand();
            } else if(enemy.animation && !isActiveMesh) {
                enemy.animation.stop();
                enemy.animation = null;
            }
        });
    }, 1000);

Tom

1 Like

This is expected because else you may miss some animation steps. Plus what if the animation brings the mesh back to the screen?
If you want to stop that behavior you can add a function in the scene.registerAfterRender and stop animations on all meshes which are not in scene.activeMeshes

1 Like

I create cache in my game object, which store all enemies. I want to avoid scan all meshes in scene to optimize that process. After render function will be faster then interval?

I just start animation from the beginning, when mesh is visible.

So OK, stay with actual optimization :).

1 Like

So cool. Like this concept very much. :black_heart:

Optimization: optionally, start enemy animation once in frustum.

:musical_score:

:+1:

Also, great to consider… animation steps may be skipped. So concept of PAUSE… interesting. :grin:

Into and out of the anm sequence when in the frustum~zone (alarm).

Cool concept. :slight_smile:

You can also leverage the AssetContainer as it is dedicated to store data in the scene ?
https://doc.babylonjs.com/how_to/how_to_use_assetcontainer

1 Like