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-serializer/index.js

44 lines
896 B
JavaScript

const { ensureManifoldness } = require('@jscad/io-utils')
const mimeType = 'application/json'
function fromCAG (CAG) {
let str = '{ "type": "cag","sides": ['
let comma = ''
CAG.sides.map(
function (side) {
str += comma
str += JSON.stringify(side)
comma = ','
}
)
str += '] }'
return [str]
}
function fromCSG (CSG) {
let str = '{ "type": "csg","polygons": ['
let comma = ''
CSG.polygons.map(
function (polygon) {
str += comma
str += JSON.stringify(polygon)
comma = ','
}
)
str += '],'
str += '"isCanonicalized": ' + JSON.stringify(CSG.isCanonicalized) + ','
str += '"isRetesselated": ' + JSON.stringify(CSG.isRetesselated)
str += '}'
return [str]
}
function serialize (data, options) {
return 'sides' in data ? fromCAG(data) : fromCSG(ensureManifoldness(data))
}
module.exports = {
serialize,
mimeType
}