codec and color cleanup

This commit is contained in:
Stewart Allen 2020-11-09 19:22:28 -05:00
commit 1d573b1605
8 changed files with 29 additions and 43 deletions

View file

@ -3,7 +3,6 @@
## `C` cosmetic, `F` functional, `P` performance, `B` bug fix
* `F` detect and report slow framerates
* `F` gcode generation progress bar
* `F` implement an in-app bug reporting system. add workspace to export option.
* `F` extend mesh object to store raw + annotations (rot,scale,pos)
* share raw data w/ dups, encode/decode
@ -12,6 +11,8 @@
* `F` 2D image import
* `P` improve decimation speed by avoiding in/out of Point?
* `P` duplicate objects should share same slice data unless rotated or scaled
* `P` worker state cache cleanup and organization
* `P` client/worker interface normalization and cleanup
# FDM

View file

@ -127,6 +127,7 @@
for (let i=0; i<v.layers.length; i++) {
render.layers[v.layers[i]] = {
polys: decode(v.data[i].polys, state),
cpoly: v.data[i].cpoly,
lines: decodePointArray(v.data[i].lines),
faces: v.data[i].faces,
color: v.data[i].color,
@ -142,27 +143,11 @@
return {
type: 'top',
poly: encode(this.poly, state),
// traces: encode(this.traces, state),
// inner: encode(this.inner, state),
// // thinner: encode(this.thinner, state),
// solids: encode(this.solids, state),
// thin_fill: encodePointArray(this.thin_fill, state),
// fill_lines: encodePointArray(this.fill_lines, state),
// fill_sparse: encode(this.fill_sparse, state),
// polish: encode(this.polish, state)
};
};
registerDecoder('top', function(v, state) {
let top = KIRI.newTop(decode(v.poly, state));
// top.traces = decode(v.traces, state);
// top.inner = decode(v.inner, state);
// // top.thinner = decode(v.thinner, state);
// top.solids = decode(v.solids, state);
// top.thin_fill = decodePointArray(v.thin_fill, state);
// top.fill_lines = decodePointArray(v.fill_lines, state);
// top.fill_sparse = decode(v.fill_sparse, state);
// top.polish = decode(v.polish, state);
return top;
});
@ -215,10 +200,7 @@
let cached = state.poly[this.id];
if (cached) {
return {
type: 'poly',
ref: this.id
};
return { type: 'poly', ref: this.id };
}
state.poly[this.id] = this;
@ -230,8 +212,9 @@
open: this.isOpen(),
inner: encode(this.inner, state),
parent: encode(this.parent, state),
fills: encodePointArray(this.fills, state),
depth: this.depth
// fills: encodePointArray(this.fills, state),
depth: this.depth,
color: this.color
};
};
@ -255,8 +238,9 @@
poly.inner = decode(v.inner, state);
poly.parent = decode(v.parent, state);
poly.fills = decodePointArray(v.fills);
// poly.fills = decodePointArray(v.fills);
poly.depth = v.depth;
poly.color = v.color;
return poly;
});

View file

@ -89,6 +89,7 @@
return this;
}
// z planar closed polygonal areas
addAreas(polys, options) {
const faces = this.current.faces;
polys = Array.isArray(polys) ? polys : [ polys ];
@ -102,6 +103,7 @@
}
}
// misleading name. these are flat offset paths (old style rendering)
addFlats(polys, options) {
const opts = options || {};
const offset = opts.offset || 1;
@ -121,7 +123,7 @@
if (open) {
exp.appendAll(POLY.expand_lines(poly, offset * 0.9, z));
this.stats.flat_line = 0;
} else {
} else if (offset) {
POLY.offset([poly], offset * 0.9, off_opt);
POLY.offset([poly], -offset * 0.9, off_opt);
this.stats.flat_poly = 0;

View file

@ -109,11 +109,11 @@
ctrl.toggle.checked = defstate;
const { polys, lines, faces, paths, cpath } = data;
const { polys, cpoly, lines, faces, paths, cpath } = data;
if (polys.length || lines.length) {
const mat = [];
if (cpath) {
cpath.forEach(c => { mat.push(createLineMaterial({ color: c })) });
if (cpoly) {
cpoly.forEach(c => { mat.push(createLineMaterial({ color: c })) });
} else {
mat.push(createLineMaterial(data));
}
@ -128,8 +128,8 @@
vert.push(new THREE.Vector3(p.x, p.y, p.z));
}
if (vert.length) {
if (cpath) {
cpath.forEach((c, i) => geo.addGroup(c.start, c.count, i));
if (cpoly) {
cpoly.forEach((c, i) => geo.addGroup(c.start, c.count, i));
} else {
geo.addGroup(0, Infinity, 0);
}

View file

@ -172,7 +172,7 @@ KIRI.worker = {
}, done => {
const layers = KIRI.driver.FDM.prepareRender(done.output, progress => {
send.data({ progress: 0.5 + progress * 0.5 });
}, { thin, tools });
}, { thin, tools, xspeed: mode === 'FDM' });
send.done({parsed: KIRI.codec.encode(layers)});
}, { fdm : mode === 'FDM' });
},

View file

@ -415,6 +415,10 @@
const cn_len = new Counter();
const cn_col = new Counter();
function color(point) {
return hsv2rgb({h:point.speed / maxspd, s:1, v:0.75}, true);
}
levels.forEach((level, index) => {
const prints = {};
const moves = [];
@ -444,7 +448,7 @@
if (!lastOut.emit || (ckspeed && out.speed !== lastOut.speed)) {
current = newPolygon().setOpen();
current.push(lastOut.point);
current.color = hsv2rgb({h:out.speed/maxspd, s:1, v:0.75}, true);
current.color = color(out);
pushPrint(out.tool, current);
}
current.push(out.point);
@ -460,7 +464,7 @@
current = newPolygon().setOpen();
current.push(out.point);
if (out.emit) {
current.color = hsv2rgb({h:out.speed/maxspd, s:1, v:1}, true);
current.color = color(out);
pushPrint(out.tool, current);
} else {
moves.push(current);

View file

@ -18,9 +18,9 @@
FILL = KIRI.fill,
FILLFIXED = KIRI.fill_fixed,
COLOR = {
shell: { face: 0x003399, line: 0x003399, opacity: 1 },
fill: { face: 0x003399, line: 0x003399, opacity: 1 },
infill: { face: 0x003399, line: 0x003399, opacity: 1 },
shell: { face: 0x0077bb, line: 0x0077bb, opacity: 1 },
fill: { face: 0x0077bb, line: 0x0077bb, opacity: 1 },
infill: { face: 0x0077bb, line: 0x0077bb, opacity: 1 },
support: { face: 0x006699, line: 0x006699, opacity: 1 }
};

View file

@ -17,7 +17,6 @@
slice,
prepare,
export: exportLaser,
printRender,
exportGCode,
exportSVG,
exportDXF
@ -256,8 +255,8 @@
min.y = 0;
} else {
// normalize against center of build area
let w = print.settings.device.bedWidth;
let h = print.settings.device.bedDepth;
let w = settings.device.bedWidth;
let h = settings.device.bedDepth;
output.forEach(function(layer) {
layer.forEach(function(out) {
point = out.point;
@ -495,8 +494,4 @@
return lines.join('\n');
};
function printRender(print) {
return KIRI.driver.FDM.printRender(print, {aslines: true, nomoves: true, flat: true});
}
})();