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.
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.
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.
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.
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:
Either split your FBX to smaller models, if that’s possible.
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.