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
|
## 2.3 remaining
|
||||||
* cap path ends
|
* cap path ends
|
||||||
* rulers need to follow workspace units
|
* rulers need to follow workspace units
|
||||||
* gcode render broken when layer hints disabled
|
|
||||||
* onshape mouse mapping option
|
* onshape mouse mapping option
|
||||||
|
|
||||||
## 2.4
|
## 2.4
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// perform earcut()
|
// perform earcut()
|
||||||
let cut = earcut(out,holes,3);
|
let cut = self.earcut(out,holes,3);
|
||||||
let ret = [];
|
let ret = [];
|
||||||
|
|
||||||
// preserve swaps in new polys
|
// preserve swaps in new polys
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,17 @@
|
||||||
allocFloat32Array: allocFloat32Array
|
allocFloat32Array: allocFloat32Array
|
||||||
};
|
};
|
||||||
|
|
||||||
function allocFloat32Array(len) {
|
function allocFloat32Array(arg) {
|
||||||
if (Array.isArray(len)) {
|
if (arg.byteLength) {
|
||||||
return new Float32Array(len);
|
// 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) {
|
function encode(o, state) {
|
||||||
|
|
@ -138,16 +144,26 @@
|
||||||
let enc = {
|
let enc = {
|
||||||
type: 'render',
|
type: 'render',
|
||||||
layers: Object.keys(this.layers),
|
layers: Object.keys(this.layers),
|
||||||
data: Object.values(this.layers).map(layer => { return {
|
data: Object.values(this.layers).map(layer => {
|
||||||
|
const e = {
|
||||||
polys: encode(layer.polys, state),
|
polys: encode(layer.polys, state),
|
||||||
lines: encodePointArray(layer.lines, state),
|
lines: encodePointArray(layer.lines, state),
|
||||||
faces: codec.allocFloat32Array(layer.faces),
|
faces: codec.allocFloat32Array(layer.faces),
|
||||||
cface: layer.cface,
|
cface: layer.cface,
|
||||||
color: layer.color,
|
color: layer.color,
|
||||||
paths: layer.paths,
|
paths: layer.paths.map(lp => {
|
||||||
|
return {
|
||||||
|
z: lp.z,
|
||||||
|
index: lp.index,
|
||||||
|
faces: codec.allocFloat32Array(lp.faces)
|
||||||
|
};
|
||||||
|
}),
|
||||||
cpath: layer.cpath,
|
cpath: layer.cpath,
|
||||||
off: layer.off
|
off: layer.off
|
||||||
} })
|
};
|
||||||
|
// console.log('-->',e);
|
||||||
|
return e;
|
||||||
|
})
|
||||||
};
|
};
|
||||||
return enc;
|
return enc;
|
||||||
};
|
};
|
||||||
|
|
@ -155,17 +171,39 @@
|
||||||
registerDecoder('render', function(v, state) {
|
registerDecoder('render', function(v, state) {
|
||||||
let render = new KIRI.Render();
|
let render = new KIRI.Render();
|
||||||
for (let i=0; i<v.layers.length; i++) {
|
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),
|
polys: decode(v.data[i].polys, state),
|
||||||
cpoly: v.data[i].cpoly,
|
cpoly: v.data[i].cpoly,
|
||||||
lines: decodePointArray(v.data[i].lines),
|
lines: decodePointArray(v.data[i].lines),
|
||||||
faces: v.data[i].faces,
|
faces: codec.allocFloat32Array(v.data[i].faces),
|
||||||
cface: v.data[i].cface,
|
cface: v.data[i].cface,
|
||||||
color: v.data[i].color,
|
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,
|
cpath: v.data[i].cpath,
|
||||||
off: v.data[i].off
|
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;
|
return render;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -178,8 +178,9 @@
|
||||||
// non-move in a new plane means burp out
|
// non-move in a new plane means burp out
|
||||||
// the old sequence and start a new one
|
// the old sequence and start a new one
|
||||||
if (seq.Z != pos.Z) {
|
if (seq.Z != pos.Z) {
|
||||||
|
const nh = (defh || pos.Z - seq.Z);
|
||||||
seq = [];
|
seq = [];
|
||||||
seq.height = height = (defh || pos.Z - seq.Z);
|
seq.height = height = nh;
|
||||||
if (fdm) dz = -height / 2;
|
if (fdm) dz = -height / 2;
|
||||||
output.push(seq);
|
output.push(seq);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue