Partially update a vertexbuffer or split buffers into smaller parts

Hi all,

Is there a way to partially update a mesh vertex buffer or to split a vertex buffer into smaller ones? With mesh.updateVerticesData you have to pass the whole vertex buffer of any kind, even if you just need a few vertices to be changed.

With low vertex count meshes, this is done very fast and can be performed several times in a row without lagging, but when your meshes have a few thousands vertices, this is an issue for realtime performance in a particular project (that involves randomly moving a few vertices from a bigger mesh on each click or series of clicks).

I’ve tried to slice the whole mesh in smaller parts, and it gets better performance, but it will be better if there’s a solution that keeps the mesh as a whole and not split into pieces. That’s why I thought if there’s the possibility to update a small part of the whole buffer or if maybe is there a way to split the vertex buffer into smaller buffers (so you just need to update a smaller part).

Thanks!

This is actually supported :slight_smile:
You can get the vertexbuffer you want and be able to call:
https://doc.babylonjs.com/api/classes/babylon.vertexbuffer#updatedirectly

2 Likes

Thanks @Deltakosh for pointing me to the right direction. I’ve managed to set up a simple system with this but I’ve found an issue: as sson as I call updateDirectly, the buffer data is cleared and I can not continue using it (after calling mesh.updateVerticesData it’s filled again, but the whole point in my case was to not use that method and just partially update the buffer).
Here I’ve set up a playground with this issue with the color buffer (take a look at the console output and line 58 and 74):
https://playground.babylonjs.com/#37Z4FJ#1

Is there a workaround for this?

Thanks again for your support and keeping this awesome framework mantained :slight_smile:

getData is invalidated (this is the local copy and not the GPU copy) to save time.

We do not want to sync the local copy if you update the vertex buffer directly (as we assume this is done for perf reason)

But the GPU memory is updated and ready to be rendered

But also mesh.getVerticesData(BABYLON.VertexBuffer.ColorKind) returns null after updateDirectly.

So is it necessary to create again the color buffer for that mesh if you want to perform any new changes?

all the data are wiped as they are not synced anymore (Again, we don’t want to spend time on syncing things as maybe you are using one single big buffer for all your VBs)

So ideally you should get your own copy before updating the data in raw mode

Thanks! Then I’ve stored the data after the first call and I’m using it afterwards. The system works nicely now.

Fantastic and it is really fast now as well :slight_smile: