I’m using rhino3dm.js (the JavaScript/WebAssembly build of openNURBS) in a browser-based 3D viewer to export large meshes to .3dm. I’m hitting the 32-bit WebAssembly linear memory ceiling (~2 GB addressable, ~4 GB hard cap) when serializing large models.
Concrete repro:
Input: ~28.6M vertices / 9.5M triangles across 54 meshes (single file → GLB ~670 MB on disk).
Payload handed to the worker: ~327 MB of Float32Array vertex positions (normals stripped, Rhino recomputes them).
Pipeline: meshes are pre-merged on the JS side, then for each group I call new rhino.Mesh(), mesh.vertices().add(…), mesh.faces().addFace(…), mesh.compact(), mesh.normals().computeNormals(), append to File3dm, then doc.toByteArray().
Result: after roughly 20–25 groups, verts.add() starts silently failing (vertex count stops incrementing), and the final doc.toByteArray() triggers Aborted(). Build with -sASSERTIONS for more info. — the classic Emscripten OOM abort when the WASM heap can’t grow further.
Tested on rhino3dm@8.4.0 and @7.15.0 , Chromium-based browser, dedicated Web Worker, INITIAL_MEMORY left at default and ALLOW_MEMORY_GROWTH implicitly on. Same outcome.
What I’d like to ask:
Are there plans to publish a WASM64 / -sMEMORY64=1 build of rhino3dm.js so the linear memory can exceed the 4 GB cap on browsers that support the memory64 proposal (Chrome/Edge behind a flag today, shipping more broadly soon)?
If not, would it be possible to expose a bulk/typed-array vertex and face ingestion API (e.g. mesh.vertices().setFromFloat32Array(buffer) / mesh.faces().setFromUint32Array(buffer)) to avoid the per-vertex/per-face JS↔WASM call overhead and the intermediate allocations that inflate heap usage?
Any recommended EMSCRIPTEN_* build flags or Module instantiation options (e.g. higher INITIAL_MEMORY, MAXIMUM_MEMORY=4GB) you’d suggest in the meantime?
For now my workaround is to fall back to glTF/GLB export for models above ~15M vertices, but native .3dm output is what I actually want.
WASM64 is now generally supported across Node and most major browsers. Unfortunately Safari still does not support wasm64, so I kept wasm32 as the default package. I might change this in a subsequent release of rhino3dm.js.
OK, after a lot of testing, iterating and bug tracking, with the help of AI, it appears there still is a 2GB limit on the WASM64. Here is the response I got:
Found it — and it’s conclusive. Answer is (a): a hard ceiling baked into the compiled .wasm.
Evidence 1 — the wasm memory section (decoded the binaries directly):
The wasm64 build is 64-bit addressing but is still linked with MAXIMUM_MEMORY=2GB. memory.grow past that fails at the engine level — nothing on our side can lift it.
Evidence 2 — the glue confirms it. emscripten_resize_heap in the wasm64 module still has the wasm32 clamp verbatim:
Any allocation request above 2 GiB returns false immediately, so malloc returns null.
Evidence 3 — why our probes were all -1/null. The minified module keeps HEAPU8/wasmMemory as closure locals; they are not exported on the Module object (_malloc is, but returned null — consistent with the growth failure path). So heapLen: -1 was our probe being blind, not a detached heap. Not (b), not evidence for (c).
What actually happens at 128 MB output: the archive writer’s buffer allocation crosses the 2 GB wall, malloc returns null, and rhino3dm’s toByteArray still reports the computed archive length — hence a correctly-sized, freshly-allocated (byteOffset: 0, bufLen === len, sameBuffer: false) but zero-filled array. It’s a silent OOM, not a stale view.
So there is no app-side workaround at this model size right now.
Thank you! It now works and I was able to write out a 254MB Rhino file with meshes. Total memory use for the worker was 2.6GB. I will test it out on larger models too.
I really appreciate the work you put in and that you handled this so fast.