Pipeline Overview
The geometry generation follows this flow:User changes bin config
User modifies parameters like dimensions, wall thickness, dividers, or features via the UI
Web Worker receives config
Updated configuration is posted to
manifoldWorker.ts as a serializable messageManifold WASM generates CSG mesh
Worker thread executes Constructive Solid Geometry operations to build the mesh
Mesh transferred back to main thread
Vertex positions and triangle indices are sent back using Transferable Objects (zero-copy)
Converted to Three.js BufferGeometry
Mesh data is wrapped in Three.js geometry format and added to the scene
Worker Communication Protocol
The main thread and worker communicate via structured messages. Here’s the interface frommanifoldWorker.ts:33-38:
Request Types
preview: Generates simplified geometry for real-time viewport display (flat base, no detailed Z-profile)export: Generates full-fidelity geometry with accurate Gridfinity base profile for 3D printing
Request Management
TheuseManifoldWorker.ts hook provides request queuing and caching:
useManifoldWorker.ts:41-60
Caching Strategy
Request Cancellation
For interactive editing, outdated requests are cancelled to avoid race conditions (useManifoldWorker.ts:78-80):
Mesh Extraction
The worker extracts raw vertex and index data from Manifold’s internal mesh format (manifoldWorker.ts:15-31):
Transferable Objects
Mesh buffers are transferred using the Transferable Objects API for zero-copy performance (manifoldWorker.ts:50-53):
ArrayBuffer underlying each TypedArray is transferred to the main thread without copying, drastically improving performance for large meshes.
Preview vs Export Geometry
Two geometry generation functions exist inbinGeometry.ts:
| Function | Purpose | Base Detail | Use Case |
|---|---|---|---|
generateBinPreview | Real-time viewport | Flat slab (0→4.75mm) | Interactive editing |
generateBinExport | 3MF file output | Full 5-layer Z-profile | 3D printing |
Error Handling
If geometry generation fails, the worker posts an error message back to the main thread (manifoldWorker.ts:54-59):
useManifoldWorker hook resolves promises with errors, allowing components to gracefully handle failures.