I decided not to use highlight layer because of the instancedMesh. I am trying to highlight by drawing a new lines mesh around the object and enabling edges rendering.
But for the optimization.
As users are uploading arbitrary gltfs my options are:
0. leave it to the users to optimize them, which they may or may not do.
- try to optimize them on the server with some python gltf library,
- try to optimize them in browser and then save the optimized copy to be delivered to the next clients.
Ideally I would prefer to have one code base, and since I already have a viewer in the browser, probably I could do the optimization in the browser.
A threaded bolt is a repeating pattern. Each cycle repeats for about 20 times. And each cycle could consists of hundreds of thousands of vertexes. Even millions. Who needs this level of detail - nobody. But content creators often lack the tools to optimize the gltfs or have legacy project which when converted to gltf produce this results. We all agree they should be removed, but they should not be removed by hand, but rather automatically.
Theoretically I could have a few vertexes that describe 1 degree of the cycle and this could be repeated 360 times. Given that there are about 40-50 bolts on the scene if I have 1 mesh for the 1 degree of the cycle of the threaded bolt and InstancedMesh for the other 359 than it is ‘20x360x50 times optimized’
How exactly am I going to find the pattern I still don’t know, but I can handle the math. What I probably need in this case from a GLTF.Loader is to get the opportunity to run a check on a ‘raw geometry node’, before it is created as a mesh and decided if this ‘raw geometry node’ should be in one large mesh, or one mesh and a lot of instancedmesh. In this way when there is a 20MB node to be loaded that is a threaded bolt I could load only one degree mesh in the memory and hundreds of thousands of instancedmesh that are offset by position and rotation. This, as far as I understood Babylon InstancedMesh in the last two days should take a lot less memory and should render a lot faster.
While writing this I was looking at GLTFLoader - Babylon.js Documentation. And also at Use the glTF File Loader Plugin - Babylon.js Documentation
I think the onMeshLoaded could do be used for this. Load the whole Mesh and then create many InstancedMeshes and dispose of the unneeded Mesh. Would this work?
The last scene I received contained about 40 bolts and was about 700 MB.