fix gcode parsing for contours

This commit is contained in:
Stewart Allen 2020-11-11 18:07:53 -05:00
commit de17fe597b
2 changed files with 32 additions and 19 deletions

View file

@ -129,7 +129,21 @@
const output = scope.output = [ seq ];
function G0G1(moving) {
function G0G1(moving, line) {
const mov = {};
line.forEach(function(tok) {
if (abs) {
pos[tok.charAt(0)] = parseFloat(tok.substring(1));
} else {
mov[tok.charAt(0)] = parseFloat(tok.substring(1));
}
});
if (!abs) {
for (let [k,v] of Object.entries(mov)) {
pos[k] += v;
}
}
if (pos.X) bounds.min.x = Math.min(bounds.min.x, pos.X * factor);
if (pos.X) bounds.max.x = Math.max(bounds.max.x, pos.X * factor);
if (pos.Y) bounds.min.y = Math.min(bounds.min.y, pos.Y * factor);
@ -201,23 +215,10 @@
abs = false;
break;
case 'G0':
G0G1(true);
G0G1(true, line);
break;
case 'G1':
const mov = {};
line.forEach(function(tok) {
if (abs) {
pos[tok.charAt(0)] = parseFloat(tok.substring(1));
} else {
mov[tok.charAt(0)] = parseFloat(tok.substring(1));
}
});
if (!abs) {
for (let [k,v] of Object.entries(mov)) {
pos[k] += v;
}
}
G0G1(fdm ? pos.E <= 0 : false);
G0G1(fdm ? pos.E <= 0 : false, line);
break;
case 'M6':
break;

View file

@ -94,7 +94,8 @@
hiddenKey,
vizChange,
docVisible = true,
lastAction = Date.now();
lastAction = Date.now(),
fps = 0;
if (typeof DOC.hidden !== "undefined") {
hiddenKey = "hidden";
@ -842,7 +843,8 @@
load: function(cam) { viewControl.setPosition(cam) },
save: function() { return viewControl.getPosition(true) },
panTo: function(x,y,z) { tweenCamPan(x,y,z) },
setZoom: function(r,v) { viewControl.setZoom(r,v) }
setZoom: function(r,v) { viewControl.setZoom(r,v) },
getFPS: function() { return fps }
},
mouse: {
@ -970,9 +972,19 @@
'touchend', updateLastAction
]);
let animating = true;
let animates = 0;
let rateStart = Date.now();
function animate() {
animates++;
const now = Date.now();
if (now - rateStart > 1000) {
const delta = now - rateStart;
fps = 1000 * animates / delta;
animates = 0;
rateStart = now;
}
requestAnimationFrame(animate);
if (docVisible && !freeze && Date.now() - lastAction < 1500) {
renderer.render(SCENE, camera);