Skip to content

knee-cola/three-2-csg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

About

converts ThreeJS object into CSG and back

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published