diff --git a/notes.md b/notes.md index eeed012b..b1132e33 100644 --- a/notes.md +++ b/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 diff --git a/src/geo/polygon.js b/src/geo/polygon.js index 533d8463..d4b569fa 100644 --- a/src/geo/polygon.js +++ b/src/geo/polygon.js @@ -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 diff --git a/src/kiri/codec.js b/src/kiri/codec.js index f5b8356d..ff7df8bc 100644 --- a/src/kiri/codec.js +++ b/src/kiri/codec.js @@ -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 { + 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; }); diff --git a/src/kiri/print.js b/src/kiri/print.js index bde24c36..531399ee 100644 --- a/src/kiri/print.js +++ b/src/kiri/print.js @@ -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); }