add widget render control ui. fix up cam prepare with new render engine

This commit is contained in:
Stewart Allen 2020-11-08 16:44:32 -05:00
commit b9b78cc1ae
12 changed files with 127 additions and 292 deletions

View file

@ -24,78 +24,6 @@
api.ui.camContour.marker.style.display =
proc.camContourXOn || proc.camContourYOn ? 'flex' : 'none';
});
}
CAM.sliceRender = function(widget) {
return KIRI.Layer.renderSetup().renderSlices(widget.slices);
let slices = widget.slices;
if (!slices) return;
slices.forEach(function(slice) {
let tops = slice.tops,
layers = slice.layers,
outline = layers.outline,
open = (slice.camMode === PRO.CONTOUR_X || slice.camMode === PRO.CONTOUR_Y);
layers.outline.clear(); // slice raw edges
layers.trace.clear(); // roughing
layers.solid.clear(); // outline
layers.bridge.clear(); // outline x
layers.flat.clear(); // outline y
layers.fill.clear(); // facing
tops.forEach(function(top) {
outline.poly(top.poly, 0x999900, true, open);
// if (top.inner) outline.poly(top.inner, 0xdddddd, true);
if (top.inner) outline.poly(top.inner, 0xff0000, true);
});
// various outlining
let layer;
slice.tops.forEach(function(top) {
switch (slice.camMode) {
case PRO.OUTLINE:
layer = layers.solid;
break;
case PRO.CONTOUR_X:
layer = layers.bridge;
break;
case PRO.CONTOUR_Y:
layer = layers.flat;
break;
default: // roughing
layer = layers.trace;
break;
}
if (top.traces) {
layer.poly(top.traces, 0x010101, true, null);
}
});
// facing (previously separate. now part of roughing)
layer = slice.layers.fill;
slice.tops.forEach(function(top) {
if (top.fill_lines) {
layer.lines(top.fill_lines, fill_color);
}
});
outline.render();
layers.trace.render();
layers.solid.render();
layers.bridge.render();
layers.flat.render();
layers.fill.render();
});
}
CAM.printRender = function(print) {
return KIRI.driver.FDM.printRender(print, {
aslines: true,
color: 0x010101,
move_color: 0xcc3333
});
}
};
})();

View file

