This question is widely known, but unfortunately, I have been unable to find a satisfactory answer.
My Approach
I utilize three.js for showcasing 3D models generated from drone images (example here).
The Issue
I face difficulty rendering large models (1M vertices, 2M faces) as Chrome or WebGL crashes.
Attempted Solutions
I conducted tests using examples from Threejs.org to ensure it wasn't an issue with my code. These tests were carried out on a x64 Chrome with the --max_old_space_size=6144 flag.
- Importing model in .dae format using ColladaLoader results in the utilization of 2.5GB RAM and Chrome crashing due to insufficient memory.
- Importing model in .obj format with OBJLoader + MTLLoader consumes 2.8GB RAM leading to WebGL crash.
- I read numerous posts about Three.js and memory allocation, however, most focus on removing objects from the scene which is not applicable in this scenario.
Potential Resolutions
- .stl (binary) files are more compact, but lack texture support which makes them unsuitable for my use case.
- Using BinaryLoader with GeometryBuffer output requires converting .dae or .obj files to binary, a process I am unfamiliar with.
- Breaking down the model into multiple parts for incremental loading could be an option, although I haven't found any references supporting this approach.
Reproduction Steps
For coding, I refer to basic examples on Threejs.org. Regarding models:
- If experimenting with .dae files, you can access working and non-working examples in this folder.
- Similarly, if dealing with .obj files, check out samples in this folder.
Any suggestions on how to load the larger model? Thanks!
EDIT 1 :
To determine if the RAM overload occurs during or after the load, I attempted to set a breakpoint in the SuccessCallback without success. This suggests that the RAM overuse transpires before reaching the SuccessCallback.
I proceeded to delve into the ColladaLoader step by step to identify what's consuming excessive RAM. Here is the "callstack":
- myCollada.load()
- ColladaLoader.parse()
- Geometry.parse()
- Mesh.parse()
- Source.parse (triggered 3 times) = +400MB in RAM
- Vertices.parse = no increase in RAM
- Triangles.parse = +1500MB in RAM
- this.geometry3js.computeVertexNormals() = RAM exceeds 2600MB causing Chrome to crash
Are there any other tests I can perform to pinpoint the root cause of this problem? Thank you.