add optional dpi parameter to svg import #299
This commit is contained in:
parent
1a1a17a9bb
commit
13e2fc471c
7 changed files with 15 additions and 34 deletions
|
|
@ -614,33 +614,9 @@ class Polygon {
|
|||
return ap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} [point] return just the center point
|
||||
* @returns {Polygon|Point} a new polygon centered on x=0, y=0, z=0
|
||||
*/
|
||||
// TODO: review usage
|
||||
center(point) {
|
||||
return this.bounds.center(this.getZ());
|
||||
// throw "does not work";
|
||||
let ap = newPoint(0, 0, 0, null),
|
||||
np = newPolygon(),
|
||||
pa = this.points;
|
||||
pa.forEach(function(p) {
|
||||
ap.x += p.x;
|
||||
ap.y += p.y;
|
||||
ap.z += p.z;
|
||||
});
|
||||
ap.x /= pa.length;
|
||||
ap.y /= pa.length;
|
||||
ap.z /= pa.length;
|
||||
if (point) return ap;
|
||||
pa.forEach(function(p) {
|
||||
np.push(newPoint(
|
||||
p.x - ap.x,
|
||||
p.y - ap.y,
|
||||
p.z - ap.z
|
||||
));
|
||||
});
|
||||
return np;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ gapp.register("kiri.main", [], (root, exports) => {
|
|||
is_wedm() { return MODE === MODES.WEDM },
|
||||
is_wjet() { return MODE === MODES.WJET },
|
||||
is_laser() { return MODE === MODES.LASER },
|
||||
is_2d() { return
|
||||
is_2d() { return false ||
|
||||
api.mode.is_drag() ||
|
||||
api.mode.is_wedm() ||
|
||||
api.mode.is_wjet() ||
|
||||
|
|
|
|||
|
|
@ -878,14 +878,14 @@ function loadSVGDialog(doit) {
|
|||
"<div class='f-col a-center'>",
|
||||
" <h3>Import SVG</h3>",
|
||||
" <p class='t-just' style='width:300px;line-height:1.5em'>",
|
||||
" This will create a 3D model from 2D SVG vectors.",
|
||||
" Extrude a 3D model from a 2D SVG.",
|
||||
" Fonts must be converted to paths in an SVG editor.",
|
||||
" 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 title='minimum number of segments in an arc. helps better represent small arcs'>minimum arc segments</th><td><input id='svg-marc' value='10' size='3'></td></tr>",
|
||||
" <tr><th title='interpret dimensions as pixels using dpi'>pixel dpi (optional)</th><td><input id='svg-dpi' value='0' size='3'></td></tr>",
|
||||
" <tr><th>nest shapes</th><td><input id='svg-nest' value='1' type='checkbox' checked></td></tr>",
|
||||
" </table></div>",
|
||||
"</div>"
|
||||
|
|
@ -894,8 +894,9 @@ function loadSVGDialog(doit) {
|
|||
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 sdpi = Math.max(0, parseInt($('svg-dpi').value));
|
||||
let soup = $('svg-nest').checked;
|
||||
ok && doit({ soup, resolution: arcs, segmin: marc, depth });
|
||||
ok && doit({ soup, resolution: arcs, segmin: marc, depth, dpi: sdpi });
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -433,7 +433,7 @@ let overrides = {};
|
|||
|
||||
// updates editable fields that are range dependent
|
||||
function updateFieldsFromRange() {
|
||||
return;
|
||||
if (true) return;
|
||||
if (settings.mode !== 'FDM' || !api.view.is_slice() || !settings.process.ranges) {
|
||||
let okeys = Object.keys(overrides);
|
||||
if (okeys.length) {
|
||||
|
|
|
|||
|
|
@ -20,13 +20,15 @@ function parse(text, opt = { }) {
|
|||
const justPoly = opt.flat || false;
|
||||
const fromSoup = opt.soup !== false || justPoly;
|
||||
const rez = (opt.resolution || 1);
|
||||
const dpi = (opt.dpi || 0);
|
||||
const segmin = Math.max(1, opt.segmin || 10);
|
||||
const objs = [];
|
||||
const data = new THREE.SVGLoader().parse(text);
|
||||
const paths = data.paths;
|
||||
const xmlat = data.xml.attributes;
|
||||
const polys = fromSoup ? [] : undefined;
|
||||
const scale = xmlat.width?.value.endsWith('in') ? 25.4 : 1;
|
||||
const isinch = xmlat.width?.value.endsWith('in');
|
||||
const scale = isinch ? 25.4 : (dpi ? 1 / (dpi / 25.4) : 1);
|
||||
const depth = parseFloat(opt.depth || xmlat['data-km-extrude']?.value
|
||||
|| xmlat['extrude']?.value
|
||||
|| 5);
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@
|
|||
<span id="tool-mesh"><i class="fas fa-dice-d20"></i>
|
||||
<div id="ft-mesh" class="grow f-col pop">
|
||||
<div id="ft-mesh-btn">
|
||||
<div><button id="mesh-merge" lk="rc_merge">Merge</button></div>
|
||||
<div><button id="mesh-merge" lk="rc_merg">Merge</button></div>
|
||||
<div><button id="mesh-export-obj" lk="rc_xobj">export OBJ</button></div>
|
||||
<div><button id="mesh-export-stl" lk="rc_xstl">export STL</button></div>
|
||||
</div>
|
||||
|
|
@ -550,7 +550,7 @@
|
|||
<div class="f-row">
|
||||
<button id="tool-add"><i class="fas fa-plus"></i></button>
|
||||
<button id="tool-dup" lk="clone">copy</button>
|
||||
<button id="tool-del"><i class="fas fa-minus"></i></button>
|
||||
<button id="tool-del"><i class="fas fa-minus"></i></button>
|
||||
</div>
|
||||
<div class="f-row">
|
||||
<button id="tools-save" lk="save">save</button>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ self.kiri.lang['en-us'] = {
|
|||
back: "back",
|
||||
clear: "clear", // clear workspace (remove all objects)
|
||||
copy: "copy",
|
||||
clone: "clone", // create duplicate
|
||||
delete: "delete",
|
||||
detail: "detail",
|
||||
done: "done",
|
||||
|
|
@ -74,6 +75,7 @@ self.kiri.lang['en-us'] = {
|
|||
rc_xobj: "export OBJ",
|
||||
rc_xstl: "export STL",
|
||||
sb_info: ["print speed","in mm/s"],
|
||||
rc_merg: "merge object meshes",
|
||||
|
||||
// DEVICE MENU and related dialogs
|
||||
dm_sldt: "select a device type",
|
||||
|
|
|
|||
Loading…
Reference in a new issue