Created
December 4, 2017 13:19
-
-
Save kaosat-dev/9e48ab01870355e3751281dd77a6a468 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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