fix NaN estimates with non printing layers

This commit is contained in:
Stewart Allen 2026-01-09 19:50:03 -05:00
commit fca2bb7a59
3 changed files with 16 additions and 24 deletions

View file

@ -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,

View file

@ -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 = {

View file

@ -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;