@ -7,10 +7,8 @@
const KIRI = self.kiri,
CAM = KIRI.driver.CAM = {
// init, // src/mode/cam/client.js
// sliceRender, // src/mode/cam/client.js
// printRender // src/mode/cam/client.js
// slice, // src/mode/cam/slice.js
// printSetup, // src/mode/cam/prepare.js
// prepare, // src/mode/cam/prepare.js
// printExport, // src/mode/cam/export.js
},
CPRO = CAM.process = {

View file

@ -23,7 +23,7 @@
CAM.prepare = function(widgets, settings, update) {
const count = widgets.length;
const weight = 1/count;
const print = KIRI.newPrint(settings, widgets);
const print = self.worker.print = KIRI.newPrint(settings, widgets);
print.output = [];
let point;
@ -33,11 +33,11 @@
});
});
print.output = KIRI.driver.FDM.prepareRender(print.output, progress => {
print.render = KIRI.driver.FDM.prepareRender(print.output, progress => {
update(0.5 + progress * 0.5);
}, { thin: true });
}, { thin: true, print: 0, move: 0x003366 });
return print.output;
return print.render;
};
function prepEach(widget, settings, print, firstPoint, update) {
@ -276,7 +276,6 @@
} else {
rate = plungeRate;
}
// console.log({deltaZ: deltaZ, deltaXY: deltaXY, threshold:threshold, modifier:modifier, rate:rate, plungeRate:plungeRate});
}
// todo synthesize move speed from feed / plunge accordingly
@ -320,26 +319,23 @@
case PRO.LEVEL:
setTool(process.camRoughTool, process.camRoughSpeed, 0);
spindle = Math.min(spindleMax, process.camRoughSpindle);
slice.tops.forEach(function(top) {
if (!top.traces) return;
let polys = [];
top.traces.forEach(function (poly) {
polys.push(poly);
if (poly.inner) {
poly.inner.forEach(function(inner) {
polys.push(inner);
})
}
});
// set winding specified in output
POLY.setWinding(polys, process.camConventional, false);
printPoint = poly2polyEmit(polys, printPoint, function(poly, index, count) {
poly.forEachPoint(function(point, pidx, points, offset) {
camOut(point.clone(), offset !== 0);
}, true, index);
});
newLayer();
const level = [];
slice.camLines.forEach(function (poly) {
level.push(poly);
if (poly.inner) {
poly.inner.forEach(function(inner) {
level.push(inner);
})
}
});
// set winding specified in output
POLY.setWinding(level, process.camConventional, false);
printPoint = poly2polyEmit(level, printPoint, function(poly, index, count) {
poly.forEachPoint(function(point, pidx, points, offset) {
camOut(point.clone(), offset !== 0);
}, true, index);
});
newLayer();
break;
case PRO.ROUGH:
case PRO.OUTLINE:
@ -356,33 +352,28 @@
dir = !dir;
}
}
// todo find closest next trace/trace-point
slice.tops.forEach(function(top) {
if (!top.poly) return;
if (!top.traces) return;
let polys = [], t = [], c = [];
POLY.flatten(top.traces, top.inner || []).forEach(function (poly) {
let child = poly.parent;
if (depthFirst) poly = poly.clone();
if (child) c.push(poly); else t.push(poly);
poly.layer = depthData.layer;
polys.push(poly);
});
// set cut direction on outer polys
POLY.setWinding(t, dir);
// set cut direction on inner polys
POLY.setWinding(c, !dir);
if (depthFirst) {
(slice.camMode === PRO.ROUGH ? depthData.rough : depthData.outline).append(polys);
} else {
printPoint = poly2polyEmit(polys, printPoint, function(poly, index, count) {
poly.forEachPoint(function(point, pidx, points, offset) {
camOut(point.clone(), offset !== 0);
}, poly.isClosed(), index);
});
newLayer();
}
let polys = [], t = [], c = [];
POLY.flatten(slice.camLines).forEach(function (poly) {
let child = poly.parent;
if (depthFirst) poly = poly.clone();
if (child) c.push(poly); else t.push(poly);
poly.layer = depthData.layer;
polys.push(poly);
});
// set cut direction on outer polys
POLY.setWinding(t, dir);
// set cut direction on inner polys
POLY.setWinding(c, !dir);
if (depthFirst) {
(slice.camMode === PRO.ROUGH ? depthData.rough : depthData.outline).append(polys);
} else {
printPoint = poly2polyEmit(polys, printPoint, function(poly, index, count) {
poly.forEachPoint(function(point, pidx, points, offset) {
camOut(point.clone(), offset !== 0);
}, poly.isClosed(), index);
});
newLayer();
}
break;
case PRO.CONTOUR_X:
case PRO.CONTOUR_Y:
@ -394,10 +385,9 @@
spindle = Math.min(spindleMax, process.camContourSpindle);
depthData.outlineDiam = toolDiam;
// todo find closest next trace/trace-point
slice.tops.forEach(function(top) {
if (!top.traces) return;
{
let polys = [], poly, emit;
top.traces.forEach(function (poly) {
slice.camLines.forEach(function (poly) {
if (depthFirst) poly = poly.clone(true);
polys.push({first:poly.first(), last:poly.last(), poly:poly});
});
@ -414,15 +404,11 @@
});
newLayer();
}
});
}
break;
case PRO.DRILL:
setTool(process.camDrillTool, process.camDrillDownSpeed, process.camDrillDownSpeed);
// drilling is always depth-first
slice.tops.forEach(function(top) {
if (!top.traces) return;
depthData.drill.appendAll(top.traces);
});
depthData.drill.appendAll(slice.camLines);
break;
}
update(sliceIndex / slices.length);

View file

