add z depth svg import option

This commit is contained in:
Stewart Allen 2024-09-10 14:03:02 -04:00
commit 2aa1a2c663
2 changed files with 7 additions and 7 deletions

View file

@ -883,6 +883,7 @@ function loadSVGDialog(doit) {
" Finer angle settings produce much larger models.",
" </p>",
" <div class='f-row t-right'><table>",
" <tr><th>z height in mm</th><td><input id='svg-depth' value='5' size='3'></td></tr>",
" <tr><th title='higher values results in more points. floating point values like 0.5 are accepted'>arc segments / mm</th><td><input id='svg-arcs' value='1' size='3'></td></tr>",
" <tr><th title='minimum number of segments in an arc. helps better represent small arcs'>min arc segments</th><td><input id='svg-marc' value='10' size='3'></td></tr>",
" <tr><th>nest shapes</th><td><input id='svg-nest' value='1' type='checkbox' checked></td></tr>",
@ -890,10 +891,11 @@ function loadSVGDialog(doit) {
"</div>"
]};
api.uc.confirm(undefined, {convert:true, cancel:false}, undefined, opt).then((ok) => {
let depth = Math.max(0.1, parseFloat($('svg-depth').value));
let arcs = Math.max(0.01, parseFloat($('svg-arcs').value));
let marc = Math.max(1, parseInt($('svg-marc').value));
let soup = $('svg-nest').checked;
ok && doit({ soup, resolution: arcs, segmin: marc });
ok && doit({ soup, resolution: arcs, segmin: marc, depth });
});
}

View file

@ -27,9 +27,9 @@ function parse(text, opt = { }) {
const xmlat = data.xml.attributes;
const polys = fromSoup ? [] : undefined;
const scale = xmlat.width?.value.endsWith('in') ? 25.4 : 1;
const depth = opt.depth || xmlat['data-km-extrude']?.value
const depth = parseFloat(opt.depth || xmlat['data-km-extrude']?.value
|| xmlat['extrude']?.value
|| {value: 5};
|| 5);
for (let i = 0; i < paths.length; i++) {
let path = paths[i];
@ -39,7 +39,6 @@ function parse(text, opt = { }) {
let miter = path.userData?.style?.strokeMiterLimit;
if (fromSoup) {
for (let sub of path.subPaths) {
let length = sub.getLength();
let points = sub.curves.map(curve => {
let length = curve.getLength();
let segs = curve.type === 'LineCurve' ?
@ -65,8 +64,8 @@ function parse(text, opt = { }) {
continue;
}
let geom = new THREE.ExtrudeGeometry(shapes, {
depth,
steps: 1,
depth: parseFloat(depth.value),
bevelEnabled: false
});
let array = geom.attributes.position.array;
@ -101,9 +100,8 @@ function parse(text, opt = { }) {
return nest;
}
let z = parseFloat(depth.value);
for (let poly of nest) {
let obj = poly.extrude(z);
let obj = poly.extrude(depth);
objs.push(obj);
}
}