1.0.2 • Published 6 years ago

three-2-csg v1.0.2

Weekly downloads
2
License
MIT
Repository
-
Last release
6 years ago

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.

Installation

npm i three-2-csg

Example

The following example is based on a Stack overflow example by 4m1r:

import { toCSG, fromCSG } from 'three-2-csg';

//sphere
var sphere = new THREE.SphereGeometry(2,20,20);
var sphereMesh = new THREE.Mesh( sphere, material );
var sphereCSG = toCSG( sphereMesh ); // converting ThreeJS object to CSG

// cyl
var cylinder = new THREE.CylinderGeometry(0.5, 0.5, 5, 32 );
var cylinderMesh = new THREE.Mesh( cylinder, material );
var cylinderCSG = toCSG( cylinderMesh ); // converting ThreeJS object to CSG

//result
var subtractCSG = sphereCSG.subtract( cylinderCSG );
var result = fromCSG(subtractCSG); // converting CSG back into ThreeJS object

result.geometry.computeVertexNormals();

scene.add( result );

Functions

toCSG(three_model) ⇒ CSG_solid

Converts a ThreeJS 3D object into a CSG solid

Kind: global function

ParamTypeDescription
three_modelThreeJS_MeshThreeJS 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

ParamTypeDescription
csg_modelCSG_solid= CSG solid to be converted

License

MIT License, http://www.opensource.org/licenses/MIT

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago