codec issues with float32. fix gcode parsing when layer hints missing
This commit is contained in:
parent
006823d870
commit
0611709c58
4 changed files with 58 additions and 20 deletions
1
notes.md
1
notes.md
|
|
@ -3,7 +3,6 @@
|
|||
## 2.3 remaining
|
||||
* cap path ends
|
||||
* rulers need to follow workspace units
|
||||
* gcode render broken when layer hints disabled
|
||||
* onshape mouse mapping option
|
||||
|
||||
## 2.4
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@
|
|||
}
|
||||
|
||||
// perform earcut()
|
||||
let cut = earcut(out,holes,3);
|
||||
let cut = self.earcut(out,holes,3);
|
||||
let ret = [];
|
||||
|
||||
// preserve swaps in new polys
|
||||
|
|
|
|||
|
|
@ -15,11 +15,17 @@
|
|||
allocFloat32Array: allocFloat32Array
|
||||
};
|
||||
|
||||
function allocFloat32Array(len) {
|
||||
if (Array.isArray(len)) {
|
||||
return new Float32Array(len);
|
||||
function allocFloat32Array(arg) {
|
||||
if (arg.byteLength) {
|
||||
// already a float array
|
||||
return arg;
|
||||
}
|
||||
return new Float32Array(len);
|
||||
if (Array.isArray(arg)) {
|
||||
// create float array from array
|
||||
return new Float32Array(arg);
|
||||
}
|
||||
// usually a number (size) for array
|
||||
return new Float32Array(arg);
|
||||
}
|
||||
|
||||
function encode(o, state) {
|
||||
|
|
@ -138,16 +144,26 @@
|
|||
let enc = {
|
||||
type: 'render',
|
||||
layers: Object.keys(this.layers),
|
||||
data: Object.values(this.layers).map(layer => { return {
|
||||
polys: encode(layer.polys, state),
|
||||
lines: encodePointArray(layer.lines, state),
|
||||
faces: codec.allocFloat32Array(layer.faces),
|
||||
cface: layer.cface,
|
||||
color: layer.color,
|
||||
paths: layer.paths,
|
||||
cpath: layer.cpath,
|
||||
off: layer.off
|
||||
} })
|
||||
data: Object.values(this.layers).map(layer => {
|
||||
const e = {
|
||||
polys: encode(layer.polys, state),
|
||||
lines: encodePointArray(layer.lines, state),
|
||||
faces: codec.allocFloat32Array(layer.faces),
|
||||
cface: layer.cface,
|
||||
color: layer.color,
|
||||
paths: layer.paths.map(lp => {
|
||||
return {
|
||||
z: lp.z,
|
||||
index: lp.index,
|
||||
faces: codec.allocFloat32Array(lp.faces)
|
||||
};
|
||||
}),
|
||||
cpath: layer.cpath,
|
||||
off: layer.off
|
||||
};
|
||||
// console.log('-->',e);
|
||||
return e;
|
||||
})
|
||||
};
|
||||
return enc;
|
||||
};
|
||||
|
|
@ -155,17 +171,39 @@
|
|||
registerDecoder('render', function(v, state) {
|
||||
let render = new KIRI.Render();
|
||||
for (let i=0; i<v.layers.length; i++) {
|
||||
render.layers[v.layers[i]] = {
|
||||
const d = 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,
|
||||
faces: codec.allocFloat32Array(v.data[i].faces),
|
||||
cface: v.data[i].cface,
|
||||
color: v.data[i].color,
|
||||
paths: v.data[i].paths,
|
||||
paths: v.data[i].paths.map(lp => {
|
||||
return {
|
||||
z: lp.z,
|
||||
index: lp.index,
|
||||
faces: codec.allocFloat32Array(lp.faces)
|
||||
};
|
||||
}),
|
||||
cpath: v.data[i].cpath,
|
||||
off: v.data[i].off
|
||||
};
|
||||
// fixup null -> Infinity in material counts (JSON stringify sucks)
|
||||
if (d.cface) {
|
||||
d.cface.forEach(rec => {
|
||||
if (rec.count === null) {
|
||||
rec.count = Infinity;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (d.cpoly) {
|
||||
d.cpoly.forEach(rec => {
|
||||
if (rec.count === null) {
|
||||
rec.count = Infinity;
|
||||
}
|
||||
});
|
||||
}
|
||||
// console.log('<--',d);
|
||||
}
|
||||
return render;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -178,8 +178,9 @@
|
|||
// non-move in a new plane means burp out
|
||||
// the old sequence and start a new one
|
||||
if (seq.Z != pos.Z) {
|
||||
const nh = (defh || pos.Z - seq.Z);
|
||||
seq = [];
|
||||
seq.height = height = (defh || pos.Z - seq.Z);
|
||||
seq.height = height = nh;
|
||||
if (fdm) dz = -height / 2;
|
||||
output.push(seq);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue