add ability to visualize tool usage in preview
This commit is contained in:
parent
cbb446eda1
commit
7ff1836a32
3 changed files with 65 additions and 10 deletions
|
|
@ -34,7 +34,7 @@
|
|||
"three": "^0.126.0",
|
||||
"@tweenjs/tween.js": "^16.6.0",
|
||||
"uglify-es": "3.3.9",
|
||||
"validator": "^8.2.0",
|
||||
"validator": ">=13.7.0",
|
||||
"ws": "^7.5.5"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,11 @@
|
|||
// add show() to catalog for API
|
||||
CATALOG.show = showCatalog;
|
||||
|
||||
const PMODES = {
|
||||
SPEED: 1,
|
||||
TOOLS: 2
|
||||
};
|
||||
|
||||
const feature = {
|
||||
seed: true, // seed profiles on first use
|
||||
meta: true, // show selected widget metadata
|
||||
|
|
@ -73,7 +78,8 @@
|
|||
on_load: undefined, // function override file drop loads
|
||||
on_add_stl: undefined, // legacy override stl drop loads
|
||||
work_alerts: true, // allow disabling work progress alerts
|
||||
modes: [ "fdm", "sla", "cam", "laser" ] // enable device modes
|
||||
modes: [ "fdm", "sla", "cam", "laser" ], // enable device modes
|
||||
pmode: PMODES.SPEED // preview modes
|
||||
};
|
||||
|
||||
const selection = {
|
||||
|
|
@ -1048,6 +1054,7 @@
|
|||
|
||||
function updateSpeeds(maxSpeed, minSpeed) {
|
||||
UI.speeds.style.display =
|
||||
maxSpeed &&
|
||||
settings.mode !== 'SLA' &&
|
||||
settings.mode !== 'LASER' &&
|
||||
viewMode === VIEWS.PREVIEW &&
|
||||
|
|
@ -1253,14 +1260,13 @@
|
|||
}
|
||||
|
||||
function preparePreview(callback, scale = 1, offset = 0) {
|
||||
if (complete.preview) {
|
||||
if (complete.preview === feature.pmode) {
|
||||
if (callback) callback();
|
||||
return;
|
||||
}
|
||||
if (!complete.slice) {
|
||||
settings.render = false;
|
||||
prepareSlices(() => {
|
||||
settings.render = true;
|
||||
preparePreview(callback, 0.25, 0.75);
|
||||
}, 0.75);
|
||||
return;
|
||||
|
|
@ -1290,6 +1296,10 @@
|
|||
lastMsg,
|
||||
output = [];
|
||||
|
||||
// pass preview mode to worker
|
||||
settings.pmode = feature.pmode;
|
||||
settings.render = true;
|
||||
|
||||
KIRI.client.prepare(settings, function(progress, message, layer) {
|
||||
if (layer) {
|
||||
output.push(KIRI.codec.decode(layer));
|
||||
|
|
@ -1350,11 +1360,15 @@
|
|||
SPACE.update();
|
||||
updateSliderMax(true);
|
||||
setVisibleLayer(-1, 0);
|
||||
updateSpeeds(maxSpeed, minSpeed);
|
||||
if (feature.pmode === PMODES.SPEED) {
|
||||
updateSpeeds(maxSpeed, minSpeed);
|
||||
} else {
|
||||
updateSpeeds();
|
||||
}
|
||||
updateStackLabelState();
|
||||
|
||||
// mark preview complete for export
|
||||
complete.preview = true;
|
||||
complete.preview = feature.pmode;
|
||||
|
||||
if (typeof(callback) === 'function') {
|
||||
callback();
|
||||
|
|
|
|||
|
|
@ -423,6 +423,17 @@
|
|||
}
|
||||
}
|
||||
|
||||
// clear slice.prep so it can be re-previewed in a different mode
|
||||
for (let widget of widgets) {
|
||||
// skip synthesized support widget(s)
|
||||
if (!widget.mesh) {
|
||||
continue;
|
||||
}
|
||||
for (let slice of widget.slices) {
|
||||
slice.prep = false;
|
||||
}
|
||||
}
|
||||
|
||||
// if a declared extruder isn't used in a layer, use selected
|
||||
// extruder to fill the relevant purge blocks for later support
|
||||
track.forEach(ext => {
|
||||
|
|
@ -575,7 +586,13 @@
|
|||
if (render) {
|
||||
print.render = FDM.prepareRender(output, (progress, layer) => {
|
||||
update(0.5 + progress * 0.5, "render", layer);
|
||||
}, { tools: device.extruders, thin: isThin, flat: isFlat, fdm: true });
|
||||
}, {
|
||||
toolMode: settings.pmode === 2,
|
||||
tools: device.extruders,
|
||||
thin: isThin,
|
||||
flat: isFlat,
|
||||
fdm: true
|
||||
});
|
||||
}
|
||||
|
||||
return print.render;
|
||||
|
|
@ -618,6 +635,7 @@
|
|||
const arrowAll = false;
|
||||
const arrowSize = arrowAll ? 0.2 : 0.4;
|
||||
const layers = [];
|
||||
const toolMode = opts.toolMode;
|
||||
|
||||
const moveOpt = {
|
||||
face: moveColor,
|
||||
|
|
@ -632,6 +650,7 @@
|
|||
|
||||
let minspd = Infinity;
|
||||
let maxspd = 0;
|
||||
let maxtool = [];
|
||||
|
||||
for (let level of levels) {
|
||||
for (let o of level) {
|
||||
|
|
@ -639,6 +658,11 @@
|
|||
minspd = Math.min(minspd, o.speed);
|
||||
maxspd = Math.max(maxspd, o.speed);
|
||||
}
|
||||
if (toolMode && o.tool !== undefined) {
|
||||
if (maxtool.indexOf(o.tool) < 0) {
|
||||
maxtool.push(o.tool);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -652,6 +676,7 @@
|
|||
self.worker.print.thinColor = thin;
|
||||
self.worker.print.flatColor = flat;
|
||||
|
||||
let lastTool = null;
|
||||
let lastEnd = null;
|
||||
let lastOut = null;
|
||||
let current = null;
|
||||
|
|
@ -659,13 +684,18 @@
|
|||
let retractz = 0;
|
||||
|
||||
function color(point) {
|
||||
return FDM.rateToColor(point.speed, maxspd);
|
||||
if (toolMode) {
|
||||
return FDM.rateToColor(maxtool.indexOf(point.tool), maxtool.length);
|
||||
} else {
|
||||
return FDM.rateToColor(point.speed, maxspd);
|
||||
}
|
||||
}
|
||||
|
||||
levels.forEach((level, index) => {
|
||||
const prints = {};
|
||||
const moves = [];
|
||||
const heads = [];
|
||||
const changes = [];
|
||||
const retracts = [];
|
||||
const engages = [];
|
||||
const output = new KIRI.Layers();
|
||||
|
|
@ -689,6 +719,10 @@
|
|||
retracted = false;
|
||||
engages.push(lastOut.point);
|
||||
}
|
||||
if (out.tool !== lastTool) {
|
||||
lastTool = out.tool;
|
||||
changes.push(out.point);
|
||||
}
|
||||
if (out.retract) {
|
||||
retracts.push(out.point);
|
||||
retracted = true;
|
||||
|
|
@ -743,18 +777,25 @@
|
|||
pushPrint(lastOut.tool, current)
|
||||
}
|
||||
lastEnd = lastOut;
|
||||
if (changes.length) {
|
||||
output
|
||||
.setLayer('tool', { line: 0x000055, face: 0x0000ff, opacity: 0.5 }, true)
|
||||
.addAreas(changes.map(point => {
|
||||
return newPolygon().centerCircle(point, 0.2, 4).setZ(point.z + 0.03);
|
||||
}), { outline: true });
|
||||
}
|
||||
if (retracts.length) {
|
||||
output
|
||||
.setLayer('retract', { line: 0x550000, face: 0xff0000, opacity: 0.5 }, true)
|
||||
.addAreas(retracts.map(point => {
|
||||
return newPolygon().centerCircle(point, 0.2, 16).setZ(point.z + 0.01);
|
||||
return newPolygon().centerCircle(point, 0.2, 5).setZ(point.z + 0.01);
|
||||
}), { outline: true });
|
||||
}
|
||||
if (engages.length) {
|
||||
output
|
||||
.setLayer('engage', { line: 0x005500, face: 0x00ff00, opacity: 0.5 }, true)
|
||||
.addAreas(engages.map(point => {
|
||||
return newPolygon().centerCircle(point, 0.2, 16).setZ(point.z + 0.01);
|
||||
return newPolygon().centerCircle(point, 0.2, 7).setZ(point.z + 0.02);
|
||||
}), { outline: true });
|
||||
}
|
||||
if (heads.length) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue