Is it possible to batch skinned / animated characters in PlayCanvas?

Does PlayCanvas have a way to use batching to speed up drawing of multiple instances of the same animated character?

Here’s an online link showing different speed results, showing the same skinned model duplicated and with batching applied ( click to cycle through the three scenes )…

https://playcanv.as/e/p/I6b0DCvc/ ( the /e is added, as there is still an issue with the iOS public link )

The original project is here, feel free to fork and try to get a batch-based speed-up.

https://playcanvas.com/project/604336/overview/skinned-batching-test

Hopefully this is something that is already supported, or that is on the road-map.

If I get some time, I’m going to try to create the same scenario using other WebGL technologies ( BabylonJS, FlareJS ). If anyone else has experience with other technologies and wants to try the same, you can download the FBX model from the project above ( the characters are placed in a 10 x 20 grid )

Best regards…
Mal

Sorry, haven’t got much into Playcanvas for the time being, but hmm…

By default, Playcanvas doesn’t support skinned animation batching. If you place them in a batch group, all animations will cease to work. I had to run a hackish code replacement (that isn’t guarenteed to be future proof but as of now it’s working though) in existing projects to get my animated skin batching to work. There were also some considerable issues with regards to the nature of bounding boxes (eg. should it be combined + updated per frame or not???, etc.) for the built-in playcanvas culling visibility checks which meant things became slightly project specific in terms of how conventions go.

Go to the project at (with regards to the above described consideration):
https://playcanvas.com/project/571469/overview/skinbounds-batching-testings

Look for the script /script/modpc.js . Include this script as the first script in order to modify hack the Playcanvas batching engine to support skinned animations. If you have a bunch of animated character entities, they should all be batched and be able to support independant animations.

Anyway, the fork with the working animated batched can be found at:

https://playcanvas.com/project/606147/overview/skinned-batching-test

To further optimise this, you may wish to avoid the per frame overhead of updating/combining of individual bounding boxes of each animated character by setting the first reference character entity’s meshInstances cull property meshInstance.cull = false; meshInstance.visible = true to skip updating of certain things for culling checks for the batch. However, if you do this, you sacrifice the built-in camera culling functions and it’s assumed all animated model batches will always attempt to render itself even if camera isn’t facing them, without having to refer to any updated boudning box (of the combined animated skinned meshes). However, doing this by code is rather inconvenient and will not work unless you also manually set up your batches by code as well (only after setting the first reference meshInstance.cull = false, then batching the list of meshInstances manually on your own). Otherwise, you’ve got to go and find the batch (after creation) and update it yourself…to use batch’s meshInstance.cull = false… Bleh… I REALLY wish the Playcanvas editor had ways to modify the .cull properties within the editor itself for batch groups and entities…but alas…no such way of doing so.

In terms of framerate, they can be kinda similar unless you zoom out the camera to view ALL meshInstances, for that the batching always benefits for framerate since with batching all models are combined into 1 single instance unlike the other case where some models may get culled away. ie., without batching , you get the benefit of the built-in culling of individual models’ meshInstances which can help reduce overall polycount which may be good on “some” videocards.

4 Likes

I have been looking at this for a while now and I have @Glenn_Ko solution up and running as well
However - I am not seeing any changes in drawcalls. As matter of fact for each new cloned character 2 drawcalls are added. I am checking the drawcalls in the profiler.

Shouldn’t I see a consistent amount of drawcalls?

-Pieter

If you newly spawn new cloned character, you’d need to re-batch from what i remembered (i think), purely by code. This is because the newly cloned character doesn’t belong to the previously pre-generated batch group in the scene setup in the editor.

For that demo project Mal Duffin did it seems that if you click on the screen, it’ll switch to different scenes (one of it is skinned batching…).

If you are doing a lot of dynamic removal/addition of variable number of cloned characters and don’t want to incur re-batching performance costs assosiated with that, the current batching system isn’t entirely ideal unless you adopt a kind of matrix palette skinning approach alongside with batching like here: https://playcanvas.com/project/574049/overview/lodbvhbatched-spawnings-wip (I actually call it repeaters, rather than batches…)