prep cam driver for new prepare render
This commit is contained in:
parent
15ea39e849
commit
9493206d29
8 changed files with 194 additions and 204 deletions
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
(function() {
|
||||
|
||||
let KIRI = self.kiri,
|
||||
const KIRI = self.kiri,
|
||||
CAM = KIRI.driver.CAM = {
|
||||
// init, // src/mode/cam/client.js
|
||||
// sliceRender, // src/mode/cam/client.js
|
||||
|
|
|
|||
|
|
@ -20,16 +20,28 @@
|
|||
* @param {Number} [index] into widget array
|
||||
* @param {Object} [firstPoint] starting point
|
||||
*/
|
||||
CAM.printSetup = function(print, update, index, firstPoint) {
|
||||
let widgetIndex = index || 0,
|
||||
widgetArray = print.widgets,
|
||||
widgetCount = widgetArray.length,
|
||||
widget = widgetArray[widgetIndex];
|
||||
CAM.prepare = function(widgets, settings, update) {
|
||||
const count = widgets.length;
|
||||
const weight = 1/count;
|
||||
const print = KIRI.newPrint(settings, widgets);
|
||||
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,
|
||||
device = settings.device,
|
||||
print.output = KIRI.driver.FDM.prepareRender(print.output, progress => {
|
||||
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,
|
||||
stock = settings.stock,
|
||||
outer = settings.bounds,
|
||||
|
|
@ -58,7 +70,7 @@
|
|||
drillDown = process.camDrillDown,
|
||||
drillLift = process.camDrillLift,
|
||||
drillDwell = process.camDrillDwell,
|
||||
newOutput = widgetIndex === 0 ? [] : print.output,
|
||||
newOutput = print.output || [],
|
||||
layerOut = [],
|
||||
printPoint,
|
||||
isNewMode,
|
||||
|
|
@ -574,9 +586,7 @@
|
|||
// replace output single flattened layer with all points
|
||||
print.output = newOutput;
|
||||
|
||||
if (widgetIndex + 1 < widgetCount) {
|
||||
printSetup(print, update, widgetIndex + 1, printPoint);
|
||||
}
|
||||
return printPoint;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -22,112 +22,112 @@
|
|||
});
|
||||
}
|
||||
|
||||
FDM.printRender = function(print, options) {
|
||||
let debug = KIRI.api.const.LOCAL;
|
||||
let scope = print, emits, last,
|
||||
moves, moving = true,
|
||||
opt = options || {},
|
||||
tools = opt.tools || [],
|
||||
showmoves = !opt.nomoves,
|
||||
maxspeed = 0;
|
||||
// find max speed
|
||||
scope.output.forEach(function(layerout) {
|
||||
layerout.forEach(function(out, index) {
|
||||
if (out.emit && out.speed) {
|
||||
maxspeed = Math.max(maxspeed, out.speed);
|
||||
}
|
||||
});
|
||||
});
|
||||
if (maxspeed === 0) {
|
||||
maxspeed = 4000;
|
||||
}
|
||||
maxspeed *= 1.001;
|
||||
// render layered output
|
||||
scope.lines = 0;
|
||||
scope.output.forEach(function(layerout) {
|
||||
let move = [], print = [], cprint;
|
||||
layerout.forEach(function(out, index) {
|
||||
let point = toPoint(out.point);
|
||||
if (last) {
|
||||
// drop short segments
|
||||
// if (point.emit === last.emit && UTIL.distSq(last, point) < 0.001 && point.z === last.z) {
|
||||
// return;
|
||||
// }
|
||||
if (out.emit > 0) {
|
||||
if (moving || !cprint) {
|
||||
cprint = base.newPolygon().setOpen(true).append(last);
|
||||
print.push({
|
||||
poly: cprint,
|
||||
speed: out.speed || maxspeed || 4000,
|
||||
tool:tools[out.tool]
|
||||
});
|
||||
}
|
||||
try {
|
||||
cprint.append(point);
|
||||
} catch (e) {
|
||||
console.log(e, {cprint});
|
||||
}
|
||||
moving = false;
|
||||
} else {
|
||||
cprint = null;
|
||||
move.push(last);
|
||||
move.push(point);
|
||||
moving = true;
|
||||
}
|
||||
// move direction arrow heads
|
||||
if (debug && last.z == point.z) {
|
||||
let rs = BASE.newSlope(
|
||||
{x: point.x, y: point.y},
|
||||
{x: last.x, y: last.y}
|
||||
);
|
||||
let ao1 = BASE.newSlopeFromAngle(rs.angle + 25);
|
||||
let ao2 = BASE.newSlopeFromAngle(rs.angle - 25);
|
||||
let sp = BASE.newPoint(point.x, point.y, point.z);
|
||||
move.push(sp);
|
||||
move.push(sp.projectOnSlope(ao1, BASE.config.debug_arrow));
|
||||
move.push(sp);
|
||||
move.push(sp.projectOnSlope(ao2, BASE.config.debug_arrow));
|
||||
}
|
||||
}
|
||||
last = point;
|
||||
});
|
||||
emits = KIRI.newLayer(scope.group);
|
||||
if (showmoves) {
|
||||
moves = KIRI.newLayer(scope.group);
|
||||
moves.lines(move, opt.move_color || 0x888888);
|
||||
}
|
||||
emits.setTransparent(false);
|
||||
// emit printing shapes
|
||||
print.forEach(segment => {
|
||||
let {poly, speed, tool} = segment;
|
||||
let off = tool ? (tool.extNozzle || 0.4) / 2 : 0.2;
|
||||
let sint = Math.min(maxspeed, parseInt(speed));
|
||||
let rgb = scope.hsv2rgb({h:sint/maxspeed, s:1, v:1});
|
||||
let color = ((rgb.r * 0xff) << 16) |
|
||||
((rgb.g * 0xff) << 8) |
|
||||
((rgb.b * 0xff) << 0);
|
||||
if (opt.flat) {
|
||||
poly = poly.clone().setZ(0);
|
||||
}
|
||||
if (opt.aslines) {
|
||||
emits.poly(poly, opt.color || color, false, true);
|
||||
} else {
|
||||
// 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.renderAll();
|
||||
if (showmoves) {
|
||||
moves.render();
|
||||
scope.movesView.push(moves);
|
||||
}
|
||||
scope.printView.push(emits);
|
||||
scope.lines += print.length;
|
||||
});
|
||||
}
|
||||
|
||||
function toPoint(obj) {
|
||||
return base.newPoint(obj.x, obj.y, obj.z);
|
||||
}
|
||||
// FDM.printRender = function(print, options) {
|
||||
// let debug = KIRI.api.const.LOCAL;
|
||||
// let scope = print, emits, last,
|
||||
// moves, moving = true,
|
||||
// opt = options || {},
|
||||
// tools = opt.tools || [],
|
||||
// showmoves = !opt.nomoves,
|
||||
// maxspeed = 0;
|
||||
// // find max speed
|
||||
// scope.output.forEach(function(layerout) {
|
||||
// layerout.forEach(function(out, index) {
|
||||
// if (out.emit && out.speed) {
|
||||
// maxspeed = Math.max(maxspeed, out.speed);
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
// if (maxspeed === 0) {
|
||||
// maxspeed = 4000;
|
||||
// }
|
||||
// maxspeed *= 1.001;
|
||||
// // render layered output
|
||||
// scope.lines = 0;
|
||||
// scope.output.forEach(function(layerout) {
|
||||
// let move = [], print = [], cprint;
|
||||
// layerout.forEach(function(out, index) {
|
||||
// let point = toPoint(out.point);
|
||||
// if (last) {
|
||||
// // drop short segments
|
||||
// // if (point.emit === last.emit && UTIL.distSq(last, point) < 0.001 && point.z === last.z) {
|
||||
// // return;
|
||||
// // }
|
||||
// if (out.emit > 0) {
|
||||
// if (moving || !cprint) {
|
||||
// cprint = base.newPolygon().setOpen(true).append(last);
|
||||
// print.push({
|
||||
// poly: cprint,
|
||||
// speed: out.speed || maxspeed || 4000,
|
||||
// tool:tools[out.tool]
|
||||
// });
|
||||
// }
|
||||
// try {
|
||||
// cprint.append(point);
|
||||
// } catch (e) {
|
||||
// console.log(e, {cprint});
|
||||
// }
|
||||
// moving = false;
|
||||
// } else {
|
||||
// cprint = null;
|
||||
// move.push(last);
|
||||
// move.push(point);
|
||||
// moving = true;
|
||||
// }
|
||||
// // move direction arrow heads
|
||||
// if (debug && last.z == point.z) {
|
||||
// let rs = BASE.newSlope(
|
||||
// {x: point.x, y: point.y},
|
||||
// {x: last.x, y: last.y}
|
||||
// );
|
||||
// let ao1 = BASE.newSlopeFromAngle(rs.angle + 25);
|
||||
// let ao2 = BASE.newSlopeFromAngle(rs.angle - 25);
|
||||
// let sp = BASE.newPoint(point.x, point.y, point.z);
|
||||
// move.push(sp);
|
||||
// move.push(sp.projectOnSlope(ao1, BASE.config.debug_arrow));
|
||||
// move.push(sp);
|
||||
// move.push(sp.projectOnSlope(ao2, BASE.config.debug_arrow));
|
||||
// }
|
||||
// }
|
||||
// last = point;
|
||||
// });
|
||||
// emits = KIRI.newLayer(scope.group);
|
||||
// if (showmoves) {
|
||||
// moves = KIRI.newLayer(scope.group);
|
||||
// moves.lines(move, opt.move_color || 0x888888);
|
||||
// }
|
||||
// emits.setTransparent(false);
|
||||
// // emit printing shapes
|
||||
// print.forEach(segment => {
|
||||
// let {poly, speed, tool} = segment;
|
||||
// let off = tool ? (tool.extNozzle || 0.4) / 2 : 0.2;
|
||||
// let sint = Math.min(maxspeed, parseInt(speed));
|
||||
// let rgb = scope.hsv2rgb({h:sint/maxspeed, s:1, v:1});
|
||||
// let color = ((rgb.r * 0xff) << 16) |
|
||||
// ((rgb.g * 0xff) << 8) |
|
||||
// ((rgb.b * 0xff) << 0);
|
||||
// if (opt.flat) {
|
||||
// poly = poly.clone().setZ(0);
|
||||
// }
|
||||
// if (opt.aslines) {
|
||||
// emits.poly(poly, opt.color || color, false, true);
|
||||
// } else {
|
||||
// // 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.renderAll();
|
||||
// if (showmoves) {
|
||||
// moves.render();
|
||||
// scope.movesView.push(moves);
|
||||
// }
|
||||
// scope.printView.push(emits);
|
||||
// scope.lines += print.length;
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// function toPoint(obj) {
|
||||
// return base.newPoint(obj.x, obj.y, obj.z);
|
||||
// }
|
||||
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@
|
|||
/**
|
||||
* DRIVER PRINT CONTRACT
|
||||
*
|
||||
* @param {Object} print state object
|
||||
* @param {Function} update incremental callback
|
||||
* @param {Function} update progress callback
|
||||
* @returns {Object[]} returns array of render objects
|
||||
*/
|
||||
FDM.printSetup = function(print, update) {
|
||||
let widgets = print.widgets.slice(),
|
||||
settings = FDM.fixExtruders(print.settings),
|
||||
device = settings.device,
|
||||
FDM.prepare = function(widgets, settings, update) {
|
||||
settings = FDM.fixExtruders(settings);
|
||||
|
||||
let device = settings.device,
|
||||
nozzle = device.extruders[0].extNozzle,
|
||||
process = settings.process,
|
||||
mode = settings.mode,
|
||||
|
|
@ -40,7 +40,9 @@
|
|||
find,
|
||||
layerout = [],
|
||||
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
|
||||
// create brim, skirt, raft if specificed in FDM mode (code shared by laser)
|
||||
|
|
@ -371,19 +373,26 @@
|
|||
lastOut = undefined;
|
||||
}
|
||||
|
||||
print.output = render(output, progress => {
|
||||
print.output = FDM.prepareRender(output, progress => {
|
||||
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 = [];
|
||||
output.forEach((level, index) => {
|
||||
levels.forEach((level, index) => {
|
||||
const prints = {};
|
||||
const moves = [];
|
||||
const pushPrint = (tool, poly) => {
|
||||
let array = prints[tool] = prints[tool] || [];
|
||||
array.width = tools[tool].extNozzle / 2;
|
||||
const pushPrint = (toolid, poly) => {
|
||||
toolid = toolid || 0;
|
||||
const array = prints[toolid] = prints[toolid] || [];
|
||||
const tool = tools[toolid];
|
||||
array.width = (tool.extNozzle || 1) / 2;
|
||||
array.push(poly);
|
||||
};
|
||||
let lastOut = null;
|
||||
|
|
@ -418,11 +427,13 @@
|
|||
}
|
||||
lastOut = out;
|
||||
});
|
||||
const out = new KIRI.Render();
|
||||
layers.push(out);
|
||||
out.setLayer('move', 0xaaaaaa).addPolys(moves);
|
||||
const output = new KIRI.Render();
|
||||
layers.push(output);
|
||||
output.setLayer('move', 0xaaaaaa).addPolys(moves);
|
||||
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);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue