How do I assign fbx sub meshes to a batch group

Hello,

I have a fbx model in my scene and I search for sub meshes by name in order to assign them to a batch group.
I’m struggeling with the batchManager. How would I assign the nodes to a batch group? I can’t find any examples, only for using the editor but not at runtime.

Thanks!
Stefan

Hi @SteOberg and welcome,

So, the batch manager will automatically assign your mesh instances (sub meshes) to a batch group when it runs (or when you manually re-trigger it).

For that you need to:

  1. Create the batch groups in your project settings

image

  1. Assign those batch groups to your models, on each entity model component.

image

Here is the relevant manual page on batching:

https://developer.playcanvas.com/en/user-manual/optimization/batching/

Hi @Leonidas and thanks for the quick reply!
I saw the batching docs already and I set up batch groups in the editor. I just have problems assigning the sub meshes to these batch groups, because there is no way of accessing the meshes in the editor right (it’s not the main fbx, they are sub meshes of the fbx)? So I have to do it at runtime.
I find the graph nodes by name but I don’t know how to assign them to the batch group.

Hello, @SteOberg, and welcome to Playcanvas :slight_smile:

You can get an example of runtime batching here:
https://playcanvas.github.io/#graphics/batching-dynamic.html

2 Likes

I could guide you with a code example on how to add mesh instances directly to the batcher, but that is quite advanced and not the official way of doing this.

I assume on runtime you load your models and add model components. The example @LeXXik posted is great to showcase how to add those model components (that include all of your sub-meshes / mesh instances) to batch groups, fully in code.

1 Like

Thank you guys. This helps already. But still I can’t find a way to assign the batch groups.

I have a fbx e.g. like this:

root
|___object
------|___object
------------|___object
------------------|___cube1
------------------|___cube2
------------------|___cube3
------------|___object
------------------|___cube4
------------------|___cube5

Now I want to assign batch groups to all the cubes. I find the graph nodes by searching for the names. But I don’t find a way to assign model components to the cubes. Is that possible? There seems to be no reference from the graph nodes back to the mesh instances.

Thanks!

Hi @SteOberg,

So assigning different batch groups for the same model isn’t currently supported, neither in editor nor with the public API in code.

That doesn’t mean batching won’t work, it will work quite ok by assigning the same batch group to your top model component (the one used to render this mesh hierarchy). The Playcanvas batcher will automatically split your model to pc.Batch instances belonging on the same batch group. That means all pc.Batch instances will be either static or dynamic and will share the same AABB.

If you would still like to add each mesh instance to a different batch group, I see two ways:

  1. Either split your FBX to smaller models, if that’s possible.
  2. Or study the pc.Batcher class to see how it searches and groups the mesh instances of each model component. You can create your own method that does that and calls the internal (private) methods of the pc.Batcher instance (this.app.batcher) to do that.
2 Likes

@Leonidas thanks so much. It was indeed enough to assign the main model to a batch group. Reduced the draw calls to 1/4. Awesome support!

1 Like