From fca2bb7a59149f098111d4d7a30b60fa63d9c8cf Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Fri, 9 Jan 2026 19:50:03 -0500 Subject: [PATCH] fix NaN estimates with non printing layers --- src/kiri/mode/fdm/work/export.js | 30 ++++++++--------------------- src/kiri/mode/fdm/work/init-work.js | 8 ++++++-- src/kiri/mode/fdm/work/prepare.js | 2 ++ 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/kiri/mode/fdm/work/export.js b/src/kiri/mode/fdm/work/export.js index 06fff1b5..4ba3cd24 100644 --- a/src/kiri/mode/fdm/work/export.js +++ b/src/kiri/mode/fdm/work/export.js @@ -349,6 +349,7 @@ export function fdm_export(print, online, ondone, ondebug) { if (line.indexOf('G92') === 0) { line.split(";")[0].split(' ').forEach(function (tok) { let val = parseFloat(tok.substring(1) || 0) || 0; + if (isNaN(val)) console.log(val, line); switch (tok[0]) { case 'X': pos.x = val; break; case 'Y': pos.y = val; break; @@ -357,15 +358,17 @@ export function fdm_export(print, online, ondone, ondebug) { } }); } - if (line.indexOf('E') > 0) { - line.split(";")[0].split(' ').forEach(function (tok) { + if (line.indexOf('E') > 0 && line[0] === 'G') { + line.split(";")[0].split(' ').forEach((tok) => { // use max E position from gcode-preamble if (tok[0] == 'E') { + let etok = parseFloat(tok.substring(1) || 0); + if (isNaN(etok)) console.log(line); if (extrudeAbs) { - outputLength = Math.max(outputLength, parseFloat(tok.substring(1)) || 0); + outputLength = Math.max(outputLength, etok); emitted = outputLength; } else { - emitted += parseFloat(tok.substring(1) || 0); + emitted += etok; } } }); @@ -423,24 +426,6 @@ export function fdm_export(print, online, ondone, ondebug) { time += (retDist / retSpeed) * 60 * 2; // retraction time } - let taxis = new THREE.Vector3( 1, 0, 0 ); - let tcent = new THREE.Vector2( 0, 0 ); - let angle = -Math.PI / 4; - let savePos = pos; - - function pushPos(newpos, rate, comment) { - savePos = Object.clone(pos); - moveTo({ - x: newpos.x + offset.x, - y: newpos.y + offset.y, - z: newpos.z + offset.z - }, rate, comment); - } - - function popPos(rate, comment) { - moveTo(savePos, rate, comment); - } - function moveTo(newpos, rate, comment, arc) { let o = arc ? [arc.clockwise ? 'G2' : 'G3'] : @@ -656,6 +641,7 @@ export function fdm_export(print, online, ondone, ondebug) { extruder = extruders[tool]; offset_x = extruder.extOffsetX; offset_y = extruder.extOffsetY; + emitPerMM = extrudePerMM( lineWidth || extruder.extNozzle, extruder.extFilament, diff --git a/src/kiri/mode/fdm/work/init-work.js b/src/kiri/mode/fdm/work/init-work.js index a3d699f7..36686765 100644 --- a/src/kiri/mode/fdm/work/init-work.js +++ b/src/kiri/mode/fdm/work/init-work.js @@ -10,6 +10,9 @@ import { codec } from '../../../core/codec.js'; // fil = filament diameter // slice = slice height function extrudePerMM(noz, fil, slice) { + // if (isNaN(noz)) console.trace({ noz }); + // if (isNaN(fil)) console.trace({ fil }); + // if (isNaN(slice)) console.trace({ slice }); // (ratio of nozzle to filament) * (ratio of slice to nozzle) return ((Math.PI * util.sqr(noz / 2)) / (Math.PI * util.sqr(fil / 2))) * (slice / noz); }; @@ -18,12 +21,14 @@ function extrudePerMM(noz, fil, slice) { // perMM = amount extruded per MM (from extrudePerMM) // factor = scaling factor (usually 1.0) function extrudeMM(dist, perMM, factor) { + // if (isNaN(dist)) console.trace({ dist }); + // if (isNaN(perMM)) console.trace({ perMM }); + // if (isNaN(factor)) console.trace({ factor }); return dist * perMM * factor; } // defer loading until client and worker exist function init(worker) { - // worker.dispatch.fdm_support_generate = function(data, send) { // const { settings } = data; // const widgets = Object.values(worker.cache); @@ -33,7 +38,6 @@ function init(worker) { // supports: widget.supports, // } } ))); // }; - } export const FDM = { diff --git a/src/kiri/mode/fdm/work/prepare.js b/src/kiri/mode/fdm/work/prepare.js index 82575f0f..5ab342a5 100644 --- a/src/kiri/mode/fdm/work/prepare.js +++ b/src/kiri/mode/fdm/work/prepare.js @@ -608,7 +608,9 @@ export async function fdm_prepare(widgets, settings, update) { layerout.layer = layerno++; update((layerno / cake.length) * 0.5, "prepare"); + // clear for next layer layerout = []; + layerout.height = sliceHeight; } print.output = output;