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
- Kernel-backed boolean operations (union, intersection, subtraction)
vertex- Point in 3D spacehalfedge- Directed half-edge topology (twin/next/prev)edge- Undirected edge with primary/twin half-edge referencesloop- Face boundary loops (outer and inner holes)face- Face normal and loop referenceswire- Polyline topology (open or closed)shell- Face groups (open or closed)builder- Safe B-Rep construction helper that validates topologyerror- B-Rep error types used during building and validation
stl- STL export (bytes, experimental)ifc- IFC export (text, experimental)pdf- PDF export (native only, experimental)step- STEP export (text, experimental)projection- 2D projection with hidden line removal (experimental)
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
Next Steps
Primitives and Shapes
Explore the available 2D and 3D primitives you can create
CAD Operations
Learn about extrusion, offsetting, sweeping, and more
Boundary Representation
Understand how BREP works and how to build complex geometry
Booleans
See how to perform boolean operations with OpenGeometry

