From 1bdea68a0082c25c3f48af892a5b0dcdf40392dc Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Wed, 17 Nov 2021 13:46:01 -0500 Subject: [PATCH] fix starting extruder for anchors, purge tower scaling on belt --- src/kiri/export.js | 22 ++++++++---- src/kiri/init.js | 2 +- src/mode/fdm/prepare.js | 74 +++++++++++++++++++++-------------------- src/mode/fdm/slice.js | 1 + 4 files changed, 55 insertions(+), 44 deletions(-) diff --git a/src/kiri/export.js b/src/kiri/export.js index 70ce6c9a..1cea307c 100644 --- a/src/kiri/export.js +++ b/src/kiri/export.js @@ -470,17 +470,25 @@ console.log/** Copyright Stewart Allen -- All Rights Reserved */ let driveInfo = {}; let volume = {}; let length = {}; + // clean up and round pings + pings.forEach(p => { + p.length = p.length.round(2); + p.extrusion = p.extrusion.round(2); + }); // add length push filament to the last segment - // console.log({device, pinfo}); segments.peek().emitted += pinfo.push; + let lastEmit = 0; for (let seg of segments) { let seginfo = driveInfo[seg.tool] = driveInfo[seg.tool] || { length: 0, volume: 0 }; - seginfo.length += seg.emitted; - seginfo.volume += seg.emitted * Math.PI; - volume[seg.tool+1] = seginfo.volume + 2; // prepad 2mm - length[seg.tool+1] = seginfo.length; + seginfo.length += seg.emitted - lastEmit; + seginfo.volume = seginfo.length * Math.PI; + volume[seg.tool+1] = (seginfo.volume + 2).round(2); // prepad 2mm + length[seg.tool+1] = seginfo.length.round(2); + lastEmit = seg.emitted; } - let totalVolume = Object.values(volume).reduce((a,v) => a+v); + let totalLength = Object.values(length).reduce((a,v) => a+v).round(2); + let totalVolume = Object.values(volume).reduce((a,v) => a+v).round(2); + // console.log({info, device, pinfo, segments, volume, length, totalLength}); let meta = { version: "3.2", printerProfile: { @@ -554,7 +562,7 @@ console.log/** Copyright Stewart Allen -- All Rights Reserved */ KIRI.work.png({}, data => { png = data.png; }); - // console.log({meta,palette}); + console.log({meta,palette}); downloadPalette.onclick = function() { KIRI.client.zip([ {name:"meta.json", data:JSON.stringify(meta,undefined,4)}, diff --git a/src/kiri/init.js b/src/kiri/init.js index d81d50d4..18f852e8 100644 --- a/src/kiri/init.js +++ b/src/kiri/init.js @@ -1666,7 +1666,7 @@ ], {modes:FDM, class:"dev-buttons ext-buttons"}), palette: UC.newGroup(LANG.dv_gr_pal, $('palette3'), {group:"dext", inline:true, modes:FDM}), - paletteId: UC.newInput(LANG.dv_paid_s, {title:LANG.dv_paid_l, modes:FDM, size:15}), + paletteId: UC.newInput(LANG.dv_paid_s, {title:LANG.dv_paid_l, modes:FDM, size:15, text:true}), palettePing: UC.newInput(LANG.dv_paps_s, {title:LANG.dv_paps_l, modes:FDM, convert:UC.toInt}), paletteFeed: UC.newInput(LANG.dv_pafe_s, {title:LANG.dv_pafe_l, modes:FDM, convert:UC.toInt}), palettePush: UC.newInput(LANG.dv_papl_s, {title:LANG.dv_papl_l, modes:FDM, convert:UC.toInt}), diff --git a/src/mode/fdm/prepare.js b/src/mode/fdm/prepare.js index acca1c2c..ca099a8e 100644 --- a/src/mode/fdm/prepare.js +++ b/src/mode/fdm/prepare.js @@ -244,40 +244,42 @@ } // determine size/location of purge blocks - let blokw = Math.sqrt(purgeTower), - blokh = blokw; - let stepw = blokw + nozzle / 2; + let blokw = Math.sqrt(purgeTower); + let blokh = blokw; let blokpos, walkpos, blok; - if (bounds.min.x < bounds.min.y && !isBelt) { - let mx = (bounds.max.x + bounds.min.x) / 2; - let px = mx - (extcount * blokw) / 2 + (blokw / 2); - let dx = ((bounds.max.x - bounds.min.x) - (extcount * blokw)) / 2; - blokpos = { x:px, y: bounds.max.y + 2 + blokh / 2}; - walkpos = { x:stepw, y:0 }; - blok = { x:blokw, y:blokh }; - } else { - let my = (bounds.max.y + bounds.min.y) / 2; - let mp = (extcount * blokw) / 2 + (blokw / 2); - let py = my - mp; - blokpos = { x:bounds.max.x + 2 + blokh / 2, y:isBelt ? -mp : py}; - walkpos = { x:0, y:stepw }; - blok = { x:blokh, y:blokw }; + function mkblok(w,h) { + let stepw = w + nozzle / 2; + if (bounds.min.x < bounds.min.y && !isBelt) { + let mx = (bounds.max.x + bounds.min.x) / 2; + let px = mx - (extcount * w) / 2 + (w / 2); + let dx = ((bounds.max.x - bounds.min.x) - (extcount * w)) / 2; + blokpos = { x:px, y: bounds.max.y + 2 + h / 2}; + walkpos = { x:stepw, y:0 }; + blok = { x:w, y:h }; + } else { + let my = (bounds.max.y + bounds.min.y) / 2; + let mp = (extcount * w) / 2 + (w / 2); + let py = my - mp; + blokpos = { x:bounds.max.x + 2 + h / 2, y:isBelt ? -mp : py}; + walkpos = { x:0, y:stepw }; + blok = { x:h, y:w }; + } } - // replace extruders array with object array containing more info - extruders = extruders.map((ext,i) => { - if (!ext) return ext; + function mkrec(i, angle = 45) { + blokpos.x += walkpos.x * i; + blokpos.y += walkpos.y * i; let exi = device.extruders[i], noz = exi.extNozzle, pos = {x:blokpos.x, y:blokpos.y, z:0}, rect = newPolygon().centerRectangle(pos, blok.x, blok.y), full = linesToPoly(POLY.fillArea([ newPolygon().centerRectangle(pos, blok.x - noz, blok.y - noz) - ], 45, noz)), + ], angle, noz)), sparse = linesToPoly(POLY.fillArea([ newPolygon().centerRectangle(pos, blok.x - noz, blok.y - noz) - ], 135, noz * 5)), + ], angle + 90, noz * 5)), rec = { extruder: i, diameter: exi.extNozzle, @@ -285,9 +287,14 @@ full, sparse }; - blokpos.x += walkpos.x; - blokpos.y += walkpos.y; return rec; + } + + mkblok(blokw, blokh); + + // replace extruders array with object array containing more info + extruders = extruders.map((ext,i) => { + return ext ? mkrec(i) : ext; }); function linesToPoly(points) { @@ -326,19 +333,14 @@ layer.last().retract = true; } let purgeOn = (!isBelt && first) || !thin; + if (isBelt && z < 0) { + let scale = 1 + ((z / blokw)); + mkblok(blokw * scale, blokh); + rec = mkrec(rec.extruder, 0); + } let box = rec.rect.clone().setZ(z); - let fill = (purgeOn ? rec.full : rec.sparse).clone().setZ(z); + let fill = (z >= 0 && purgeOn ? rec.full : rec.sparse).clone().setZ(z); if (isBelt) { - let scale = z >= 0 ? 0 : 1 + ((z / blokw)); - if (scale) { - box.scale({x:1, y:scale, z:1}); - let inset = box.offset(rec.diameter/2); - if (inset) { - fill = linesToPoly(POLY.fillArea(inset, 90, rec.diameter * 5)); - } else { - fill = undefined; - } - } // offset by nozzle diameter + half step (shell) then angled let exo = rec.diameter * beltfact * 1.5; box.move({x:0, y:z - exo, z:0}); @@ -354,7 +356,7 @@ simple: true, open: false, }); - if (fill) start = print.polyPrintPath(fill, start, layer, { + if (fill && fill.length) start = print.polyPrintPath(fill, start, layer, { tool, rate, simple: true, diff --git a/src/mode/fdm/slice.js b/src/mode/fdm/slice.js index 567c9d0c..ecaf937b 100644 --- a/src/mode/fdm/slice.js +++ b/src/mode/fdm/slice.js @@ -390,6 +390,7 @@ let addto = start.down; if (!addto) { addto = newSlice(start.z - sliceHeight); + addto.extruder = extruder; addto.belt = { }; addto.height = start.height; addto.up = start;