Repro: Babylon.js Playground
There seems to be an issue reading vertex data from a Geometry
if it has been updated at any point with fewer vertices than any previous vertex data.
When querying for vertex data there is a constructor call to Float32Array
which tries to fetch a view into the underlying data buffer with the same length of the original vertex data’s size. However, our newly updated vertex data has a smaller size than our original, causing an error to be thrown from the Float32Array constructor.
The (bad) size that we’re trying to read is provided by the function caller to VertexBuffer.getFloatData
, in this case it is Geometry._totalVertices
.
The _totalVertices
field is automatically set when calling Geometry.setVerticesBuffer
with the VertexData.PositionKind
, which is in turn called by Geometry.setVerticesData
. However, this value is never updated when Vertex Data is updated through Geometry.updateVerticesData
. I guess one solution to this would be to update the field in the Geometry.updateVerticesData
function.
You could also argue that what the Geometry
class is asking of the VertexBuffer
is valid, as its actual GPU buffer still has the capacity of the original vertex data size (or the largest in the lifetime of the VertexBuffer
if you update multiple times). But it doesn’t work like this currently either, as the CPU-side buffer of the data is set to the user-given array when updating the VertexBuffer
which is smaller in this repro-case.
Unsure which way to fix is best!
Unfortunately I don’t have the time to set aside for a PR at the moment as I don’t have Babylon running locally currently, so any assistance would be greatly appreciated!
Thanks,
-Tore