0.1.10 • Published 2 years ago
@beanjs/three-csg-modeller v0.1.10
About
Solid mesh modeling for three.js.
Featrues
- Manipulate
BufferGeometrydirectly. - Support vertex color and mutli-material.
- Dump mesh with indexed
BufferGeometry.
Examples
- Gradient Crown (vertex color)
- Gallery Frame (mutli-material)
- Extrude Inwards (set operations)
Installation
Via npm ( npm i ycw/three-csg-modeller#v0.1.10 )
import { CSGModeller } from "three-csg-modeller"Via cdn
import { CSGModeller } from "https://cdn.jsdelivr.net/gh/ycw/three-csg-modeller@0.1.10/dist/lib.esm.js"Usage
// Ex. Subtract a box from a sphere.
const modeller = new CSGModeller(THREE);
const sphereModel = modeller.model(new THREE.Mesh(
new THREE.SphereBufferGeometry(0.5),
new THREE.MeshLambertMaterial({ color: "black" })
));
const boxModel = modeller.model(new THREE.Mesh(
new THREE.BoxBufferGeometry(0.5, 0.5, 1),
new THREE.MeshLambertMaterial({ color: "white" })
));
const model = sphereModel.subtract(boxModel);
const mesh = model.build();Live result: Basic Subtract. See also: Basic Multi-Material.
API
CSGModeller
new CSGModeller(THREE)
- Construct a modeller.
THREEis the three.js lib.
.model(mesh)
- Create a
Modelinstance from a mesh whose.geometrymust be aBufferGeometry.
Model
.union(model)
- Return a new model holding result of
this∪model.
.subtract(model)
- Return a new model holding result of
this−model.
.intersect(model)
- Return a new model holding result of
this∩model.
.applyMatrix4(matrix)
- Return a new transformed model. Param
matrixis aTHREE.Matrix4.
.build()
- Build and return a mesh holding an indexed
BufferGeometry.
Credits
License
0.1.10
2 years ago