I’m creating meshes with Float32Array vertices data.
Many of those vertices data are no longer used once copied by Babylon.js to the GPU via native WebGL bufferData.
Is there a way to explicitly remove reference to the vertice data kinds of my choice? I don’t need tangent, normals, etc… anymore. But maybe want to keep position (in order to keep the Babylon.js click event working).
Note that I’m never copying, cloning meshes and I’m not making use of
Let me add @ryantrem to the thread as he did something really similar recently for some meshes but I can not remember the function name ?
The only thing I can think of that I did recently that was similar to this was about releasing all the geometry data from main memory after it is loaded into graphics memory. In my case, given a
rootNode for a loaded glb, I had something like this:
(rootNode.getChildMeshes(false, (mesh): mesh is BABYLON.Mesh => mesh instanceof BABYLON.Mesh)).forEach(mesh => mesh.geometry.clearCachedData());
But this would also break picking, which it sounds like @yvele is trying to maintain, hence the idea of only clearing the data for certain vertex attributes (e.g. everything except positions, and maybe normals if they are used to determine the normal of the raycast hit).
For that though, I think you could just call
mesh.geometry.removeVerticesData instead to remove only the attributes you’re sure you don’t need (for things like picking). @sebavan do you think this would work?
@yvele - since it seems like you are concerned about the footprint in main memory, can you share a little more detail about the meshes you are creating? What vertex attributes do they have?
So I can do:
That looks OK for me
But, I know that on Apple devices GPU memory and RAM are shared… does
this._vertexBuffers[kind].dispose(); also dispose memory in GPU? (I don’t think so but just to make sure…).
VertexBuffer.dispose really do?
since it seems like you are concerned about the footprint in main memory, can you share a little more detail about the meshes you are creating? What vertex attributes do they have?
I have indices, positions, normals, tangents, uvs and custom attributes as well.
This releases the webgl memory associated with it, and you will not be able to draw it anymore
I still need the render loop to draw the geometry.
this is exactly what the clearCachedData does.
One issue might also be mesh.getTotalVertices() calls. Think this is is called by inspector, so might no be a could idea during development. Save for deployment.
Ok cool thank you! So the render loop will still work.
Oh ok. I’m not using the inspector I’m only using Spector.js but I think Spector.js is 3D engine anemic anyway (and then doesn’t rely on Babylon.js internal structure)
@sebavan @JCPalmer I have a related question… Does clearing the cached vertice data prevent Babylon.js from recovering from WebGL context lost?
As the documentation says: Babylon.js “keeps track of resources creation” does that mean that Babylon.js recovers from geometry cached data (the one that I’m clearing)?
Yup this will need to be handled on your side in this case