This repository has been archived on 2023-03-25. You can view files and clone it, but cannot push or open issues or pull requests.
mightyscape-1.1-deprecated/extensions/fablabchemnitz/papercraft/openjscad/node_modules/@jscad/json-deserializer/CSGFromJson.js

27 lines
821 B
JavaScript

const {CSG} = require('@jscad/csg')
// convert the given (anonymous JSON) object into CSG
// Note: Any issues during conversion will result in exceptions
function parse (o) {
// verify the object IS convertable
if (o.type === 'csg') {
Object.setPrototypeOf(o, CSG.prototype)
o.polygons.map(function (p) {
Object.setPrototypeOf(p, CSG.Polygon.prototype)
p.vertices.map(function (v) {
Object.setPrototypeOf(v, CSG.Vertex.prototype)
Object.setPrototypeOf(v.pos, CSG.Vector3D.prototype)
})
Object.setPrototypeOf(p.shared, CSG.Polygon.Shared.prototype)
Object.setPrototypeOf(p.plane, CSG.Plane.prototype)
Object.setPrototypeOf(p.plane.normal, CSG.Vector3D.prototype)
})
o.properties = new CSG.Properties()
}
return o
}
module.exports = {
parse
}