belopot / three-bvh-csg

A flexible, memory compact, fast and dynamic CSG implementation on top of three-mesh-bvh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

three-bvh-csg

lgtm code quality build github twitter sponsors

A 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

  • Hierarchical operations #6
  • Polygon splitting #4
  • Worker Support #14

Examples

Simple CSG

Complex Model CSG

Multimaterial CSG

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

About

A flexible, memory compact, fast and dynamic CSG implementation on top of three-mesh-bvh

License:MIT License


Languages

Language:JavaScript 100.0%