-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.hbs
39 lines (27 loc) · 1.46 KB
/
README.hbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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](https://www.npmjs.com/package/@jscad/csg).
This solution is based on [ThreeCSG.js converter](https://gist.github.com/chandlerprall/1590424) by [Chandler Prall](https://github.com/chandlerprall).
## Installation
`npm i three-2-csg`;
# Example
The following example is based on a [Stack overflow example](https://stackoverflow.com/questions/24716145/create-a-unique-sphere-geometry-from-a-sphere-and-a-cylinder-three-js#24720819) by [4m1r](https://stackoverflow.com/users/2296997/4m1r):
```javascript
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 );
```
{{>main}}
# License
MIT License, [http://www.opensource.org/licenses/MIT](http://www.opensource.org/licenses/MIT)