Skip to content

Instantly share code, notes, and snippets.

@kaosat-dev
Created December 4, 2017 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaosat-dev/9e48ab01870355e3751281dd77a6a468 to your computer and use it in GitHub Desktop.
Save kaosat-dev/9e48ab01870355e3751281dd77a6a468 to your computer and use it in GitHub Desktop.
const projection = function (params, ...csgs) {
const defaults = {
plane: [0, 0, 1, 1],// x, y, z, w : as an array, magically simple !!
cut: false
}
const {plane, cut} = Object.assign({}, defaults, params)
const [x, y, z, w] = plane
// for now we still have to convert arrays to something way more complicated internally , sigh
const orthobasis = new CSG.OrthoNormalBasis(new CSG.Plane(new CSG.Vector3D([x, y, z]), w))
const results = csgs.map(function (csg) {
if (cut) {
return csg.sectionCut(orthobasis)
} else {
let cags = []
csg.polygons
.map(function (polygon) {
let cag = polygon.projectToOrthoNormalBasis(orthobasis)
if (cag.sides.length > 0) {
cags.push(cag)
}
})
let result = new CAG().union(cags)
return result
}
})
return results.length > 1 ? results : results[0]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment