prep cam driver for new prepare render

This commit is contained in:
Stewart Allen 2020-11-08 13:04:54 -05:00
commit 9493206d29
8 changed files with 194 additions and 204 deletions

View file

@ -153,14 +153,21 @@ KIRI.work = {
movez: movez movez: movez
} }
}, function(reply) { }, function(reply) {
if (reply.done || reply.error) delete slicing[widget.id]; if (reply.done || reply.error) {
delete slicing[widget.id];
}
callback(reply); callback(reply);
}, [vertices]); }, [vertices]);
}, },
printSetup : function(settings, callback) { prepare : function(settings, update, done) {
send("printSetup", {settings:settings}, function(reply) { send("prepare", {settings:settings}, function(reply) {
callback(reply); if (reply.progress) {
update(reply.progress, reply.message);
}
if (reply.done) {
done(reply.output);
}
}); });
}, },

View file

@ -705,20 +705,19 @@
setOpacity(color.preview_opacity); setOpacity(color.preview_opacity);
} }
currentPrint = kiri.newPrint(settings, WIDGETS); KIRI.client.prepare(settings, function(progress, message) {
currentPrint.setup(true, function(update, status) { API.show.progress(progress, message);
API.show.progress(update, status); }, function (output) {
}, function() {
if (!currentPrint) {
return setViewMode(VIEWS.ARRANGE);
}
API.show.progress(0); API.show.progress(0);
if (!isCam) setOpacity(0); if (!isCam) setOpacity(0);
if (feature.preview) { output = KIRI.codec.decode(output);
if (feature.preview && output) {
STACKS.clear(); STACKS.clear();
currentPrint.render(STACKS.create('print', SPACE.platform.world)); const stack = STACKS.create('print', SPACE.platform.world)
output.forEach(layer => {
stack.add(layer);
});
} }
API.event.emit('print', pMode); API.event.emit('print', pMode);

View file

@ -212,34 +212,6 @@
scope.bytes = gcode.length; scope.bytes = gcode.length;
}; };
PRO.setup = function(remote, onupdate, ondone) {
let print = this,
settings = print.settings,
mode = settings.mode;
lastPoint = null;
lastEmit = null;
if (KIRI.client) {
// executed main kiri.js
KIRI.client.printSetup(settings, function(reply) {
if (reply.done) {
print.output = KIRI.codec.decode(reply.output);
ondone();
} else {
onupdate(reply.progress, reply.message)
}
});
} else {
// executed from kiri-worker.js
// uses encodeOutput in this class to produce print.output above
// this encoding could be made vastly more efficient
let driver = KIRI.driver[mode];
if (driver) driver.printSetup(print, onupdate);
else console.log({missing_print_driver: mode});
ondone();
}
};
// more generic. only used by SLA at the moment // more generic. only used by SLA at the moment
PRO.export = function(remote, online, ondone) { PRO.export = function(remote, online, ondone) {
@ -339,12 +311,6 @@
return newout; return newout;
}; };
PRO.render = function(stack) {
this.output.forEach(layer => {
stack.add(layer);
});
};
function pref(a,b) { function pref(a,b) {
return a !== undefined ? a : b; return a !== undefined ? a : b;
} }

View file

@ -106,30 +106,27 @@ KIRI.worker = {
} }
}, },
printSetup: function(data, send) { prepare: function(data, send) {
// create widget array from id:widget cache // create widget array from id:widget cache
const widgets = []; const widgets = Object.values(cache);
for (let key in cache) {
if (cache.hasOwnProperty(key)) {
widgets.push(cache[key]);
}
}
// let client know we've started // let client know we've started
send.data({update:0.05, updateStatus:"preview"}); send.data({update:0.05, updateStatus:"preview"});
current.print = KIRI.newPrint(data.settings, widgets, data.id); const drivers = KIRI.driver;
current.print.setup(false, function(progress, message) { const settings = data.settings;
send.data({ const mode = settings.mode;
progress, const driver = drivers[mode];
message
}); if (!(driver && driver.prepare)) {
}, function() { return console.log({invalid_print_driver: mode, driver});
send.done({ }
done: true,
output: KIRI.codec.encode(current.print.output) const layers = driver.prepare(widgets, settings, (progress, message) => {
}); send.data({ progress, message });
}); });
send.done({ done: true, output: KIRI.codec.encode(layers) });
}, },
printExport: function(data, send) { printExport: function(data, send) {

View file

@ -4,7 +4,7 @@
(function() { (function() {
let KIRI = self.kiri, const KIRI = self.kiri,
CAM = KIRI.driver.CAM = { CAM = KIRI.driver.CAM = {
// init, // src/mode/cam/client.js // init, // src/mode/cam/client.js
// sliceRender, // src/mode/cam/client.js // sliceRender, // src/mode/cam/client.js

View file

@ -20,16 +20,28 @@
* @param {Number} [index] into widget array * @param {Number} [index] into widget array
* @param {Object} [firstPoint] starting point * @param {Object} [firstPoint] starting point
*/ */
CAM.printSetup = function(print, update, index, firstPoint) { CAM.prepare = function(widgets, settings, update) {
let widgetIndex = index || 0, const count = widgets.length;
widgetArray = print.widgets, const weight = 1/count;
widgetCount = widgetArray.length, const print = KIRI.newPrint(settings, widgets);
widget = widgetArray[widgetIndex]; print.output = [];
if (widgetIndex >= widgetCount || !widget) return; let point;
widgets.forEach((widget, index) => {
point = prepEach(widget, settings, print, point, progress => {
update((index * weight + progress * weight) * 0.5);
});
});
let settings = print.settings, print.output = KIRI.driver.FDM.prepareRender(print.output, progress => {
device = settings.device, update(0.5 + progress * 0.5);
}, { thin: true });
return print.output;
};
function prepEach(widget, settings, print, firstPoint, update) {
let device = settings.device,
process = settings.process, process = settings.process,
stock = settings.stock, stock = settings.stock,
outer = settings.bounds, outer = settings.bounds,
@ -58,7 +70,7 @@
drillDown = process.camDrillDown, drillDown = process.camDrillDown,
drillLift = process.camDrillLift, drillLift = process.camDrillLift,
drillDwell = process.camDrillDwell, drillDwell = process.camDrillDwell,
newOutput = widgetIndex === 0 ? [] : print.output, newOutput = print.output || [],
layerOut = [], layerOut = [],
printPoint, printPoint,
isNewMode, isNewMode,
@ -574,9 +586,7 @@
// replace output single flattened layer with all points // replace output single flattened layer with all points
print.output = newOutput; print.output = newOutput;
if (widgetIndex + 1 < widgetCount) { return printPoint;
printSetup(print, update, widgetIndex + 1, printPoint);
}
}; };
/** /**

View file

@ -22,112 +22,112 @@
}); });
} }
FDM.printRender = function(print, options) { // FDM.printRender = function(print, options) {
let debug = KIRI.api.const.LOCAL; // let debug = KIRI.api.const.LOCAL;
let scope = print, emits, last, // let scope = print, emits, last,
moves, moving = true, // moves, moving = true,
opt = options || {}, // opt = options || {},
tools = opt.tools || [], // tools = opt.tools || [],
showmoves = !opt.nomoves, // showmoves = !opt.nomoves,
maxspeed = 0; // maxspeed = 0;
// find max speed // // find max speed
scope.output.forEach(function(layerout) { // scope.output.forEach(function(layerout) {
layerout.forEach(function(out, index) { // layerout.forEach(function(out, index) {
if (out.emit && out.speed) { // if (out.emit && out.speed) {
maxspeed = Math.max(maxspeed, out.speed); // maxspeed = Math.max(maxspeed, out.speed);
} // }
}); // });
}); // });
if (maxspeed === 0) { // if (maxspeed === 0) {
maxspeed = 4000; // maxspeed = 4000;
} // }
maxspeed *= 1.001; // maxspeed *= 1.001;
// render layered output // // render layered output
scope.lines = 0; // scope.lines = 0;
scope.output.forEach(function(layerout) { // scope.output.forEach(function(layerout) {
let move = [], print = [], cprint; // let move = [], print = [], cprint;
layerout.forEach(function(out, index) { // layerout.forEach(function(out, index) {
let point = toPoint(out.point); // let point = toPoint(out.point);
if (last) { // if (last) {
// drop short segments // // drop short segments
// if (point.emit === last.emit && UTIL.distSq(last, point) < 0.001 && point.z === last.z) { // // if (point.emit === last.emit && UTIL.distSq(last, point) < 0.001 && point.z === last.z) {
// return; // // return;
// } // // }
if (out.emit > 0) { // if (out.emit > 0) {
if (moving || !cprint) { // if (moving || !cprint) {
cprint = base.newPolygon().setOpen(true).append(last); // cprint = base.newPolygon().setOpen(true).append(last);
print.push({ // print.push({
poly: cprint, // poly: cprint,
speed: out.speed || maxspeed || 4000, // speed: out.speed || maxspeed || 4000,
tool:tools[out.tool] // tool:tools[out.tool]
}); // });
} // }
try { // try {
cprint.append(point); // cprint.append(point);
} catch (e) { // } catch (e) {
console.log(e, {cprint}); // console.log(e, {cprint});
} // }
moving = false; // moving = false;
} else { // } else {
cprint = null; // cprint = null;
move.push(last); // move.push(last);
move.push(point); // move.push(point);
moving = true; // moving = true;
} // }
// move direction arrow heads // // move direction arrow heads
if (debug && last.z == point.z) { // if (debug && last.z == point.z) {
let rs = BASE.newSlope( // let rs = BASE.newSlope(
{x: point.x, y: point.y}, // {x: point.x, y: point.y},
{x: last.x, y: last.y} // {x: last.x, y: last.y}
); // );
let ao1 = BASE.newSlopeFromAngle(rs.angle + 25); // let ao1 = BASE.newSlopeFromAngle(rs.angle + 25);
let ao2 = BASE.newSlopeFromAngle(rs.angle - 25); // let ao2 = BASE.newSlopeFromAngle(rs.angle - 25);
let sp = BASE.newPoint(point.x, point.y, point.z); // let sp = BASE.newPoint(point.x, point.y, point.z);
move.push(sp); // move.push(sp);
move.push(sp.projectOnSlope(ao1, BASE.config.debug_arrow)); // move.push(sp.projectOnSlope(ao1, BASE.config.debug_arrow));
move.push(sp); // move.push(sp);
move.push(sp.projectOnSlope(ao2, BASE.config.debug_arrow)); // move.push(sp.projectOnSlope(ao2, BASE.config.debug_arrow));
} // }
} // }
last = point; // last = point;
}); // });
emits = KIRI.newLayer(scope.group); // emits = KIRI.newLayer(scope.group);
if (showmoves) { // if (showmoves) {
moves = KIRI.newLayer(scope.group); // moves = KIRI.newLayer(scope.group);
moves.lines(move, opt.move_color || 0x888888); // moves.lines(move, opt.move_color || 0x888888);
} // }
emits.setTransparent(false); // emits.setTransparent(false);
// emit printing shapes // // emit printing shapes
print.forEach(segment => { // print.forEach(segment => {
let {poly, speed, tool} = segment; // let {poly, speed, tool} = segment;
let off = tool ? (tool.extNozzle || 0.4) / 2 : 0.2; // let off = tool ? (tool.extNozzle || 0.4) / 2 : 0.2;
let sint = Math.min(maxspeed, parseInt(speed)); // let sint = Math.min(maxspeed, parseInt(speed));
let rgb = scope.hsv2rgb({h:sint/maxspeed, s:1, v:1}); // let rgb = scope.hsv2rgb({h:sint/maxspeed, s:1, v:1});
let color = ((rgb.r * 0xff) << 16) | // let color = ((rgb.r * 0xff) << 16) |
((rgb.g * 0xff) << 8) | // ((rgb.g * 0xff) << 8) |
((rgb.b * 0xff) << 0); // ((rgb.b * 0xff) << 0);
if (opt.flat) { // if (opt.flat) {
poly = poly.clone().setZ(0); // poly = poly.clone().setZ(0);
} // }
if (opt.aslines) { // if (opt.aslines) {
emits.poly(poly, opt.color || color, false, true); // emits.poly(poly, opt.color || color, false, true);
} else { // } else {
// first point may be from the layer below, so use second point // // first point may be from the layer below, so use second point
emits.noodle_open(poly, off - 0.02, color, 0x0, poly.getZ(1)); // emits.noodle_open(poly, off - 0.02, color, 0x0, poly.getZ(1));
} // }
}); // });
emits.renderAll(); // emits.renderAll();
if (showmoves) { // if (showmoves) {
moves.render(); // moves.render();
scope.movesView.push(moves); // scope.movesView.push(moves);
} // }
scope.printView.push(emits); // scope.printView.push(emits);
scope.lines += print.length; // scope.lines += print.length;
}); // });
} // }
//
function toPoint(obj) { // function toPoint(obj) {
return base.newPoint(obj.x, obj.y, obj.z); // return base.newPoint(obj.x, obj.y, obj.z);
} // }
})(); })();

View file

@ -15,13 +15,13 @@
/** /**
* DRIVER PRINT CONTRACT * DRIVER PRINT CONTRACT
* *
* @param {Object} print state object * @param {Function} update progress callback
* @param {Function} update incremental callback * @returns {Object[]} returns array of render objects
*/ */
FDM.printSetup = function(print, update) { FDM.prepare = function(widgets, settings, update) {
let widgets = print.widgets.slice(), settings = FDM.fixExtruders(settings);
settings = FDM.fixExtruders(print.settings),
device = settings.device, let device = settings.device,
nozzle = device.extruders[0].extNozzle, nozzle = device.extruders[0].extNozzle,
process = settings.process, process = settings.process,
mode = settings.mode, mode = settings.mode,
@ -40,7 +40,9 @@
find, find,
layerout = [], layerout = [],
slices = [], slices = [],
sliceEntry; sliceEntry,
print = KIRI.newPrint(settings, widgets),
isThin = settings.controller.thinRender;
// TODO pick a widget with a slice on the first layer and use that nozzle // TODO pick a widget with a slice on the first layer and use that nozzle
// create brim, skirt, raft if specificed in FDM mode (code shared by laser) // create brim, skirt, raft if specificed in FDM mode (code shared by laser)
@ -371,19 +373,26 @@
lastOut = undefined; lastOut = undefined;
} }
print.output = render(output, progress => { print.output = FDM.prepareRender(output, progress => {
update(0.5 + progress * 0.5); update(0.5 + progress * 0.5);
}, device.extruders); }, { tools: device.extruders, thin: isThin });
return print.output;
}; };
function render(output, update, tools) { FDM.prepareRender = function(levels, update, options) {
const opts = options || {};
const tools = opts.tools;
const thin = opts.thin || false;
const layers = []; const layers = [];
output.forEach((level, index) => { levels.forEach((level, index) => {
const prints = {}; const prints = {};
const moves = []; const moves = [];
const pushPrint = (tool, poly) => { const pushPrint = (toolid, poly) => {
let array = prints[tool] = prints[tool] || []; toolid = toolid || 0;
array.width = tools[tool].extNozzle / 2; const array = prints[toolid] = prints[toolid] || [];
const tool = tools[toolid];
array.width = (tool.extNozzle || 1) / 2;
array.push(poly); array.push(poly);
}; };
let lastOut = null; let lastOut = null;
@ -418,11 +427,13 @@
} }
lastOut = out; lastOut = out;
}); });
const out = new KIRI.Render(); const output = new KIRI.Render();
layers.push(out); layers.push(output);
out.setLayer('move', 0xaaaaaa).addPolys(moves); output.setLayer('move', 0xaaaaaa).addPolys(moves);
Object.values(prints).forEach(array => { Object.values(prints).forEach(array => {
out.setLayer('print', 0x888800).addPolys(array, { offset: array.width, height }) output
.setLayer('print', 0x888800)
.addPolys(array, thin ? null : { offset: array.width, height })
}) })
update(index / output.length); update(index / output.length);
}); });