3D de-standalone-ification
This commit is contained in:
parent
c6f4832ee4
commit
bbab283850
12 changed files with 44 additions and 284 deletions
|
@ -15,7 +15,6 @@
|
||||||
"coverage": "nyc --reporter=html --reporter=text npm test"
|
"coverage": "nyc --reporter=html --reporter=text npm test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@jscad/openjscad": "github:ergogen/oldjscad",
|
|
||||||
"fs-extra": "^10.0.1",
|
"fs-extra": "^10.0.1",
|
||||||
"js-yaml": "^3.14.1",
|
"js-yaml": "^3.14.1",
|
||||||
"kle-serial": "github:ergogen/kle-serial#ergogen",
|
"kle-serial": "github:ergogen/kle-serial#ergogen",
|
||||||
|
|
|
@ -4,7 +4,7 @@ import commonjs from '@rollup/plugin-commonjs'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
input: 'src/ergogen.js',
|
input: 'src/ergogen.js',
|
||||||
external: ['makerjs', 'js-yaml', 'mathjs', 'kle-serial', '@jscad/openjscad'],
|
external: ['makerjs', 'js-yaml', 'mathjs', 'kle-serial'],
|
||||||
output: {
|
output: {
|
||||||
name: 'ergogen',
|
name: 'ergogen',
|
||||||
file: 'dist/ergogen.js',
|
file: 'dist/ergogen.js',
|
||||||
|
@ -14,8 +14,7 @@ export default {
|
||||||
'makerjs': 'makerjs',
|
'makerjs': 'makerjs',
|
||||||
'js-yaml': 'jsyaml',
|
'js-yaml': 'jsyaml',
|
||||||
'mathjs': 'math',
|
'mathjs': 'math',
|
||||||
'kle-serial': 'kle',
|
'kle-serial': 'kle'
|
||||||
'@jscad/openjscad': 'myjscad'
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
|
|
@ -81,7 +81,7 @@ const composite = (data, rel) => {
|
||||||
fs.mkdirpSync(path.dirname(abs))
|
fs.mkdirpSync(path.dirname(abs))
|
||||||
fs.writeFileSync(abs + '.yaml', yaml.dump(data.yaml, {indent: 4}))
|
fs.writeFileSync(abs + '.yaml', yaml.dump(data.yaml, {indent: 4}))
|
||||||
}
|
}
|
||||||
for (const format of ['svg', 'dxf', 'jscad', 'stl']) {
|
for (const format of ['svg', 'dxf', 'jscad']) {
|
||||||
if (data[format]) {
|
if (data[format]) {
|
||||||
fs.mkdirpSync(path.dirname(abs))
|
fs.mkdirpSync(path.dirname(abs))
|
||||||
fs.writeFileSync(abs + '.' + format, data[format])
|
fs.writeFileSync(abs + '.' + format, data[format])
|
||||||
|
|
|
@ -67,12 +67,12 @@ const process = async (raw, debug=false, logger=()=>{}) => {
|
||||||
empty = false
|
empty = false
|
||||||
}
|
}
|
||||||
|
|
||||||
logger('Extruding cases...')
|
logger('Modeling cases...')
|
||||||
const cases = cases_lib.parse(config.cases || {}, outlines, units)
|
const cases = cases_lib.parse(config.cases || {}, outlines, units)
|
||||||
results.cases = {}
|
results.cases = {}
|
||||||
for (const [case_name, case_script] of Object.entries(cases)) {
|
for (const [case_name, case_script] of Object.entries(cases)) {
|
||||||
if (!debug && case_name.startsWith('_')) continue
|
if (!debug && case_name.startsWith('_')) continue
|
||||||
results.cases[case_name] = await io.threedee(case_script, debug)
|
results.cases[case_name] = {jscad: case_script}
|
||||||
empty = false
|
empty = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
src/io.js
16
src/io.js
|
@ -1,6 +1,5 @@
|
||||||
const yaml = require('js-yaml')
|
const yaml = require('js-yaml')
|
||||||
const makerjs = require('makerjs')
|
const makerjs = require('makerjs')
|
||||||
const jscad = require('@jscad/openjscad')
|
|
||||||
|
|
||||||
const u = require('./utils')
|
const u = require('./utils')
|
||||||
const a = require('./assert')
|
const a = require('./assert')
|
||||||
|
@ -65,18 +64,3 @@ exports.twodee = (model, debug) => {
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.threedee = async (script, debug) => {
|
|
||||||
const compiled = await new Promise((resolve, reject) => {
|
|
||||||
jscad.compile(script, {}).then(compiled => {
|
|
||||||
resolve(compiled)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
const result = {
|
|
||||||
stl: jscad.generateOutput('stla', compiled).asBuffer().toString()
|
|
||||||
}
|
|
||||||
if (debug) {
|
|
||||||
result.jscad = script
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
36
test/cases/cube___cases_cube_jscad.jscad
Normal file
36
test/cases/cube___cases_cube_jscad.jscad
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
function square_outline_fn(){
|
||||||
|
return new CSG.Path2D([[-2.5,-2.5],[2.5,-2.5]]).appendPoint([2.5,2.5]).appendPoint([-2.5,2.5]).appendPoint([-2.5,-2.5]).close().innerToCAG()
|
||||||
|
.extrude({ offset: [0, 0, 5] });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function cube_case_fn() {
|
||||||
|
|
||||||
|
|
||||||
|
// creating part 0 of case cube
|
||||||
|
let cube__part_0 = square_outline_fn();
|
||||||
|
|
||||||
|
// make sure that rotations are relative
|
||||||
|
let cube__part_0_bounds = cube__part_0.getBounds();
|
||||||
|
let cube__part_0_x = cube__part_0_bounds[0].x + (cube__part_0_bounds[1].x - cube__part_0_bounds[0].x) / 2
|
||||||
|
let cube__part_0_y = cube__part_0_bounds[0].y + (cube__part_0_bounds[1].y - cube__part_0_bounds[0].y) / 2
|
||||||
|
cube__part_0 = translate([-cube__part_0_x, -cube__part_0_y, 0], cube__part_0);
|
||||||
|
cube__part_0 = rotate([0,0,0], cube__part_0);
|
||||||
|
cube__part_0 = translate([cube__part_0_x, cube__part_0_y, 0], cube__part_0);
|
||||||
|
|
||||||
|
cube__part_0 = translate([0,0,0], cube__part_0);
|
||||||
|
let result = cube__part_0;
|
||||||
|
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
return cube_case_fn();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
solid csg.js
|
|
||||||
facet normal 0 0 -1
|
|
||||||
outer loop
|
|
||||||
vertex -2.5 2.5 0
|
|
||||||
vertex 2.5 2.5 0
|
|
||||||
vertex 2.5 -2.5 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 0 -1
|
|
||||||
outer loop
|
|
||||||
vertex -2.5 2.5 0
|
|
||||||
vertex 2.5 -2.5 0
|
|
||||||
vertex -2.5 -2.5 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 0 1
|
|
||||||
outer loop
|
|
||||||
vertex -2.5 2.5 5
|
|
||||||
vertex -2.5 -2.5 5
|
|
||||||
vertex 2.5 -2.5 5
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 0 1
|
|
||||||
outer loop
|
|
||||||
vertex -2.5 2.5 5
|
|
||||||
vertex 2.5 -2.5 5
|
|
||||||
vertex 2.5 2.5 5
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 -1 0
|
|
||||||
outer loop
|
|
||||||
vertex 2.5 -2.5 0
|
|
||||||
vertex 2.5 -2.5 5
|
|
||||||
vertex -2.5 -2.5 5
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 -1 0
|
|
||||||
outer loop
|
|
||||||
vertex 2.5 -2.5 0
|
|
||||||
vertex -2.5 -2.5 5
|
|
||||||
vertex -2.5 -2.5 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 1 0 0
|
|
||||||
outer loop
|
|
||||||
vertex 2.5 2.5 0
|
|
||||||
vertex 2.5 2.5 5
|
|
||||||
vertex 2.5 -2.5 5
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 1 0 0
|
|
||||||
outer loop
|
|
||||||
vertex 2.5 2.5 0
|
|
||||||
vertex 2.5 -2.5 5
|
|
||||||
vertex 2.5 -2.5 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 1 0
|
|
||||||
outer loop
|
|
||||||
vertex 2.5 2.5 5
|
|
||||||
vertex 2.5 2.5 0
|
|
||||||
vertex -2.5 2.5 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 1 0
|
|
||||||
outer loop
|
|
||||||
vertex 2.5 2.5 5
|
|
||||||
vertex -2.5 2.5 0
|
|
||||||
vertex -2.5 2.5 5
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal -1 0 0
|
|
||||||
outer loop
|
|
||||||
vertex -2.5 2.5 5
|
|
||||||
vertex -2.5 2.5 0
|
|
||||||
vertex -2.5 -2.5 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal -1 0 0
|
|
||||||
outer loop
|
|
||||||
vertex -2.5 2.5 5
|
|
||||||
vertex -2.5 -2.5 0
|
|
||||||
vertex -2.5 -2.5 5
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
endsolid csg.js
|
|
|
@ -5,7 +5,7 @@ Preprocessing input...
|
||||||
Calculating variables...
|
Calculating variables...
|
||||||
Parsing points...
|
Parsing points...
|
||||||
Generating outlines...
|
Generating outlines...
|
||||||
Extruding cases...
|
Modeling cases...
|
||||||
Scaffolding PCBs...
|
Scaffolding PCBs...
|
||||||
Cleaning output folder...
|
Cleaning output folder...
|
||||||
Writing output to disk...
|
Writing output to disk...
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
solid csg.js
|
|
||||||
facet normal 0 0 -1
|
|
||||||
outer loop
|
|
||||||
vertex -9 9 0
|
|
||||||
vertex 9 9 0
|
|
||||||
vertex 9 -9 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 0 -1
|
|
||||||
outer loop
|
|
||||||
vertex -9 9 0
|
|
||||||
vertex 9 -9 0
|
|
||||||
vertex -9 -9 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 0 1
|
|
||||||
outer loop
|
|
||||||
vertex -9 9 1
|
|
||||||
vertex -9 -9 1
|
|
||||||
vertex 9 -9 1
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 0 1
|
|
||||||
outer loop
|
|
||||||
vertex -9 9 1
|
|
||||||
vertex 9 -9 1
|
|
||||||
vertex 9 9 1
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 -1 0
|
|
||||||
outer loop
|
|
||||||
vertex 9 -9 0
|
|
||||||
vertex 9 -9 1
|
|
||||||
vertex -9 -9 1
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 -1 0
|
|
||||||
outer loop
|
|
||||||
vertex 9 -9 0
|
|
||||||
vertex -9 -9 1
|
|
||||||
vertex -9 -9 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 1 0 0
|
|
||||||
outer loop
|
|
||||||
vertex 9 9 0
|
|
||||||
vertex 9 9 1
|
|
||||||
vertex 9 -9 1
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 1 0 0
|
|
||||||
outer loop
|
|
||||||
vertex 9 9 0
|
|
||||||
vertex 9 -9 1
|
|
||||||
vertex 9 -9 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 1 0
|
|
||||||
outer loop
|
|
||||||
vertex 9 9 1
|
|
||||||
vertex 9 9 0
|
|
||||||
vertex -9 9 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 1 0
|
|
||||||
outer loop
|
|
||||||
vertex 9 9 1
|
|
||||||
vertex -9 9 0
|
|
||||||
vertex -9 9 1
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal -1 0 0
|
|
||||||
outer loop
|
|
||||||
vertex -9 9 1
|
|
||||||
vertex -9 9 0
|
|
||||||
vertex -9 -9 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal -1 0 0
|
|
||||||
outer loop
|
|
||||||
vertex -9 9 1
|
|
||||||
vertex -9 -9 0
|
|
||||||
vertex -9 -9 1
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
endsolid csg.js
|
|
|
@ -1,86 +0,0 @@
|
||||||
solid csg.js
|
|
||||||
facet normal 0 0 -1
|
|
||||||
outer loop
|
|
||||||
vertex -9 9 0
|
|
||||||
vertex 9 9 0
|
|
||||||
vertex 9 -9 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 0 -1
|
|
||||||
outer loop
|
|
||||||
vertex -9 9 0
|
|
||||||
vertex 9 -9 0
|
|
||||||
vertex -9 -9 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 0 1
|
|
||||||
outer loop
|
|
||||||
vertex -9 9 1
|
|
||||||
vertex -9 -9 1
|
|
||||||
vertex 9 -9 1
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 0 1
|
|
||||||
outer loop
|
|
||||||
vertex -9 9 1
|
|
||||||
vertex 9 -9 1
|
|
||||||
vertex 9 9 1
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 -1 0
|
|
||||||
outer loop
|
|
||||||
vertex 9 -9 0
|
|
||||||
vertex 9 -9 1
|
|
||||||
vertex -9 -9 1
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 -1 0
|
|
||||||
outer loop
|
|
||||||
vertex 9 -9 0
|
|
||||||
vertex -9 -9 1
|
|
||||||
vertex -9 -9 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 1 0 0
|
|
||||||
outer loop
|
|
||||||
vertex 9 9 0
|
|
||||||
vertex 9 9 1
|
|
||||||
vertex 9 -9 1
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 1 0 0
|
|
||||||
outer loop
|
|
||||||
vertex 9 9 0
|
|
||||||
vertex 9 -9 1
|
|
||||||
vertex 9 -9 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 1 0
|
|
||||||
outer loop
|
|
||||||
vertex 9 9 1
|
|
||||||
vertex 9 9 0
|
|
||||||
vertex -9 9 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal 0 1 0
|
|
||||||
outer loop
|
|
||||||
vertex 9 9 1
|
|
||||||
vertex -9 9 0
|
|
||||||
vertex -9 9 1
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal -1 0 0
|
|
||||||
outer loop
|
|
||||||
vertex -9 9 1
|
|
||||||
vertex -9 9 0
|
|
||||||
vertex -9 -9 0
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
facet normal -1 0 0
|
|
||||||
outer loop
|
|
||||||
vertex -9 9 1
|
|
||||||
vertex -9 -9 0
|
|
||||||
vertex -9 -9 1
|
|
||||||
endloop
|
|
||||||
endfacet
|
|
||||||
endsolid csg.js
|
|
|
@ -5,7 +5,7 @@ Preprocessing input...
|
||||||
Calculating variables...
|
Calculating variables...
|
||||||
Parsing points...
|
Parsing points...
|
||||||
Generating outlines...
|
Generating outlines...
|
||||||
Extruding cases...
|
Modeling cases...
|
||||||
Scaffolding PCBs...
|
Scaffolding PCBs...
|
||||||
Writing output to disk...
|
Writing output to disk...
|
||||||
Done.
|
Done.
|
||||||
|
|
|
@ -5,7 +5,7 @@ Preprocessing input...
|
||||||
Calculating variables...
|
Calculating variables...
|
||||||
Parsing points...
|
Parsing points...
|
||||||
Generating outlines...
|
Generating outlines...
|
||||||
Extruding cases...
|
Modeling cases...
|
||||||
Scaffolding PCBs...
|
Scaffolding PCBs...
|
||||||
Output would be empty, rerunning in debug mode...
|
Output would be empty, rerunning in debug mode...
|
||||||
Writing output to disk...
|
Writing output to disk...
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue