Question about bufferObject

Hi everyone,
I’m doing some inplements to combine sculptgl tools and vtk recently, and I noticed that the sculptgl has a way to deal with vbo, thatis it does not enlarge the size of the element array each time the elements changed, but do it with a computed number of size, in this case, when element array is expanding during a short time and had not reached the new limit, it just change the subarray and do not need to rebuild the buffer array.
I think I had once seen in forum or github or somewhere else that someone said the do not use the subarray(or bufferSubData) because it has performance issue, but I’m not sure of this.
I have quesiton of this because when changing the vertices and faces for a large model(e.g. 200000 verts or more) in vtk scene, it takes too much time to recreate the buffer object data array, which lead to a frame drop, but in sculpt scene it’s quite smooth.

Are you talking of VTK.js ?

You can pre-allocate arrays larger than necessary if needed.
When allocating your vtkDataArray, you can pass a “values” array larger than “size” .
e.g. vtkDataArray.newInstance({values: new UInt8Array(10000), size:10}). Inserting next tuples won’t reallocate array until size === 10000.

Hi Julien,

Yes, it is vtk.js, forgive me for stating it clearly.

I need to change the points/faces/normals of the polyData each time mesh changed, so I did


because it could be a decrease or an increase for the mesh vertices and faces and the new points/faces/normals are calculated outside vtk.

Take points as example, when initial value is a typedArray with length of 600, once the sculpt is finished, it could be enlarged to a length of 1200 one, but the available length is 690(expand 30 vertices).

How should I refresh the data by just change the element array and not trigger the createVBO event, the time to buildBufferObjects takes about 4 times of the time to change the mesh array(sculptStroke function), it’s like this:

If there is no available ways I will consider to add extra params to limit the element array used by the shader, which is used in sculpt rendering.

Indeed, createVBO() is time consuming. There is not much you can do about it. (you could consider caching packedVBO but that would be very specific to your usecase).

1 Like

Hi Julien,
Thank you for the reply, I’ve just finished the work by reducing some calculations for the packedVBO, it is indeed very specific. Do you have any plans to add those kinds of tools(mesh edit) to VTK?

Glad you made it work.
There is no such identified effort at short or mid term.
If you have identified a generic VBO caching mechanism (e.g. mesh editing does not change the number of points nor the connectiviy) that avoids recomputing the whole VBO each time, but only a subset, I guess that could be contributed into VTK.js master.