@ -59,7 +59,6 @@
camRoughDown = proc.camRoughDown,
minStepDown = Math.min(1, roughDown, outlineDown),
maxToolDiam = 0,
sliceIndex = 0,
thruHoles;
if (settings.stock.x + 0.00001 < bounds.max.x - bounds.min.x) {
@ -149,11 +148,11 @@
for (let z = zMax + ztOff - zstep; z >= zMax; z -= zstep) {
let slice = shadowTop.slice.clone(false);
slice.z = z;
slice.index = sliceIndex++;
slice.camMode = PRO.LEVEL;
slice.camLines = POLY.setZ(facing.clone(true), slice.z);
slice.output()
.setLayer("facing", {face: 0, line: 0})
.addPolys(POLY.setZ(facing.clone(true), slice.z));
.addPolys(slice.camLines);
sliceAll.push(slice);
}
}
@ -223,10 +222,10 @@
}
});
slice.camLines = offset;
slice.output()
.setLayer("roughing", {face: 0, line: 0})
.addPolys(offset);
slice.index = sliceIndex++;
updateOp(index, slices.length);
});
@ -302,7 +301,7 @@
offset = addCutoutTabs(offset, slice.z, outlineToolDiam, tabWidth, proc.camTabsCount, proc.camTabsAngle);
}
slice.index = sliceIndex++;
slice.camLines = offset;
slice.output()
.setLayer("outline", {face: 0, line: 0})
.addPolys(offset);
@ -343,6 +342,8 @@
sliceDrill(drillTool, tslices, sliceAll);
}
sliceAll.forEach((slice, index) => slice.index = index);
// used in printSetup()
widget.terrain = terrain;
widget.maxToolDiam = maxToolDiam;
@ -394,6 +395,7 @@
point.y = center.y;
});
slice.camMode = PRO.DRILL;
slice.camLines = [ drill ];
slice.output()
.setLayer("drill", {face: 0, line: 0})
.addPolys(drill);
@ -433,6 +435,7 @@
.append(point.clone().setZ(bounds.max.z - stock.z - mz)));
});
slice.camMode = PRO.DRILL;
slice.camLines = polys;
slice.output()
.setLayer("register", {face: 0, line: 0})
.addPolys(polys);

View file

@ -19,7 +19,6 @@
let opt = options || {},
ondone = opt.ondone || noop,
onupdate = opt.onupdate || noop,
mesh = widget.mesh,
proc = settings.process,
resolution = proc.camTolerance,
tool = new CAM.Tool(settings, proc.camContourTool),
@ -179,9 +178,9 @@
for (x = minX; x <= maxX; x += toolStep) {
gridx = Math.round(((x - minX) / boundsX) * stepsx);
ly = gridy = 0;
slice = newSlice(gridx, mesh.newGroup ? mesh.newGroup() : null);
slice = newSlice(gridx);
slice.camMode = CPRO.CONTOUR_X;
slice.lines = newlines = [];
// slice.lines = newlines = [];
newtop = slice.addTop(newPolygon().setOpen()).poly;
newtrace = newPolygon().setOpen();
sliceout = [];
@ -200,10 +199,6 @@
continue;
}
if (ly) {
if (mesh) newlines.push(newLine(
newPoint(x,ly,ltv),
newPoint(x,y,tv)
));
let ang = Math.abs((Math.atan2(ltv - tv, resolution) * R2A) % 90);
// over max angle, turn into square edge (up or down)
if (ang > maxangle) {
@ -224,6 +219,7 @@
end_poly();
if (sliceout.length > 0) {
newslices.push(slice);
slice.camLines = sliceout;
slice.output()
.setLayer("contour x", {face: 0, line: 0})
.addPolys(sliceout);
@ -239,9 +235,9 @@
for (y = minY; y <= maxY; y += toolStep) {
gridy = Math.round(((y - minY) / boundsY) * stepsy);
lx = gridx = 0;
slice = newSlice(gridy, mesh.newGroup ? mesh.newGroup() : null);
slice = newSlice(gridy);
slice.camMode = CPRO.CONTOUR_Y;
slice.lines = newlines = [];
// slice.lines = newlines = [];
newtop = slice.addTop(newPolygon().setOpen()).poly;
newtrace = newPolygon().setOpen();
sliceout = [];
@ -260,10 +256,6 @@
continue;
}
if (lx) {
if (mesh) newlines.push(newLine(
newPoint(lx,y,ltv),
newPoint(x,y,tv)
));
let ang = Math.abs((Math.atan2(ltv - tv, resolution) * R2A) % 90);
// over max angle, turn into square edge (up or down)
if (ang > maxangle) {
@ -284,6 +276,7 @@
end_poly();
if (sliceout.length > 0) {
newslices.push(slice);
slice.camLines = sliceout;
slice.output()
.setLayer("contour y", {face: 0, line: 0})
.addPolys(sliceout);