checkpoint rendering tweaks

This commit is contained in:
Stewart Allen 2020-11-07 18:30:17 -05:00
commit 99d34ae2de
3 changed files with 51 additions and 33 deletions

View file

@ -480,9 +480,9 @@
depth = numOrDefault(opts.depth, 0), depth = numOrDefault(opts.depth, 0),
clean = opts.clean !== false, clean = opts.clean !== false,
simple = opts.simple !== false, simple = opts.simple !== false,
fill = opts.fill || ClipperLib.PolyFillType.pftNonZero, fill = numOrDefault(opts.fill, ClipperLib.PolyFillType.pftNonZero),
join = opts.join || ClipperLib.JoinType.jtMiter, join = numOrDefault(opts.join, ClipperLib.JoinType.jtMiter),
type = opts.type || ClipperLib.EndType.etClosedPolygon, type = numOrDefault(opts.type, ClipperLib.EndType.etClosedPolygon),
coff = new ClipperLib.ClipperOffset(), coff = new ClipperLib.ClipperOffset(),
ctre = new ClipperLib.PolyTree(), ctre = new ClipperLib.PolyTree(),
// if dist is array with values, shift out next offset // if dist is array with values, shift out next offset

View file

@ -41,14 +41,15 @@
addLines(lines, options) { addLines(lines, options) {
if (options) { if (options) {
options.open = true;
const polys = [];
for (let i=0; i<lines.length-1; i += 2) { for (let i=0; i<lines.length-1; i += 2) {
const poly = new BASE.Polygon() polys.push(new BASE.Polygon()
.append(lines[i]) .append(lines[i])
.append(lines[i+1]) .append(lines[i+1])
.setOpen(); .setOpen());
this.addPoly(poly, options);
} }
return; return this.addPolys(polys, options);
} }
for (let i=0; i<lines.length-1; i += 2) { for (let i=0; i<lines.length-1; i += 2) {
this.addLine(lines[i], lines[i+1]); this.addLine(lines[i], lines[i+1]);
@ -56,22 +57,18 @@
} }
addPoly(poly, options) { addPoly(poly, options) {
if (options) { return this.addPolys([poly], options);
this.addPaths([poly], options);
} else {
this.current.polys.push(poly);
}
return this;
} }
addPolys(polys, options) { addPolys(polys, options) {
if (options && options.flat) {
return this.addFlats(polys, options);
}
if (options) { if (options) {
return this.addPaths(polys, options); return this.addPaths(polys, options);
} }
polys = flat(polys); polys = flat(polys);
for (let i=0; i<polys.length; i++) { this.current.polys.appendAll(polys);
this.addPoly(polys[i]);
}
return this; return this;
} }
@ -96,10 +93,20 @@
return; return;
} }
const z = polys[0].getZ(), faces = this.current.faces; const z = polys[0].getZ(), faces = this.current.faces;
const open = opts.open || false;
const off_opt = {
z,
flat: true,
type: open ? ClipperLib.EndType.etOpenSquare : undefined,
};
polys.forEach(poly => { polys.forEach(poly => {
let exp = []; let exp = off_opt.outs = [];
POLY.offset([poly], offset/2, { z, outs: exp, flat: true }); if (open) {
POLY.offset([poly], -offset/2, { z, outs: exp, flat: true }); exp.appendAll(POLY.expand_lines(poly, offset * 0.9, z));
} else {
POLY.offset([poly], offset * 0.9, off_opt);
POLY.offset([poly], -offset * 0.9, off_opt);
}
if (opts.outline) { if (opts.outline) {
this.addPolys(exp.clone()); this.addPolys(exp.clone());
} }

View file

@ -24,10 +24,15 @@
}; };
let isThin = false; // force line rendering let isThin = false; // force line rendering
let isFlat = false; // force flat rendering
let offset = 0; // poly line generation offsets let offset = 0; // poly line generation offsets
function thin(opt) { function vopt(opt) {
return isThin ? null : opt; if (opt) {
if (isFlat) { opt.flat = true; return opt }
if (isThin) return null;
}
return opt;
} }
/** /**
@ -64,6 +69,7 @@
sliceFillAngle = spro.sliceFillAngle, sliceFillAngle = spro.sliceFillAngle,
view = widget.mesh && widget.mesh.newGroup ? widget.mesh.newGroup() : null; view = widget.mesh && widget.mesh.newGroup ? widget.mesh.newGroup() : null;
isFlat = false;
isThin = settings.controller.thinRender; isThin = settings.controller.thinRender;
offset = nozzleSize / 2; offset = nozzleSize / 2;
@ -114,6 +120,10 @@
return; return;
} }
// if (!isThin && slices.length > 100) {
// isFlat = true;
// }
if (slices.length > 150) { if (slices.length > 150) {
isThin = true; isThin = true;
} }
@ -414,49 +424,50 @@
output output
.setLayer("shells", COLOR.shell) .setLayer("shells", COLOR.shell)
.addPolys(top.shells, thin({ offset })); .addPolys(top.shells, vopt({ offset }));
// if (isThin && debug) { // if (isThin && debug) {
// slice.output() // slice.output()
// .setLayer('offset', { face: 0, line: 0x888888 }) // .setLayer('offset', { face: 0, line: 0x888888 })
// .addPolys(top.fill_off) // .addPolys(top.fill_off)
// .setLayer('last', { face: 0, line: 0x008888 }) // .setLayer('last', { face: 0, line: 0x008888 })
// .addPolys(top.last) // .addPolys(top.last);
// ;
// } // }
if (top.fill_lines) output if (top.fill_lines) output
.setLayer("fill", COLOR.fill) .setLayer("fill", COLOR.fill)
.addLines(top.fill_lines, thin({ offset })); .addLines(top.fill_lines, vopt({ offset }));
if (top.fill_sparse) output if (top.fill_sparse) output
.setLayer("infill", COLOR.infill) .setLayer("infill", COLOR.infill)
.addPolys(top.fill_sparse, thin({ offset })) .addPolys(top.fill_sparse, vopt({ offset, open: true, outline: true }))
// emit solid areas // emit solid areas
// if (isThin && debug) { // if (isThin && debug) {
// render.setLayer("solids", { face: 0x00dd00 }).addAreas(solids); // output
// .setLayer("solids", { face: 0x00dd00 })
// .addAreas(slice.solids);
// } // }
}); });
if (slice.supports) output if (slice.supports) output
.setLayer("support", COLOR.support) .setLayer("support", COLOR.support)
.addPolys(slice.supports, thin({ offset })); .addPolys(slice.supports, vopt({ offset }));
if (slice.supports) slice.supports.forEach(poly => { if (slice.supports) slice.supports.forEach(poly => {
output output
.setLayer("support", COLOR.support) .setLayer("support", COLOR.support)
.addLines(poly.fill, thin({ offset })); .addLines(poly.fill, vopt({ offset }));
}) })
// if (isThin && debug) { // if (isThin && debug) {
// top.output() // output
// .setLayer("bridges", { face: 0x00aaaa, line: 0x00aaaa }) // .setLayer("bridges", { face: 0x00aaaa, line: 0x00aaaa })
// .addAreas(bridges) // .addAreas(top.bridges);
// //
// down.output() // output
// .setLayer("flats", { face: 0xaa00aa, line: 0xaa00aa }) // .setLayer("flats", { face: 0xaa00aa, line: 0xaa00aa })
// .addAreas(flats) // .addAreas(top.flats);
// } // }
} }