I have a scene that has potentially a few million thin instanced cubes used to render a model. After the meshes are loaded I have a large memory footprint from all of the position matrices. Is there a way to clear out all the position matrices from the thin instance meshes since the position will no longer be updated?
Hi, after you set the buffer you can add those 2 lines
mesh.thinInstanceSetBuffer('matrix', matrixBuffer);
// add
mesh.doNotSyncBoundingInfo = true;
mesh.thinInstanceRefreshBoundingInfo(false);
I’ll give this a go and report back, have a few items I am addressing along with this.
You can do:
mesh._thinInstanceDataStorage.matrixData = null;
mesh._thinInstanceDataStorage.matrixBuffer._data = null;
mesh._thinInstanceDataStorage.matrixBufferSize = 0;
to get rid of all CPU memory related to matrices.
Note, however, that picking and automatic recovery from a context lost won’t work anymore.
Thanks for your help guys! With these recommendations and a few tweaks throughout the code base I was able to cut back the memory usage quite a bit and boost performance.
This is a rewrite of a library I wrote a few years back. Taking advantage of Web Workers, Offscreen Canvas, and writing custom shaders. This is one of the larger samples I test with. It ends up a little over 7 million thin instances of a a cube.
As far as picking goes I used the approach provided in this post GPU picking demo and have had great performance/success with it.