BatchNode rebatch feature?

I have played around with this feature for awhile now and I cannot figure out a way to “rebatch” the BatchNode (or update the batched geometry when a child is attached/detached). The work around I have found is to create a Node that holds the actual children and create a new BatchNode with the data Node attached and then run batch(). This has the downside of using multiple nodes for the same data and is honestly just plain annoying that it has to be worked around at all! Am I just missing a simple way to run batch() more than once without getting a IndexOutOfBoundsException? If I’m not missing something and there really is no way to update a BatchNode when the child tree is updated than why? Is someone able to add this ability in because I haven’t found a way. Thanks!

You probably try to add a mesh with a different buffer count (e.g. a lit model that has a tangent buffer)

well basically I’m dealing with a chunk of 16x16x16 blocks and I’m using the BatchNode to simplify the meshes to draw the chunks quicker. When I click on a ‘block’ i generate the name and detach the geometry but then it obviously doesn’t update as it is batched but if I try to run the batch() again it has an IndexOutOfBoundsException which I read was because it resets some variable in the BatchNode. Would your solution work well for this and if so can you expound at all? I haven’t done much with meshes, just the default geometry.

a) I think I remember hearing that there is a bug in batch node when batch() is called more than once per update.

b) if this is for a block world, this is the least efficient way to deal with a “chunk” and the maximum world size you can support is like 1/8th or 1/10th (or worse) what you would be capable of by making your own custom mesh.

@pspeed said: a) I think I remember hearing that there is a bug in batch node when batch() is called more than once per update.

b) if this is for a block world, this is the least efficient way to deal with a “chunk” and the maximum world size you can support is like 1/8th or 1/10th (or worse) what you would be capable of by making your own custom mesh.

Stilll you can do quite large worls already with this, in tests 2kx2k visible was possible without problems. (though i suggest larger batches to keep object count lower, and optimize by removing batches that cannot be visible)

so there is a bug in the BatchNode and I should write my own mesh creator from the data, is that right? Or is there a better way to work around the bug from what I’ve started doing because I’m not sure how I would do all the textures on the mesh generated :confused: I’m still kinda new at this area of programming, trying to wrap my head around all of it :smiley:

@Empire Phoenix said: Stilll you can do quite large worls already with this, in tests 2kx2k visible was possible without problems. (though i suggest larger batches to keep object count lower, and optimize by removing batches that cannot be visible)

I guess it’s really only a little over twice the memory. 2.2 or something… but that’s per visible quad (presuming only visible quads are drawn) and not per block. Presuming you are already keeping the cell data somehow that’s potentially a lot of unneeded overhead when it’s not that hard to go straight from cells to mesh.

To the OP, I was not making a specific suggestion just pointing out what I’ve heard. If you call batch() more than once per update then try not doing that anymore. Set a dirty flag when you add/remove quads and then batch only when dirty or something. I have zero familiarity with how BatchNode is used in practice.

well apparently the bug in the node is that there is a variable that holds the max vertex count (or something similar, i read that a few hours ago and lost the link) and whenever the batch function is run it resets that and causes a Out of bounds exception. I tried to see if there was a way of clearing out the batched data but I couldn’t really wrap my head around the code. the data I have is a 3D array with a texture ID and a position as a Vector3i (made that for block position as I didn’t need as much precision) so would it be easier to just create a mesh by going through that data? It seems like that would take MORE time per chunk update as it has to rebuild the texture it’s using for the material as well as go through each block to create a custom mesh. I really am clueless though so I may be totally off base here

I don’t know. It sounds different than every other block world I’ve seen. Not sure why you would have a 3D array of IDs and positions… since wouldn’t the 3D array already be providing position?

At any rate, somehow you go from “world data” → quads → Geometry → BatchNode.

I think the process of going from “world data” → batched quads → Geometry is not that different calculation-wise… but you aren’t storing the mesh data twice.

I simplified it, I have a 3D array of a Block type which HAS a block Id and position attached to it. The Block type has subtypes (dirt, light, grass, etc) and there is an updateGeo function which is called and overriden in subtypes if the Geometry is different from a standard block (such as a switch or door). I have the position variable in the block type so that I can have functions within the block types that update other blocks near them by going through the parent chunk (similar to the setBlockwithNotify() in Minecraft) so the way I have been doing this so far is I have been using the BatchNode at the Chunk level and taking the BlockId of each block in the array, fetching the pre computed geometry (which is held in a static Geometry array in the Block super type) and adding it to the BatchNode. This increased my frame rate ALOT obviously as it simplified like objects but when i remove a child of the BatchNode I need a way to update the batched geometry or this whole thing is kinda pointless. Is the BatchNode only meant for static use? It seems like a dynamic BatchNode would be pretty usefull.

So you add whole blocks? Even if only one of the sides is visible? Or is your prebuilt geometry already broken down into faces or something?

For what it’s worth, it seems a little wasteful to store a position in every cell just so you can find neighbors. How did the cell get updated in the first place? Seems like you would have known its position already.

I assume you are sharing the meshes and cloning the geometry before adding them to the batch node? Since a geometry can only have one parent at a time and so on.

There IS a bug in BatchNode when you remove spatials. I’m looking into this now. Still trying to finish the test case that narrows down the issue so Lord @nehon can use his magic touch and zap it away =)

1 Like

Just found it on monday =)
I has to do when you have children on the batch node that are several nodes deep. They don’t detach properly causing the buffer size to be out of sync.

omg I’m a lord now…
I’ll fix it asap.

sweet so I wasn’t crazy lol thanks guys! Can’t wait for the fix :smiley:

I will post some of my issues I am seeing here @nehon

I just encountered some weird offsets when batching some meshes:
unbatched:

batched:

If a mesh is added to the batchNode and it does not have tangents generated, but the rest of the meshes do, then a BufferUnderflowException happens. Not a big deal, the meshes should have had their tangents in the first place.

more to come =)

Seems like the BatchNode could use some unit tests…

Monkeys are unit tests :smiley:

I fixed the IndexOutOfBoundsException issue in last SVN

I can’t seem to find the BatchNode code on the svn… (just having a navigational issue) do you have a link handy to the updated version?