I was playing around with getting a group cloned/instanced meshes to play their animations separately, and in general trying to see if one approach works better than another in terms of performance. Are there any other tricks I could be using to squeeze out even more performance (fps, lower memory usage) in either case of using clones vs instances?
This is definitely useful for exploring the curve of n-entities vs fps for both instances and clones as you scale up the number of entities with animations playing.
Note that by default instantiateModelsToScene will always clone meshes if they have a skeleton, even if you set doNotInstantiate = false. If you want to force instanciation in this case, you should pass () => false for doNotInstantiate.
However, doing so will prevent you to use a different animation for each instance: all instances of a mesh share the same animation.
Since 5.0, we added Baked Texture Animation, if that can help:
That’s super interesting to learn. So it sounds like in the playground I set up, those birds are always cloned? Yet I thought I had seen a consistent difference in the fps as measured by the babylonjs inspector.
I tried it out as you said, opts = { doNotInstantiate: () => false } and observed all of the instances animations play as one.
A limitation of the current VAT implementation is that you cannot blend animations to play simultaneously. Also, the animations may not be as smooth as when not using BVA because there is no interpolation between frames. The “smoothness” will depend on the number of frames of the animation.
So it sounds like if I wanted to do a large flock of birds in the distance this could work but otherwise is too rigid to work in a game setting where birds close to the player need to be able dynamically stop and go… is it possible to use both baked animations and regular animations on the same model/instance?
I think it should be possible, but not at the same time, as there’s a BakedVertexAnimationManager property on the mesh that you can disable by doing mesh.bakedVertexAnimationManager.isEnabled = false.
Wow, if that’s the case, that makes some really cool stuff possible. Say for example we have a flock of ducks, animated as flying and moving forward on a given axis at 3m/s:
If the game allowed it, the player could click at random any duck in the flock, and that particular duck instance could then be switched over from a baked animation, to the regular more dynamic animation system and do something to display different behavior from the flock?
Finishing up some code, and there’s a thread I need to respond on first, but very soon I think I can set up a cool pg to demo it. I’ll also have to learn about baking animations first, but that looks easy enough
WebGPU will change the game completely
drawcalls will no longer be such a huge limitation it is today,
and you’ll be able to just have 100’s of clones playing separate animations
I remember seeing @Deltakosh showing this in a video once,
this version was just what i found from a quick google
i believe it’s 10000 static clones in each scene.
I wish it could be validated already… Trying to run my example from the other thread gives bazillion errors in google chrome canary with webgpu turned on
There is additional requirement at least in my case, since I need some specific trickery with lighting as well and that sorcery only works with clones…
Hypothetically would it make sense to have bone calculations done in a wasm module and it would just write the results to a shared buffer array that babylon.js would internally reading from?