fix the offsetting issue
This commit is contained in:
parent
825d556e71
commit
c37946f51c
1 changed files with 84 additions and 86 deletions
|
|
@ -81,7 +81,7 @@ class Print {
|
||||||
lastOut.retract = retract;
|
lastOut.retract = retract;
|
||||||
lastOut.widget = this.widget;
|
lastOut.widget = this.widget;
|
||||||
array.push(lastOut);
|
array.push(lastOut);
|
||||||
console.log(structuredClone({lastOut,array}))
|
// console.log("addOutput Called", structuredClone({lastOut,array}))
|
||||||
this.nextType = undefined;
|
this.nextType = undefined;
|
||||||
return lastOut;
|
return lastOut;
|
||||||
}
|
}
|
||||||
|
|
@ -294,14 +294,14 @@ class Print {
|
||||||
E: 0.0
|
E: 0.0
|
||||||
},
|
},
|
||||||
off = {
|
off = {
|
||||||
X: offset ? offset.x || 0 : 0,
|
x: offset ? offset.x || 0 : 0,
|
||||||
Y: offset ? offset.y || 0 : 0,
|
y: offset ? offset.y || 0 : 0,
|
||||||
Z: offset ? offset.z || 0 : 0
|
z: offset ? offset.z || 0 : 0
|
||||||
},
|
},
|
||||||
xoff = {
|
xoff = {
|
||||||
X: 0,
|
x: 0,
|
||||||
Y: 0,
|
y: 0,
|
||||||
Z: 0
|
z: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
let dz = 0,
|
let dz = 0,
|
||||||
|
|
@ -337,21 +337,31 @@ class Print {
|
||||||
*/
|
*/
|
||||||
function processLine(line, axes) {
|
function processLine(line, axes) {
|
||||||
const prevPoint = newPoint(
|
const prevPoint = newPoint(
|
||||||
factor * pos.X + xoff.X,
|
factor * pos.X ,
|
||||||
factor * pos.Y + xoff.Y,
|
factor * pos.Y ,
|
||||||
factor * pos.Z + xoff.Z + dz
|
factor * pos.Z + dz
|
||||||
);
|
)
|
||||||
|
.add(xoff)
|
||||||
|
.add(off);
|
||||||
|
|
||||||
|
// apply origin offset
|
||||||
|
// for (let layer of output) {
|
||||||
|
// for (let rec of layer) {
|
||||||
|
// let point = rec.point;
|
||||||
|
// point.x += off.X;
|
||||||
|
// point.y += off.Y;
|
||||||
|
// point.z += off.Z;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
const point = prevPoint.clone()
|
const point = prevPoint.clone()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
line.forEach(tok => {
|
line.forEach(tok => {
|
||||||
let axis = tok.charAt(0).toUpperCase();
|
let axis = tok.charAt(0).toUpperCase();
|
||||||
if (morph && belt) {
|
if (morph && belt) {
|
||||||
axis = beltaxis[axis];
|
axis = beltaxis[axis];
|
||||||
}
|
}
|
||||||
console.log("position updated",structuredClone(pos))
|
// console.log("position updated",structuredClone(pos))
|
||||||
|
|
||||||
let val = parseFloat(tok.substring(1));
|
let val = parseFloat(tok.substring(1));
|
||||||
axes[axis] = val;
|
axes[axis] = val;
|
||||||
|
|
@ -359,23 +369,23 @@ class Print {
|
||||||
if (abs) {
|
if (abs) {
|
||||||
pos[axis] = val;
|
pos[axis] = val;
|
||||||
|
|
||||||
if (axis == "X") point.x = factor * pos.X + xoff.X
|
if (axis == "X") point.x = factor * pos.X + xoff.x + off.x
|
||||||
else if (axis == "Y") point.y = factor * pos.Y + xoff.Y
|
else if (axis == "Y") point.y = factor * pos.Y + xoff.y + off.y
|
||||||
else if (axis == "Z") point.z = factor * pos.Z + xoff.Z+dz
|
else if (axis == "Z") point.z = factor * pos.Z + xoff.z + off.z + dz
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
mov[axis] = val;
|
mov[axis] = val;
|
||||||
pos[axis] += val;
|
pos[axis] += val;
|
||||||
}
|
}
|
||||||
console.log("position updated",structuredClone(pos))
|
// console.log("position updated",structuredClone(pos))
|
||||||
});
|
});
|
||||||
|
|
||||||
let center;
|
let center;
|
||||||
if(axes.I !== undefined && axes.J !== undefined) {
|
if(axes.I !== undefined && axes.J !== undefined) {
|
||||||
center = newPoint(
|
center = newPoint(
|
||||||
factor* axes.I+ xoff.X,
|
factor* axes.I+ xoff.x,
|
||||||
factor* axes.J+ xoff.Y,
|
factor* axes.J+ xoff.y,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
}else if(axes.R !== undefined) {
|
}else if(axes.R !== undefined) {
|
||||||
|
|
@ -388,7 +398,6 @@ class Print {
|
||||||
if(center){
|
if(center){
|
||||||
center = center.add(prevPoint);
|
center = center.add(prevPoint);
|
||||||
center.setZ((prevPoint.z+point.z)/2+dz);
|
center.setZ((prevPoint.z+point.z)/2+dz);
|
||||||
console.log("center z update",center)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -398,6 +407,48 @@ class Print {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function outputPoint(point,lastP,emit,{center,arcPoints,retract}) {
|
||||||
|
|
||||||
|
// non-move in a new plane means burp out
|
||||||
|
// the old sequence and start a new one
|
||||||
|
|
||||||
|
if (newlayer || (autolayer && seq.z != point.z)) {
|
||||||
|
newlayer = false;
|
||||||
|
let dz = point.z - seq.z;
|
||||||
|
let nh = dz > 0 ? dz : defh;
|
||||||
|
seq = [];
|
||||||
|
seq.height = height = nh;
|
||||||
|
if (fdm) dz = -height / 2;
|
||||||
|
output.push(seq);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasmoved) {
|
||||||
|
seq.height = seq.z = pos.Z;
|
||||||
|
hasmoved = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// debug extrusion rate
|
||||||
|
const lastPos = scope.lastPos;
|
||||||
|
if (scope.debugE && fdm && lastPos && pos.E) {
|
||||||
|
// extruder move
|
||||||
|
let dE = (absE ? pos.E - scope.lastPosE : pos.E);
|
||||||
|
// distance moved in XY
|
||||||
|
let dV = point.distTo2D(lastP);
|
||||||
|
// debug print time
|
||||||
|
time += (dV * pos.F) / 1000;
|
||||||
|
// filament per mm
|
||||||
|
let dR = (dE / dV);
|
||||||
|
if (dV > 2 && dE > 0.001) {
|
||||||
|
let lab = (absE ? 'aA' : 'rR')[scope.debugE++ % 2];
|
||||||
|
console.log(lab, height.toFixed(2), dV.toFixed(2), dE.toFixed(3), dR.toFixed(4), pos.F.toFixed(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// add point to current sequence
|
||||||
|
scope.addOutput(seq, point, emit, pos.F, tool,{retract,arcPoints});
|
||||||
|
scope.lastPos = Object.assign({}, pos);
|
||||||
|
scope.lastPosE = pos.E;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles G2 and G3 arcs, which are circular arcs.
|
* Handles G2 and G3 arcs, which are circular arcs.
|
||||||
* @param {boolean} g2 - Whether this is a G2 or G3 arc. G2 is a clockwise arc, G3 is a counter-clockwise arc.
|
* @param {boolean} g2 - Whether this is a G2 or G3 arc. G2 is a clockwise arc, G3 is a counter-clockwise arc.
|
||||||
|
|
@ -408,16 +459,16 @@ class Print {
|
||||||
const axes = {};
|
const axes = {};
|
||||||
const {point, prevPoint, center} = processLine(line,axes);
|
const {point, prevPoint, center} = processLine(line,axes);
|
||||||
|
|
||||||
console.log(structuredClone({point,prevPoint,center}));
|
// console.log(structuredClone({point,prevPoint,center}));
|
||||||
|
|
||||||
let arcPoints = arcToPath( prevPoint, point, 24,{ clockwise:g2,center}) ?? []
|
let arcPoints = arcToPath( prevPoint, point, 64,{ clockwise:g2,center}) ?? []
|
||||||
let emit = g2 ? 2 : 3;
|
let emit = g2 ? 2 : 3;
|
||||||
|
|
||||||
console.log("clone point",structuredClone({point,prevPoint,center,arcPoints,emit}));
|
// console.log("clone point",structuredClone({point,prevPoint,center,arcPoints,emit}));
|
||||||
console.log("pointer point",{point,prevPoint,center,arcPoints,emit});
|
// console.log("pointer point",{point,prevPoint,center,arcPoints,emit});
|
||||||
|
|
||||||
scope.addOutput(seq, point, emit, pos.F, tool,{arcPoints});
|
outputPoint(point,prevPoint,emit,{center,arcPoints});
|
||||||
scope.lastPos = Object.assign({}, pos);
|
// scope.addOutput(seq, point, emit, pos.F, tool,{center,arcPoints});
|
||||||
}
|
}
|
||||||
|
|
||||||
function G0G1(g0, line) {
|
function G0G1(g0, line) {
|
||||||
|
|
@ -425,7 +476,7 @@ class Print {
|
||||||
const axes = {};
|
const axes = {};
|
||||||
|
|
||||||
lastG = g0 ? 'G0' : 'G1';
|
lastG = g0 ? 'G0' : 'G1';
|
||||||
const {point} = processLine(line,axes);
|
const {point, prevPoint} = processLine(line,axes);
|
||||||
|
|
||||||
if (morph && belt) {
|
if (morph && belt) {
|
||||||
point.y -= point.z * beltfact;
|
point.y -= point.z * beltfact;
|
||||||
|
|
@ -456,61 +507,19 @@ class Print {
|
||||||
|
|
||||||
// always add moves to the current sequence
|
// always add moves to the current sequence
|
||||||
if (moving) {
|
if (moving) {
|
||||||
console.log("move",structuredClone(point))
|
// console.log("move",structuredClone(point))
|
||||||
scope.addOutput(seq, point, false, pos.F, tool).retract = retract;
|
scope.addOutput(seq, point, 0, pos.F, tool,{retract})
|
||||||
scope.lastPos = Object.assign({}, pos);
|
scope.lastPos = Object.assign({}, pos);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (seq.z === undefined) {
|
||||||
if (seq.Z === undefined) {
|
seq.z = point.z;
|
||||||
seq.Z = pos.Z;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fdm && height === 0) {
|
if (fdm && height === 0) {
|
||||||
seq.height = defh = height = pos.Z;
|
seq.height = defh = height = pos.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
// non-move in a new plane means burp out
|
outputPoint(point,prevPoint,1,{retract})
|
||||||
// the old sequence and start a new one
|
|
||||||
if (newlayer || (autolayer && seq.Z != pos.Z)) {
|
|
||||||
newlayer = false;
|
|
||||||
let dz = pos.Z - seq.Z;
|
|
||||||
let nh = dz > 0 ? dz : defh;
|
|
||||||
seq = [];
|
|
||||||
seq.height = height = nh;
|
|
||||||
if (fdm) dz = -height / 2;
|
|
||||||
output.push(seq);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasmoved && !moving) {
|
|
||||||
seq.height = seq.Z = pos.Z;
|
|
||||||
hasmoved = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// debug extrusion rate
|
|
||||||
const lastPos = scope.lastPos;
|
|
||||||
if (scope.debugE && fdm && lastPos && pos.E) {
|
|
||||||
// extruder move
|
|
||||||
let dE = (absE ? pos.E - scope.lastPosE : pos.E);
|
|
||||||
// distance moved in XY
|
|
||||||
let dV = Math.sqrt(
|
|
||||||
(Math.pow(pos.X - lastPos.X, 2)) +
|
|
||||||
(Math.pow(pos.Y - lastPos.Y, 2))
|
|
||||||
);
|
|
||||||
// debug print time
|
|
||||||
time += (dV * pos.F) / 1000;
|
|
||||||
// filament per mm
|
|
||||||
let dR = (dE / dV);
|
|
||||||
if (dV > 2 && dE > 0.001) {
|
|
||||||
let lab = (absE ? 'aA' : 'rR')[scope.debugE++ % 2];
|
|
||||||
console.log(lab, height.toFixed(2), dV.toFixed(2), dE.toFixed(3), dR.toFixed(4), pos.F.toFixed(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// add point to current sequence
|
|
||||||
console.log("cut",structuredClone(point))
|
|
||||||
scope.addOutput(seq, point, true, pos.F, tool).retract = retract;
|
|
||||||
scope.lastPos = Object.assign({}, pos);
|
|
||||||
scope.lastPosE = pos.E;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const linemod = cam ? Math.ceil(lines.length / 2500) : 0;
|
const linemod = cam ? Math.ceil(lines.length / 2500) : 0;
|
||||||
|
|
@ -602,17 +611,6 @@ class Print {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// apply origin offset
|
|
||||||
for (let layer of output) {
|
|
||||||
for (let rec of layer) {
|
|
||||||
let point = rec.point;
|
|
||||||
point.x += off.X;
|
|
||||||
point.y += off.Y;
|
|
||||||
point.z += off.Z;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
scope.imported = gcode;
|
scope.imported = gcode;
|
||||||
scope.lines = lines.length;
|
scope.lines = lines.length;
|
||||||
scope.bytes = gcode.length;
|
scope.bytes = gcode.length;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue