Skip to main content
Gridfinity Builder uses Constructive Solid Geometry (CSG) to create watertight, printable 3D meshes. CSG combines primitive shapes using boolean operations (union, subtraction, intersection) to construct complex geometry.

What is CSG?

Constructive Solid Geometry is a modeling technique where complex objects are built by combining simple primitives:
  • Union (A ∪ B): Combine two shapes into one
  • Subtraction (A − B): Remove B from A
  • Intersection (A ∩ B): Keep only overlapping volume
CSG guarantees manifold (watertight) meshes, essential for 3D printing.

Manifold WASM Library

Gridfinity Builder uses Manifold, a high-performance CSG library compiled to WebAssembly:
useManifold.ts:7-19
The WASM module is initialized once and reused across all geometry operations.

Bin Building Process

Each Gridfinity bin is constructed through a series of boolean operations. The process varies between preview and export modes, but follows the same core algorithm.

Preview Geometry (Simplified)

From binGeometry.ts:388-420, the preview bin is built in 5 steps:
1

1. Outer Shell: Rounded Box

Create a solid rounded box with configurable corner radius
binGeometry.ts:399-400
The roundedBox helper (binGeometry.ts:40-59) extrudes a 2D rounded rectangle polygon to create a 3D solid.
2

2. Inner Cavity: Subtract Hollow Body

Create walls and floor by subtracting an inner cavity
binGeometry.ts:402-406
See binGeometry.ts:250-279 for the hollowing algorithm.
3

3. Union Base + Body

Combine the flat base and hollow body into a single mesh
binGeometry.ts:408-411
4

4. Subtract Features: Magnet & Screw Holes

Remove cylindrical holes for magnets and screws from the base
binGeometry.ts:413-414
Holes are positioned at bin corners with deduplication for multi-cell bins (binGeometry.ts:88-113).
5

5. Add Features: Label Shelf & Dividers

Add or subtract final details like label shelves and interior dividers
binGeometry.ts:416-417

Export Geometry (Full Fidelity)

Export geometry (binGeometry.ts:495-537) includes the precise Gridfinity Z-profile base:
1

Per-Cell Base Profile

Each cell gets a 5-layer stepped base profile for baseplate interlocking
binGeometry.ts:435-441
Each section uses tapered extrusion to create chamfered steps.
2

Bridge Slab

A full-width slab bridges gaps between cells in multi-cell bins
binGeometry.ts:509-513
3

Union + Features

Same hollow body, holes, and features as preview mode

Hollowing Algorithm

The createHollowBody function (binGeometry.ts:250-279) demonstrates CSG subtraction:
binGeometry.ts:261-277
Notice the 0.1mm overshoot on cavityH — this ensures a clean open top by extending the cavity slightly above the body.

Memory Management

Manifold objects are manually memory-managed. Every created object must be deleted after use:
Example Pattern
Helper functions like unionAll (binGeometry.ts:62-72) encapsulate this pattern:
binGeometry.ts:62-72

Rounded Corners

The createRoundedRectPolygon function (binGeometry.ts:8-38) generates a 2D polygon with circular arc corners:
binGeometry.ts:23-35
Each corner is approximated with 16 line segments (controlled by SEGMENTS_PER_CORNER:4).

Feature Application

Features like dividers and label shelves are applied as final add/subtract operations:
binGeometry.ts:311-362
Each feature is wrapped in a try-catch to ensure partial failures don’t crash the entire build.

Performance Considerations

  • CSG is expensive: Boolean operations scale with mesh complexity. Preview mode uses simpler geometry to stay fast.
  • Web Workers: All CSG runs in a background thread to avoid blocking the UI.
  • Caching: Identical configurations reuse cached meshes.
  • Memory leaks: Forgetting to .delete() Manifold objects causes WASM heap growth.