Fix multiple extrusions of the same outline in cases
This commit is contained in:
parent
77778249d2
commit
d2c3999d41
src
test
cases
cli/big/reference/cases
14
src/cases.js
14
src/cases.js
@ -69,15 +69,19 @@ exports.parse = (config, outlines, units) => {
|
||||
const extrude = a.sane(part.extrude || 1, `${part_qname}.extrude`, 'number')(units)
|
||||
const outline = outlines[name]
|
||||
a.assert(outline, `Field "${part_qname}.name" does not name a valid outline!`)
|
||||
if (!scripts[name]) {
|
||||
scripts[name] = m.exporter.toJscadScript(outline, {
|
||||
functionName: `${name}_outline_fn`,
|
||||
// This is a hack to separate multiple calls to the same outline with different extrude values
|
||||
// I know it needlessly duplicates a lot of code, but it's the quickest fix in the short term
|
||||
// And on the long run, we'll probably be moving to CADQuery anyway...
|
||||
const extruded_name = `${name}_extrude_` + ('' + extrude).replace(/\D/g, '_')
|
||||
if (!scripts[extruded_name]) {
|
||||
scripts[extruded_name] = m.exporter.toJscadScript(outline, {
|
||||
functionName: `${extruded_name}_outline_fn`,
|
||||
extrude: extrude,
|
||||
indent: 4
|
||||
})
|
||||
}
|
||||
outline_dependencies.push(name)
|
||||
base = `${name}_outline_fn()`
|
||||
outline_dependencies.push(extruded_name)
|
||||
base = `${extruded_name}_outline_fn()`
|
||||
} else {
|
||||
a.assert(part.extrude === undefined, `Field "${part_qname}.extrude" should not be used when what=case!`)
|
||||
a.in(name, `${part_qname}.name`, Object.keys(cases))
|
||||
|
@ -1,4 +1,4 @@
|
||||
function square_outline_fn(){
|
||||
function square_extrude_5_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] });
|
||||
}
|
||||
@ -10,7 +10,7 @@ function square_outline_fn(){
|
||||
|
||||
|
||||
// creating part 0 of case cube
|
||||
let cube__part_0 = square_outline_fn();
|
||||
let cube__part_0 = square_extrude_5_outline_fn();
|
||||
|
||||
// make sure that rotations are relative
|
||||
let cube__part_0_bounds = cube__part_0.getBounds();
|
||||
|
@ -1,15 +1,21 @@
|
||||
function _square_outline_fn(){
|
||||
function _square_extrude_8_outline_fn(){
|
||||
return new CSG.Path2D([[-4,-4],[4,-4]]).appendPoint([4,4]).appendPoint([-4,4]).appendPoint([-4,-4]).close().innerToCAG()
|
||||
.extrude({ offset: [0, 0, 8] });
|
||||
}
|
||||
|
||||
|
||||
function _circle_outline_fn(){
|
||||
function _circle_extrude_8_outline_fn(){
|
||||
return CAG.circle({"center":[0,0],"radius":3})
|
||||
.extrude({ offset: [0, 0, 8] });
|
||||
}
|
||||
|
||||
|
||||
function _square_extrude_1_outline_fn(){
|
||||
return new CSG.Path2D([[-4,-4],[4,-4]]).appendPoint([4,4]).appendPoint([-4,4]).appendPoint([-4,-4]).close().innerToCAG()
|
||||
.extrude({ offset: [0, 0, 1] });
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function _subtract_case_fn() {
|
||||
@ -55,7 +61,7 @@ function _circle_outline_fn(){
|
||||
|
||||
|
||||
// creating part 0 of case _cube
|
||||
let _cube__part_0 = _square_outline_fn();
|
||||
let _cube__part_0 = _square_extrude_8_outline_fn();
|
||||
|
||||
// make sure that rotations are relative
|
||||
let _cube__part_0_bounds = _cube__part_0.getBounds();
|
||||
@ -78,7 +84,7 @@ function _circle_outline_fn(){
|
||||
|
||||
|
||||
// creating part 0 of case _cylinder_one
|
||||
let _cylinder_one__part_0 = _circle_outline_fn();
|
||||
let _cylinder_one__part_0 = _circle_extrude_8_outline_fn();
|
||||
|
||||
// make sure that rotations are relative
|
||||
let _cylinder_one__part_0_bounds = _cylinder_one__part_0.getBounds();
|
||||
@ -101,7 +107,7 @@ function _circle_outline_fn(){
|
||||
|
||||
|
||||
// creating part 0 of case _cylinder_two
|
||||
let _cylinder_two__part_0 = _circle_outline_fn();
|
||||
let _cylinder_two__part_0 = _circle_extrude_8_outline_fn();
|
||||
|
||||
// make sure that rotations are relative
|
||||
let _cylinder_two__part_0_bounds = _cylinder_two__part_0.getBounds();
|
||||
@ -124,7 +130,7 @@ function _circle_outline_fn(){
|
||||
|
||||
|
||||
// creating part 0 of case _flat_square
|
||||
let _flat_square__part_0 = _square_outline_fn();
|
||||
let _flat_square__part_0 = _square_extrude_1_outline_fn();
|
||||
|
||||
// make sure that rotations are relative
|
||||
let _flat_square__part_0_bounds = _flat_square__part_0.getBounds();
|
||||
|
@ -1,4 +1,4 @@
|
||||
function export_outline_fn(){
|
||||
function export_extrude_1_outline_fn(){
|
||||
return new CSG.Path2D([[-9,-9],[9,-9]]).appendPoint([9,9]).appendPoint([-9,9]).appendPoint([-9,-9]).close().innerToCAG()
|
||||
.extrude({ offset: [0, 0, 1] });
|
||||
}
|
||||
@ -10,7 +10,7 @@ function export_outline_fn(){
|
||||
|
||||
|
||||
// creating part 0 of case _export
|
||||
let _export__part_0 = export_outline_fn();
|
||||
let _export__part_0 = export_extrude_1_outline_fn();
|
||||
|
||||
// make sure that rotations are relative
|
||||
let _export__part_0_bounds = _export__part_0.getBounds();
|
||||
|
@ -1,4 +1,4 @@
|
||||
function export_outline_fn(){
|
||||
function export_extrude_1_outline_fn(){
|
||||
return new CSG.Path2D([[-9,-9],[9,-9]]).appendPoint([9,9]).appendPoint([-9,9]).appendPoint([-9,-9]).close().innerToCAG()
|
||||
.extrude({ offset: [0, 0, 1] });
|
||||
}
|
||||
@ -10,7 +10,7 @@ function export_outline_fn(){
|
||||
|
||||
|
||||
// creating part 0 of case export
|
||||
let export__part_0 = export_outline_fn();
|
||||
let export__part_0 = export_extrude_1_outline_fn();
|
||||
|
||||
// make sure that rotations are relative
|
||||
let export__part_0_bounds = export__part_0.getBounds();
|
||||
|
Loading…
Reference in New Issue
Block a user