three-bvh-csg
three-bvh-csg copied to clipboard
A flexible, memory compact, fast and dynamic CSG implementation on top of three-mesh-bvh
three-bvh-csg
An experimental, in progress, flexible, memory compact, fast and dynamic CSG implementation on top of three-mesh-bvh. More than 100 times faster than other BSP-based three.js CSG libraries in complex cases.
Contributions welcome!
Roadmap
- Fix triangle splitting / missing triangle issues
- Hierarchical operations #6
- Polygon splitting #4
- Worker Support #14
Examples
Use
import { SUBTRACTION, Brush, Evaluator } from 'three-bvh-csg';
import { MeshStandardMaterial, Mesh, SphereGeometry, BoxGeometry } from 'three';
const csgEvaluator = new Evaluator();
const brush1 = new Brush( new SphereGeometry() );
const brush2 = new Brush( new BoxGeometry() );
const result = csgEvaluator.evaluate( brush1, brush2, SUBTRACTION );
// render the result!
API
Constants
Operations
CSG operations enums for use with Evaluator
.
ADDITION
SUBTRACTION
DIFFERENCE
INTERSECTION
Brush
extends THREE.Mesh
An object with the same interface as THREE.Mesh
but used to evaluate CSG operations. Once a brush is created the geometry should not be modified.
Note
It is recommended to remove groups from a geometry before creating a brush if multi-material support is not required.
Evaluator
.useGroups
useGroups = true : Boolean
Whether to use geometry groups when processing the geometry. If geometry groups are used then a material array and groups will be assigned to the target Brush
after processing. If groups are disabled then a single coherent piece of geometry with no groups will be produced.
.evaluate
evaluate(
brushA : Brush,
brushB : Brush,
operation : Operation,
target = null : Brush | Mesh
) : Brush | Mesh
Performs the given operation
on brushA
with brushB
. If no target is provided then a new Brush
will be created with the new geometry. Otherwise the provided Brush will be modified in place and geometry disposed or marked for update as needed.
Gotchas
- All geometry are expected to have all attributes being used and of the same type.
- Geometry on a Brush should be unique and not be modified after being set.
References
- Godot CSG
- RealtimeCSG (Overview, GDC Presentation)