System Architecture
The architecture consists of three primary layers:Data Flow
- User Input → TypeScript wrapper classes (Line, Cuboid, etc.)
- TypeScript → WASM function calls via
wasm-bindgen - Rust Core → Geometric computations, BREP construction
- WASM Output → Serialized geometry data (JSON/typed arrays)
- TypeScript → Three.js mesh rendering
Module Structure
The Rust core is organized into focused modules as defined insrc/lib.rs:
Core Modules
primitivesarc- Circular arc segmentscuboid- Box primitivescurve- Parametric curvescylinder- Cylindrical solidsline- Line segmentspolygon- N-sided planar polygonspolyline- Connected line segmentsrectangle- Rectangular facessphere- Spherical solidssweep- Swept surfaceswedge- Wedge/prism solids
extrude- Extrude 2D profiles into 3D solidsoffset- Offset curves and facessweep- Sweep profiles along pathstriangulate- Convert faces to triangular mesheswindingsort- Polygon winding order utilities
vertex- Point in 3D spaceedge- Connection between two verticesface- Planar or curved surfacehalfedge- Half-edge data structure (planned)
projection- 2D projection with hidden line removalpdf- PDF export (native only, not WASM)
Build Process
Rust to WASM Compilation
The core is compiled to WebAssembly usingwasm-pack:
opengeometry_bg.wasm- The compiled WebAssembly binaryopengeometry.js- JavaScript bindingsopengeometry.d.ts- TypeScript type definitions
TypeScript Wrapper Build
The Three.js integration layer is bundled using Rollup:Complete Build
build-core- Compiles Rust to WASMbuild-three- Bundles TypeScript wrappercopy-wasm- Copies artifacts to dist/
Configuration
Cargo.toml
The library is configured to build both as a WebAssembly module and a native Rust library:- cdylib - C-compatible dynamic library for WASM
- rlib - Rust library for native compilation
Key Dependencies
WASM/Serialization:wasm-bindgen- Rust/JavaScript interopserde- Serialization frameworkserde-wasm-bindgen- WASM-specific serialization
openmaths- Vector and matrix operations
earcutr- Polygon triangulationuuid- Unique identifiers for entities
printpdf- PDF generation (requires native compilation)
Platform Targets
Web (WASM)
Primary target usingtarget_arch = "wasm32":
- Runs in browser via WebAssembly
- Limited to WASM-compatible operations
- No file I/O, no native PDF export
Native (CLI/Server)
Secondary target for server-side use:- Full Rust performance
- File I/O capabilities
- PDF export via
printpdf - Configured with
cfg(not(target_arch = "wasm32"))
Performance Characteristics
- Rust Core: Near-native performance, memory-safe
- WASM Overhead: Minimal for compute-heavy operations
- Serialization: JSON for complex types, typed arrays for vertex data
- Three.js Integration: Efficient mesh creation from BREP output