BatchNode best practice question


I got a 3-D Warehouse overview with about 10k shelfs with up to as many pallets on them, and well performance was horrible of course. So I read up on what to do and figured BatchNode was the way to go, problem is each shelf and each pallet can be selected in my application and it will be colored in a different color. Generally color can change for many different reasons.

Now here is my problem, I cant just simply change the color of the material of an Object when its in a Batchnode without setting the Material anew. I tried and nothing happened. And when the Object is still batched I get an exception. So if I remove the Object from the BatchNode, change the Material , and then add it again without batching it works but it looks like z-fighting as the old color and new color appear depending on camera angle and position. However if I batch it after selection, it goes trough all the objects twice (1x for deselecting old object, 1x for selecting new one) and my application freezes for half a minute.

What is the best approach to solve this? I know the guide says its best to only batch static objects, but ALL my objects are non-static as they are selectable and there is up to 20k or more.

I read that 1 BatchNode = 1 Geometry = 1 Mesh = 1 Material, so should I make a separate BatchNode for every possible texture+mesh+color combination and make the Object travel between the according Batchnodes? I am not sure that would help either as when I deselect an Objcet it would be readded to the big BatchNode with all the objects with no special color so performance would be crap again when batching it.

Texture or mesh doesnt change on the fly, only color. Atleast for now :grin:

Maybe splitting your thing into “chunks” and only loading a few that are visible is the way to go?

1 Like

For colors… look at setting the colors on the mesh.

I cant as ALL of them are in view when the user zooms out into the overview where he sees the entire warehouse, which is a wanted feature.

To elaborate on paul’s approach. It can be tedious working out little things like this. Butcher as appropriate.

    // cannot be static because we modify the mesh
    public void setVertexColor(Mesh mesh, ColorRGBA color) {
        ColorRGBA[] colors = new ColorRGBA[mesh.getVertexCount()];
        Arrays.fill(colors, color);

        mesh.setBuffer(VertexBuffer.Type.Color, 4, BufferUtils.createFloatBuffer(colors));

Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setBoolean("VertexColor", true);

You will essentially be mimicking ye olde “html imagemaps” of sorts for picking.

When it does, like what @Robbi_Blechdose said. You can have one or few nearby shelves as one batch node, nearby because of culling. That decreases the computation when re-batching the node after some select/delect etc. That’ll decrease the object count and still allow you to change the batchnodes without noticeable performance issues.

I do that in the new skeletonDebugger
I just edit the color buffer of the global mesh but just for the selected geometry indices.

There are billboards/impostors which can support color attributes.
For more information, see this thread.

1 Like