three-csg-ts
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [3.1.0](https://github.com/Jiro-Digital/three-csg-ts/compare/v3.0.1...v3.1.0) (2021-05-14) | ||
### Features | ||
* add static CSG wrapper methods ([860143c](https://github.com/Jiro-Digital/three-csg-ts/commit/860143c43c1215421ca1a69b932f96a2fa95371e)) | ||
### [3.0.1](https://github.com/Jiro-Digital/three-csg-ts/compare/v3.0.0...v3.0.1) (2021-05-14) | ||
@@ -7,0 +14,0 @@ |
@@ -13,2 +13,5 @@ import { BufferGeometry, Material, Matrix4, Mesh } from 'three'; | ||
static toMesh(csg: CSG, toMatrix: Matrix4, toMaterial?: Material | Material[]): Mesh; | ||
static union(meshA: Mesh, meshB: Mesh): Mesh; | ||
static subtract(meshA: Mesh, meshB: Mesh): Mesh; | ||
static intersect(meshA: Mesh, meshB: Mesh): Mesh; | ||
private polygons; | ||
@@ -21,2 +24,4 @@ clone(): CSG; | ||
inverse(): CSG; | ||
toMesh(toMatrix: Matrix4, toMaterial?: Material | Material[]): Mesh; | ||
toGeometry(toMatrix: Matrix4): BufferGeometry; | ||
} |
@@ -148,2 +148,17 @@ "use strict"; | ||
} | ||
static union(meshA, meshB) { | ||
const csgA = CSG.fromMesh(meshA); | ||
const csgB = CSG.fromMesh(meshB); | ||
return CSG.toMesh(csgA.union(csgB), meshA.matrix, meshA.material); | ||
} | ||
static subtract(meshA, meshB) { | ||
const csgA = CSG.fromMesh(meshA); | ||
const csgB = CSG.fromMesh(meshB); | ||
return CSG.toMesh(csgA.subtract(csgB), meshA.matrix, meshA.material); | ||
} | ||
static intersect(meshA, meshB) { | ||
const csgA = CSG.fromMesh(meshA); | ||
const csgB = CSG.fromMesh(meshB); | ||
return CSG.toMesh(csgA.intersect(csgB), meshA.matrix, meshA.material); | ||
} | ||
clone() { | ||
@@ -199,6 +214,14 @@ const csg = new CSG(); | ||
const csg = this.clone(); | ||
csg.polygons.forEach((p) => p.flip()); | ||
for (const p of csg.polygons) { | ||
p.flip(); | ||
} | ||
return csg; | ||
} | ||
toMesh(toMatrix, toMaterial) { | ||
return CSG.toMesh(this, toMatrix, toMaterial); | ||
} | ||
toGeometry(toMatrix) { | ||
return CSG.toGeometry(this, toMatrix); | ||
} | ||
} | ||
exports.CSG = CSG; |
@@ -13,2 +13,5 @@ import { BufferGeometry, Material, Matrix4, Mesh } from 'three'; | ||
static toMesh(csg: CSG, toMatrix: Matrix4, toMaterial?: Material | Material[]): Mesh; | ||
static union(meshA: Mesh, meshB: Mesh): Mesh; | ||
static subtract(meshA: Mesh, meshB: Mesh): Mesh; | ||
static intersect(meshA: Mesh, meshB: Mesh): Mesh; | ||
private polygons; | ||
@@ -21,2 +24,4 @@ clone(): CSG; | ||
inverse(): CSG; | ||
toMesh(toMatrix: Matrix4, toMaterial?: Material | Material[]): Mesh; | ||
toGeometry(toMatrix: Matrix4): BufferGeometry; | ||
} |
@@ -145,2 +145,17 @@ import { BufferAttribute, BufferGeometry, Matrix3, Matrix4, Mesh, Vector3, } from 'three'; | ||
} | ||
static union(meshA, meshB) { | ||
const csgA = CSG.fromMesh(meshA); | ||
const csgB = CSG.fromMesh(meshB); | ||
return CSG.toMesh(csgA.union(csgB), meshA.matrix, meshA.material); | ||
} | ||
static subtract(meshA, meshB) { | ||
const csgA = CSG.fromMesh(meshA); | ||
const csgB = CSG.fromMesh(meshB); | ||
return CSG.toMesh(csgA.subtract(csgB), meshA.matrix, meshA.material); | ||
} | ||
static intersect(meshA, meshB) { | ||
const csgA = CSG.fromMesh(meshA); | ||
const csgB = CSG.fromMesh(meshB); | ||
return CSG.toMesh(csgA.intersect(csgB), meshA.matrix, meshA.material); | ||
} | ||
clone() { | ||
@@ -196,5 +211,13 @@ const csg = new CSG(); | ||
const csg = this.clone(); | ||
csg.polygons.forEach((p) => p.flip()); | ||
for (const p of csg.polygons) { | ||
p.flip(); | ||
} | ||
return csg; | ||
} | ||
toMesh(toMatrix, toMaterial) { | ||
return CSG.toMesh(this, toMatrix, toMaterial); | ||
} | ||
toGeometry(toMatrix) { | ||
return CSG.toGeometry(this, toMatrix); | ||
} | ||
} |
{ | ||
"name": "three-csg-ts", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "CSG library for use with THREE.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/cjs/index.js", |
@@ -43,14 +43,4 @@ # three-csg-ts | ||
// Create a bsp tree from each of the meshes | ||
const bspA = CSG.fromMesh(meshA); | ||
const bspB = CSG.fromMesh(meshB); | ||
// Subtract one bsp from the other via .subtract... other supported modes are .union and .intersect | ||
const bspResult = bspA.subtract(bspB); | ||
// Get the resulting mesh from the result bsp | ||
const meshResult = CSG.toMesh(bspResult, meshA.matrix); | ||
// Set the results material to the material of the first cube. | ||
meshResult.material = meshA.material; | ||
// Subtract meshB from meshA | ||
const meshResult = CSG.subtract(meshA, meshB); | ||
``` |
63390
1437
46