Does Batching work with Skin model Animations?

When i assign a Skin model to a Batch Group, it seems it’s playback animations no longer work. Is this expected? Does Batching work with Skin model animations? (ie. allowing all skin models within the same batch to also have independant frame, bone transforms, etc.)

I’d be interested in hearing what the current status is for skinned batching, what future plans are, if there are any known optimisations etc.

I made some modifications to the pc.BatchManager.create and pc.BatchManager.prepare methods to provide support for getting skinned model animations to work. . and you can see the modifications of the methods works here if you play it under EDITOR > Ships/batched animations: https://playcanvas.com/project/556581 after some patch hacks under scripts/3rd/modpc.js. Yes, the ships are swaying back and forth via the Animation component! And the soldiers are dancing. And yes, they are all running on different animation components so each skin in the batch can be indepedantly animated.


Each soldier is 24 bones. (Yes, this could be optimized for lower LOD animations, i feel…as i think that won’t batch too well on mobile), but they appear to be all 1 batched draw call on desktop. Each ship is 1 bone each, all batched to 2 draw calls (note, i didn’t set the 2-ship parts to use same material …if i did, it would be 1 draw call). And some of those green billboards with custom shader (about 1 to 4 draw calls batched on desktop)…

THe mod should work with skinned meshes with multiple bones as well (like the soldiers) with vertices binded to mulitple bones but note that you can’t exceed the bone limit requirements per batch group (i haven’t tested the code thoroughly yet under pc.BatchManager.prepare to ensure the batches are prepared according to those limits). But yes, SKinned model animations should be possible with Batched animations.

Code changes on my github fork.

My future plan is to also adopt a simplified clone-repeater version of pc.BatchManager like BatchRepeater or something, that doesn’t have to rely on batching pre-exising entities on the scene (ie. just supply 1 model or single entity to clone…), and to also support varying number of active/inactive clones within the BatchRepeater per frame with little performance overhead. That should be more useful for dynamically spawning/unspawning bullets/decals and such…

BatchRepeaters are potentially more memory effecient especially for low end devices like mobiles. For example, if you buffer 1024 similar mesh instances (ie. let’s say this is based off device’s max instance/vertex limits ), or less if you wish, but have 2000 similar mesh instances to be rendered beyond what the buffer provides…it’ll reuse the same buffer of 1024 similar mesh instances, with first draw call using amount of triangles of 1024 instances (offset=0, count=1024), and second draw call using amount of triangles comprising of 976 (ie. 2000 - 1024) instances (offset=0, count=976)! So, it just clamps the amount of triangles to be drawn per batch draw call but re-uses the same vertex batch buffer with a different set of uniforms. Unlike pc.BatchManager, you can have as much batched clones as you like at no further VRAM vertex memory increase beyond what you’ve allocated in the buffer. (and you don’t have to pre-flood your Playcanvas scenes with redundant entities!) So, it’s a bit more like a particle-emitter of some sorts, with independantly transformed meshes/skins.

3 Likes

@will @daredevildave It would be very cool to apply these changes to the official engine repository. Skinned meshes batching is a must, and this guy already made the work!

Need to update/clean up the sync update though. ANd would need testing. Batching.js had quite a lot since then for UI and i would need to re-integrate my feature to the core fixes/update they did to that as well (stencil and such). ~As it stands now, it doesnt work with the latest batching.js~

okay, updated it as a new pull request. https://github.com/playcanvas/engine/pull/1618

Thank you for the work Glenn!

I’m gonna just leave this here for my lead developer:

Oog. Just noticed the dates…

Anyone aware if this has been resolved in the production engine code?

Hi @Spencer_Lindsay,

No batching for skinned models is still not supported as far as I know. This is definitely something useful to have, if you’d like add a feature request on the engine repo about it:

Edit: There is an open PR that is related, it may be something on the roadmap already, any idea @yaustar @mvaligursky ?

It’s not on the roadmap as it has limited use - it could only batch skinned models using the same material. It would be useful in some cases, but is not a priority at the moment.

1 Like

Oh I know some people that would start working in a battle royal HTML5 game as soon as that is supported :innocent:

Even with same model/material it’s still useful to be able to have skinned models running around in a single draw call.

6 Likes

Thank you both for the quick response. I think we’ll just attach all the material-similar submeshes for now. That seems to work well. Maybe an UberMaterial down the road if needed.

3 Likes