@beanjs/three-csg-modeller
TypeScript icon, indicating that this package has built-in type declarations

0.1.10 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i @beanjs/three-csg-modeller

Weekly Downloads

1

Version

0.1.10

License

MIT

Unpacked Size

33.5 kB

Total Files

8

Last publish

Collaborators

  • beanjs