From 6e31ede77143f2897f3b670827fa5783a134ee30 Mon Sep 17 00:00:00 2001 From: blackboots <47943405+aka-blackboots@users.noreply.github.com> Date: Wed, 4 Mar 2026 09:47:00 +0100 Subject: [PATCH 1/4] Add kernel and three.js boolean shape operations --- ...03-04-boolean-operations-implementation.md | 62 ++ .../examples-vite/index.html | 10 +- .../examples-vite/operations/boolean.html | 12 + .../src/pages/operations-boolean.ts | 78 +++ main/opengeometry-three/index.ts | 5 + .../src/operations/boolean.ts | 95 +++ .../src/operations/index.ts | 1 + main/opengeometry/src/lib.rs | 1 + main/opengeometry/src/operations/boolean.rs | 555 ++++++++++++++++++ 9 files changed, 818 insertions(+), 1 deletion(-) create mode 100644 AI-DOCs/2026-03-04-boolean-operations-implementation.md create mode 100644 main/opengeometry-three/examples-vite/operations/boolean.html create mode 100644 main/opengeometry-three/examples-vite/src/pages/operations-boolean.ts create mode 100644 main/opengeometry-three/src/operations/boolean.ts create mode 100644 main/opengeometry-three/src/operations/index.ts create mode 100644 main/opengeometry/src/operations/boolean.rs diff --git a/AI-DOCs/2026-03-04-boolean-operations-implementation.md b/AI-DOCs/2026-03-04-boolean-operations-implementation.md new file mode 100644 index 0000000..94f9a57 --- /dev/null +++ b/AI-DOCs/2026-03-04-boolean-operations-implementation.md @@ -0,0 +1,62 @@ +# 2026-03-04 Boolean Operations Implementation + +## What changed + +- Added a new kernel operation module `operations::boolean` with a wasm-bindgen class `OGBoolean`. +- `OGBoolean::compute` accepts two triangle buffers (`[x,y,z,...]`), an operation (`union`, `intersection`, `difference`), and optional numeric constraints. +- Implemented a BSP/plane-splitting CSG pipeline (`Node`, `Plane`, `Polygon`) with tolerance-driven vertex snapping and post-op vertex welding. +- Exposed the new module from `main/opengeometry/src/lib.rs`. +- Added `@opengeometry/kernel-three` bindings: + - `BooleanShape` for running booleans on any `THREE.Mesh` with `BufferGeometry`. + - `BooleanConstraints` and `BooleanOperation` types. +- Added a new Vite example page (`examples-vite/operations/boolean.html`) and runtime page logic (`operations-boolean.ts`). +- Updated the examples index to advertise the new Boolean operation card. + +## Why it changed + +The project needed a shape-agnostic boolean pipeline. Existing shape wrappers already produce triangulated meshes, so this implementation uses those triangulations as a shared interchange format and applies constructive-solid-geometry operations in the kernel, then returns a new triangle buffer for rendering. + +## Paper alignment and robustness strategy + +The requested `RobustBoolean.pdf` was not available inside this execution environment, so direct line-by-line extraction from the paper was not possible during implementation. This change still applies common robust boolean principles typically emphasized in robust CSG literature: + +- Epsilon-based plane classification (`front`, `back`, `coplanar`, `spanning`) +- Grid snapping for deterministic splitting intersections +- Vertex welding after operation completion + +These controls are exposed as `constraints.epsilon` and `constraints.snap` so callers can tune behavior per model scale. + +## How to test locally + +1. Kernel tests: + +```bash +cargo test --manifest-path main/opengeometry/Cargo.toml +``` + +2. Build wasm package (requires `wasm-pack`): + +```bash +npm run build-core +``` + +3. Build Three adapter/examples: + +```bash +npm run build-three +npm --prefix main/opengeometry-three run build-example-three +``` + +4. Open `main/opengeometry-three/examples-vite/operations/boolean.html` through the Vite examples app. + +## Backward compatibility + +- No existing public API was removed. +- Existing shapes/primitives continue unchanged. +- New API is additive (`OGBoolean`, `BooleanShape`). + +## Known caveats and follow-ups + +- Current boolean output quality depends on clean manifold triangulations. +- Numerical controls may need per-project presets depending on unit scale. +- A follow-up should validate against the intended RobustBoolean paper test corpus once the PDF is available in-repo. diff --git a/main/opengeometry-three/examples-vite/index.html b/main/opengeometry-three/examples-vite/index.html index d4b3d00..d6e0f41 100644 --- a/main/opengeometry-three/examples-vite/index.html +++ b/main/opengeometry-three/examples-vite/index.html @@ -134,7 +134,7 @@
3 items
+4 items
new
Union / intersection / difference with numeric robustness controls.
+ +ready
Operation-level sweep from path primitive + profile primitive.
diff --git a/main/opengeometry-three/examples-vite/operations/boolean.html b/main/opengeometry-three/examples-vite/operations/boolean.html new file mode 100644 index 0000000..dc870cb --- /dev/null +++ b/main/opengeometry-three/examples-vite/operations/boolean.html @@ -0,0 +1,12 @@ + + + + + +