Skip to content

Constructive Solid Geometry for three.js, ES6 + BufferGeometry

License

Notifications You must be signed in to change notification settings

ThreeDfish/threejs-csg

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

threejs-csg (Work in Progress)

Constructive Solid Geometry for three.js, ES6 + BufferGeometry

Developing

Run npm install then npm start

To view the demo, direct your browser to http://127.0.0.1:8080/demo/tests/index.html

Usage

const box = new Mesh(new BoxBufferGeometry(0.2, 0.2, 1), material);
// console.log('box: ', new BoxBufferGeometry(0.2, 0.2, 1));
box.position.set(0.1, 0.1, 0);

const sphere = new Mesh(new SphereBufferGeometry(0.1), material);
sphere.position.set(0, 0, -0.3);

const sphereB = sphere.clone();
sphereB.position.set(0, 0, 0.3);

const csg = new CSG();

csg.setFromMesh(box);
csg.union([sphere, sphereB]);
=> equivalent to (if no mesh is set, the first mesh in the array is used)
csg.union([box, sphere, sphereB]);

// csg.subtract([box, sphere, sphereB]);
// csg.intersect([box, sphere]);

const resultMesh = csg.toMesh();

TODO

  • Only the material from the first mesh is used.
  • Vertex colors are ignored.
  • Very slow

Prior Work

http://evanw.github.io/csg.js/docs

https://github.com/jscad/csg.js

http://sandervanrossen.blogspot.com/2010/05/csg-operations.html

https://www.geometrictools.com/Documentation/ClipMesh.pdf

About

Constructive Solid Geometry for three.js, ES6 + BufferGeometry

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%