What's this?
This is a converter which enables conversion of ThreeJS objects into CSG and back (it works both ways).
CSG objects created by this converter can then be manipulated via @jscad/csg.
This solution is based on ThreeCSG.js converter by Chandler Prall.
Example
The following example is based on a Stack overflow example by 4m1r:
import { toCSG, fromCSG } from 'three-2-csg';
var sphere = new THREE.SphereGeometry(2,20,20);
var sphereMesh = new THREE.Mesh( sphere, material );
var sphereCSG = toCSG( sphereMesh );
var cylinder = new THREE.CylinderGeometry(0.5, 0.5, 5, 32 );
var cylinderMesh = new THREE.Mesh( cylinder, material );
var cylinderCSG = toCSG( cylinderMesh );
var subtractCSG = sphereCSG.subtract( cylinderCSG );
var result = fromCSG(subtractCSG);
result.geometry.computeVertexNormals();
scene.add( result );
Functions
- toCSG(three_model) ⇒
CSG_solid
Converts a ThreeJS 3D object into a CSG solid
- fromCSG(csg_model) ⇒
THREE_Geometry
Converts a CSG solid (3d object) into regular ThreeJS geometry
toCSG(three_model) ⇒ CSG_solid
Converts a ThreeJS 3D object into a CSG solid
Kind: global function
Param | Type | Description |
---|
three_model | ThreeJS_Mesh | ThreeJS Mesh (or Geometry) which needs to be converted |
fromCSG(csg_model) ⇒ THREE_Geometry
Converts a CSG solid (3d object) into regular ThreeJS geometry
Kind: global function
Param | Type | Description |
---|
csg_model | CSG_solid | = CSG solid to be converted |
License
MIT License, http://www.opensource.org/licenses/MIT