restore gcode preview. bump rev 2.3.D4
This commit is contained in:
parent
cea9e60e0a
commit
fff3ad5db6
11 changed files with 113 additions and 221 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "grid-apps",
|
||||
"version": "2.3.D3",
|
||||
"version": "2.3.D4",
|
||||
"description": "grid.space 3d slice & modeling tools",
|
||||
"author": "Stewart Allen <sa@grid.space>",
|
||||
"license": "MIT",
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ KIRI.work = {
|
|||
},
|
||||
|
||||
prepare : function(settings, update, done) {
|
||||
send("prepare", {settings:settings}, function(reply) {
|
||||
send("prepare", { settings }, function(reply) {
|
||||
if (reply.progress) {
|
||||
update(reply.progress, reply.message);
|
||||
}
|
||||
|
|
@ -172,8 +172,7 @@ KIRI.work = {
|
|||
},
|
||||
|
||||
export : function(settings, online, ondone) {
|
||||
let lines = [];
|
||||
send("export", {settings:settings}, function(reply) {
|
||||
send("export", { settings }, function(reply) {
|
||||
if (reply.line) {
|
||||
online(reply.line);
|
||||
}
|
||||
|
|
@ -183,16 +182,13 @@ KIRI.work = {
|
|||
});
|
||||
},
|
||||
|
||||
gcode : function(callback) {
|
||||
let gcode = [];
|
||||
let start = BASE.util.time();
|
||||
send("gcode", {}, function(reply) {
|
||||
if (reply.line) {
|
||||
gcode.push(reply.line);
|
||||
} else {
|
||||
if (!reply.gcode) reply.gcode = gcode.join("\n");
|
||||
// console.log({printGCode:(BASE.util.time() - start)});
|
||||
callback(reply);
|
||||
parse : function(args, progress, done) {
|
||||
send("parse", args, function(reply) {
|
||||
if (reply.progress) {
|
||||
progress(reply);
|
||||
}
|
||||
if (reply.parsed) {
|
||||
done(KIRI.codec.decode(reply.parsed));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -628,31 +628,20 @@
|
|||
}
|
||||
|
||||
function loadCode(code, type) {
|
||||
return alert2('currently unavailable');
|
||||
|
||||
setViewMode(VIEWS.PREVIEW);
|
||||
setOpacity(0);
|
||||
currentPrint = kiri.newPrint(settings, []);
|
||||
let center = settings.process.outputOriginCenter;
|
||||
let origin = settings.origin;
|
||||
let offset = {
|
||||
x: origin.x,
|
||||
y: -origin.y,
|
||||
z: origin.z
|
||||
};
|
||||
switch (type) {
|
||||
case 'svg':
|
||||
currentPrint.parseSVG(code, offset);
|
||||
break;
|
||||
default:
|
||||
currentPrint.parseGCode(code, offset);
|
||||
break;
|
||||
}
|
||||
currentPrint.render();
|
||||
SPACE.platform.add(currentPrint.group);
|
||||
SPACE.update();
|
||||
updateSliderMax(true);
|
||||
showSlices();
|
||||
|
||||
KIRI.client.parse({code, type, settings}, progress => {
|
||||
API.show.progress(progress, "parsing");
|
||||
}, layers => {
|
||||
API.show.progress(0);
|
||||
STACKS.clear();
|
||||
const stack = STACKS.create('parse', SPACE.platform.world);
|
||||
layers.forEach(layer => stack.add(layer));
|
||||
updateSliderMax(true);
|
||||
showSlices();
|
||||
SPACE.update();
|
||||
});
|
||||
}
|
||||
|
||||
function cancelWorker() {
|
||||
|
|
|
|||
|
|
@ -52,12 +52,8 @@
|
|||
this.distance = 0;
|
||||
this.bounds = null;
|
||||
this.imported = null;
|
||||
|
||||
// this.hsv2rgb = hsv2rgb;
|
||||
}
|
||||
|
||||
Print.hsv2rgb = hsv2rgb;
|
||||
|
||||
PRO.addOutput = addOutput;
|
||||
PRO.tip2tipEmit = tip2tipEmit;
|
||||
PRO.extrudePerMM = extrudePerMM;
|
||||
|
|
@ -97,7 +93,7 @@
|
|||
scope.bytes = code.length;
|
||||
};
|
||||
|
||||
PRO.parseGCode = function(gcode, offset) {
|
||||
PRO.parseGCode = function(gcode, offset, progress, done) {
|
||||
let lines = gcode
|
||||
.toUpperCase()
|
||||
.replace("X", " X")
|
||||
|
|
@ -191,11 +187,11 @@
|
|||
}
|
||||
addOutput(
|
||||
seq,
|
||||
{
|
||||
x:(factor * pos.X + off.X + xoff.X),
|
||||
y:(factor * pos.Y + off.Y + xoff.Y),
|
||||
z:(factor * pos.Z + off.Z + xoff.Z)
|
||||
},
|
||||
newPoint(
|
||||
factor * pos.X + off.X + xoff.X,
|
||||
factor * pos.Y + off.Y + xoff.Y,
|
||||
factor * pos.Z + off.Z + xoff.Z
|
||||
),
|
||||
!move,
|
||||
pos.F,
|
||||
tool
|
||||
|
|
@ -214,138 +210,14 @@
|
|||
scope.imported = gcode;
|
||||
scope.lines = lines.length;
|
||||
scope.bytes = gcode.length;
|
||||
|
||||
done(scope.output);
|
||||
};
|
||||
|
||||
function pref(a,b) {
|
||||
return a !== undefined ? a : b;
|
||||
}
|
||||
|
||||
function rgb2hsv(ir, ig, ib) {
|
||||
let H = 0,
|
||||
S = 0,
|
||||
V = 0,
|
||||
r = ir / 255,
|
||||
g = ig / 255,
|
||||
b = ib / 255;
|
||||
|
||||
let minRGB = Math.min(r, Math.min(g, b)),
|
||||
maxRGB = Math.max(r, Math.max(g, b));
|
||||
|
||||
// Black-gray-white
|
||||
if (minRGB == maxRGB) {
|
||||
V = minRGB;
|
||||
return [0, 0, V];
|
||||
}
|
||||
|
||||
// Colors other than black-gray-white:
|
||||
let d = (r == minRGB) ? g - b : ((b == minRGB) ? r - g : b - r),
|
||||
h = (r == minRGB) ? 3 : ((b == minRGB) ? 1 : 5);
|
||||
|
||||
H = 60 * (h - d / (maxRGB - minRGB));
|
||||
S = (maxRGB - minRGB) / maxRGB;
|
||||
V = maxRGB;
|
||||
|
||||
return [H, S, V];
|
||||
}
|
||||
|
||||
function hsl2rgb(h, s, l) {
|
||||
let r, g, b;
|
||||
|
||||
if (s == 0) {
|
||||
r = g = b = l; // achromatic
|
||||
} else {
|
||||
let hue2rgb = function hue2rgb(p, q, t) {
|
||||
if (t < 0) t += 1;
|
||||
if (t > 1) t -= 1;
|
||||
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
||||
if (t < 1 / 2) return q;
|
||||
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
||||
return p;
|
||||
}
|
||||
|
||||
let q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
||||
let p = 2 * l - q;
|
||||
r = hue2rgb(p, q, h + 1 / 3);
|
||||
g = hue2rgb(p, q, h);
|
||||
b = hue2rgb(p, q, h - 1 / 3);
|
||||
}
|
||||
|
||||
const rgb =
|
||||
(((r * 255) & 0xff) << 16) |
|
||||
(((g * 255) & 0xff) << 8) |
|
||||
((b * 255) & 0xff);
|
||||
|
||||
return rgb;
|
||||
}
|
||||
|
||||
// hsv values all = 0 to 1
|
||||
function hsv2rgb(hsv, hex) {
|
||||
let seg = Math.floor(hsv.h * 6),
|
||||
rem = hsv.h - (seg * (1/6)),
|
||||
p = hsv.v * (1.0 - (hsv.s)),
|
||||
q = hsv.v * (1.0 - (hsv.s * rem)),
|
||||
t = hsv.v * (1.0 - (hsv.s * (1.0 - rem))),
|
||||
out = {};
|
||||
switch (seg) {
|
||||
case 0:
|
||||
out.r = hsv.v;
|
||||
out.g = t;
|
||||
out.b = p;
|
||||
break;
|
||||
case 1:
|
||||
out.r = q;
|
||||
out.g = hsv.v;
|
||||
out.b = p;
|
||||
break;
|
||||
case 2:
|
||||
out.r = p;
|
||||
out.g = hsv.v;
|
||||
out.b = t;
|
||||
break;
|
||||
case 3:
|
||||
out.r = p;
|
||||
out.g = q;
|
||||
out.b = hsv.v;
|
||||
break;
|
||||
case 4:
|
||||
out.r = t;
|
||||
out.g = p;
|
||||
out.b = hsv.v;
|
||||
break;
|
||||
case 5:
|
||||
out.r = hsv.v;
|
||||
out.g = p;
|
||||
out.b = q;
|
||||
break;
|
||||
}
|
||||
|
||||
// if (hex) return hsl2rgb(hsv.h, hsv.s, hsv.v);
|
||||
|
||||
return hex ? (
|
||||
(((out.r * 255) & 0xff) << 16) |
|
||||
(((out.g * 255) & 0xff) << 8) |
|
||||
((out.b * 255) & 0xff)
|
||||
) : out;
|
||||
}
|
||||
|
||||
// PRO.getLayerCount = function() {
|
||||
// return this.output.length;
|
||||
// }
|
||||
|
||||
// PRO.hide = function() {
|
||||
// this.printView.forEach(function(layer) {
|
||||
// layer.setVisible(false);
|
||||
// })
|
||||
// this.movesView.forEach(function(layer) {
|
||||
// layer.setVisible(false);
|
||||
// })
|
||||
// };
|
||||
//
|
||||
// PRO.showLayer = function(index, show, moves) {
|
||||
// if (this.printView[index]) this.printView[index].setVisible(show);
|
||||
// if (this.movesView[index]) this.movesView[index].setVisible(show && moves);
|
||||
// };
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
|
|
@ -376,18 +248,6 @@
|
|||
array.push(new Output(point, emit, speed, tool));
|
||||
}
|
||||
|
||||
// function segmentedOutput(output, p1, p2, s1, s2, steps, mult) {
|
||||
// let sd = (s2 - s1) / (steps + 1);
|
||||
// let dd = p1.distTo2D(p2) / steps;
|
||||
// let dist = dd;
|
||||
// let spd = s1;
|
||||
// while (steps-- > 0) {
|
||||
// spd += sd;
|
||||
// p1 = p1.offsetPointTo(p2, dd);
|
||||
// addOutput(output, p1, mult, spd);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* FDM & Laser. add points in polygon to an output array (print path)
|
||||
*
|
||||
|
|
|
|||
|
|
@ -22,21 +22,20 @@
|
|||
labels = $("layers");
|
||||
API = KIRI.api,
|
||||
UC = API.uc,
|
||||
UI = API.ui,
|
||||
DYN = UI.dyn = {};
|
||||
UI = API.ui;
|
||||
}
|
||||
|
||||
function clear() {
|
||||
if (!API) {
|
||||
init();
|
||||
}
|
||||
|
||||
// remove stacks from their views
|
||||
for (const [stack, data] of Object.entries(stacks)) {
|
||||
data.clear();
|
||||
}
|
||||
min = max = tallest = 0;
|
||||
stacks = {};
|
||||
DYN = UI.dyn = {};
|
||||
|
||||
// clear labels
|
||||
UC.setGroup(labels);
|
||||
|
|
@ -96,6 +95,7 @@
|
|||
|
||||
for (const [label, data] of Object.entries(render.layers)) {
|
||||
if (!DYN[label]) {
|
||||
console.log('new label', label);
|
||||
DYN[label] = {
|
||||
group: [],
|
||||
toggle: UC.newBoolean(label, (abc) => {
|
||||
|
|
|
|||
|
|
@ -629,7 +629,7 @@
|
|||
PRO.render = function(stack) {
|
||||
const mark = Date.now();
|
||||
this.slices.forEach(slice => {
|
||||
stack.add(slice.render);
|
||||
if (slice.render) stack.add(slice.render);
|
||||
});
|
||||
return Date.now() - mark;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -153,18 +153,24 @@ KIRI.worker = {
|
|||
});
|
||||
},
|
||||
|
||||
gcode: function(data, send) {
|
||||
current.print.exportGCode(false, function(gcode) {
|
||||
send.done({
|
||||
gcode: gcode,
|
||||
lines: current.print.lines,
|
||||
bytes: current.print.bytes,
|
||||
bounds: current.print.bounds,
|
||||
distance: current.print.distance,
|
||||
time: current.print.time
|
||||
});
|
||||
}, function(line) {
|
||||
send.data({line:line});
|
||||
parse: function(args, send) {
|
||||
const { settings, code, type } = args;
|
||||
const center = settings.process.outputOriginCenter;
|
||||
const origin = settings.origin;
|
||||
const offset = {
|
||||
x: origin.x,
|
||||
y: -origin.y,
|
||||
z: origin.z
|
||||
};
|
||||
const print = KIRI.newPrint(settings, Object.values(cache));
|
||||
|
||||
const parsed = print.parseGCode(code, offset, progress => {
|
||||
send.data({progress});
|
||||
}, done => {
|
||||
const layers = KIRI.driver.FDM.prepareRender(done, progress => {
|
||||
send.data({progress});
|
||||
}, { thin: true });
|
||||
send.done({parsed: KIRI.codec.encode(layers)});
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
let terms = {
|
||||
COPYRIGHT: "Copyright (C) Stewart Allen <sa@grid.space> - All Rights Reserved",
|
||||
LICENSE: "See the license.md file included with the source distribution",
|
||||
VERSION: "2.3.D3"
|
||||
VERSION: "2.3.D4"
|
||||
};
|
||||
|
||||
if (typeof(module) === 'object') {
|
||||
|
|
|
|||
|
|
@ -353,9 +353,9 @@
|
|||
}
|
||||
}
|
||||
let polys = [], t = [], c = [];
|
||||
POLY.flatten(slice.camLines).forEach(function (poly) {
|
||||
POLY.flatten(slice.camLines.clone(true)).forEach(function (poly) {
|
||||
let child = poly.parent;
|
||||
if (depthFirst) poly = poly.clone();
|
||||
if (depthFirst) poly = poly.clone(true);
|
||||
if (child) c.push(poly); else t.push(poly);
|
||||
poly.layer = depthData.layer;
|
||||
polys.push(poly);
|
||||
|
|
|
|||
|
|
@ -222,6 +222,8 @@
|
|||
}
|
||||
});
|
||||
|
||||
if (!offset) return;
|
||||
|
||||
slice.camLines = offset;
|
||||
slice.output()
|
||||
.setLayer("roughing", {face: 0, line: 0})
|
||||
|
|
@ -229,7 +231,7 @@
|
|||
updateOp(index, slices.length);
|
||||
});
|
||||
|
||||
sliceAll.appendAll(slices);
|
||||
sliceAll.appendAll(slices.filter(slice => slice.camLines));
|
||||
}
|
||||
|
||||
// create outline slices
|
||||
|
|
@ -508,7 +510,7 @@
|
|||
});
|
||||
|
||||
if (notabs) {
|
||||
console.log(`unable to compute tabs for ${notabs} traces @ z=${slice.z}`);
|
||||
console.log(`unable to compute tabs for ${notabs} traces @ z=${z}`);
|
||||
}
|
||||
|
||||
return nutrace;
|
||||
|
|
|
|||
|
|
@ -389,7 +389,6 @@
|
|||
const moveColor = opts.move >= 0 ? opts.move : 0xaaaaaa;
|
||||
const printColor = opts.print >= 0 ? opts.print : 0x777700;
|
||||
const layers = [];
|
||||
const hsv2rgb = KIRI.Print.hsv2rgb;
|
||||
const maxspd = levels.map(level => {
|
||||
return level.map(o => o.speed || 0).reduce((a, v) => Math.max(a,v));
|
||||
}).reduce((a, v) => Math.max(a, v));
|
||||
|
|
@ -459,21 +458,13 @@
|
|||
.setLayer('move', moveColor, true)
|
||||
.addPolys(moves, { thin: true, z: opts.z });
|
||||
Object.values(prints).forEach(array => {
|
||||
array.forEach(poly => {
|
||||
output
|
||||
.setLayer(opts.action || 'print', printColor)
|
||||
.addPolys([ poly ], thin ? { thin, z: opts.z } :
|
||||
{
|
||||
offset: array.width, height, z: opts.z,
|
||||
color: { face: poly.color, line: poly.color }
|
||||
})
|
||||
array.forEach(poly => { output
|
||||
.setLayer(opts.action || 'print', printColor)
|
||||
.addPolys([ poly ], thin ? { thin, z: opts.z } : {
|
||||
offset: array.width, height, z: opts.z,
|
||||
color: { face: poly.color, line: poly.color }
|
||||
})
|
||||
})
|
||||
// output
|
||||
// .setLayer(opts.action || 'print', printColor)
|
||||
// .addPolys(array, thin ? { thin, z: opts.z } :
|
||||
// { offset: array.width, height, z: opts.z,
|
||||
// xcolor: { face: hsv2rgb({h:index/levels.length, s:1, v:1}, true) }
|
||||
// })
|
||||
});
|
||||
|
||||
update(index / levels.length);
|
||||
|
|
@ -482,4 +473,52 @@
|
|||
return layers;
|
||||
}
|
||||
|
||||
// hsv values all = 0 to 1
|
||||
function hsv2rgb(hsv, int) {
|
||||
let seg = Math.floor(hsv.h * 6),
|
||||
rem = hsv.h - (seg * (1/6)),
|
||||
p = hsv.v * (1.0 - (hsv.s)),
|
||||
q = hsv.v * (1.0 - (hsv.s * rem)),
|
||||
t = hsv.v * (1.0 - (hsv.s * (1.0 - rem))),
|
||||
out = {};
|
||||
switch (seg) {
|
||||
case 0:
|
||||
out.r = hsv.v;
|
||||
out.g = t;
|
||||
out.b = p;
|
||||
break;
|
||||
case 1:
|
||||
out.r = q;
|
||||
out.g = hsv.v;
|
||||
out.b = p;
|
||||
break;
|
||||
case 2:
|
||||
out.r = p;
|
||||
out.g = hsv.v;
|
||||
out.b = t;
|
||||
break;
|
||||
case 3:
|
||||
out.r = p;
|
||||
out.g = q;
|
||||
out.b = hsv.v;
|
||||
break;
|
||||
case 4:
|
||||
out.r = t;
|
||||
out.g = p;
|
||||
out.b = hsv.v;
|
||||
break;
|
||||
case 5:
|
||||
out.r = hsv.v;
|
||||
out.g = p;
|
||||
out.b = q;
|
||||
break;
|
||||
}
|
||||
|
||||
return int ? (
|
||||
(((out.r * 255) & 0xff) << 16) |
|
||||
(((out.g * 255) & 0xff) << 8) |
|
||||
((out.b * 255) & 0xff)
|
||||
) : out;
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue