Skip to content

ycw/three-csg-modeller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

Solid mesh modeling for three.js.

Featrues

  • Manipulate BufferGeometry directly.
  • Support vertex color and mutli-material.
  • Dump mesh with indexed BufferGeometry.

Examples

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. THREE is the three.js lib.

.model(mesh)

  • Create a Model instance from a mesh whose .geometry must be a BufferGeometry.

Model

.union(model)

  • Return a new model holding result of thismodel.

.subtract(model)

  • Return a new model holding result of thismodel.

.intersect(model)

  • Return a new model holding result of thismodel.

.applyMatrix4(matrix)

  • Return a new transformed model. Param matrix is a THREE.Matrix4.

.build()

  • Build and return a mesh holding an indexed BufferGeometry.

Credits

License

MIT