checkpoint trace work

This commit is contained in:
Stewart Allen 2020-12-01 19:54:54 -05:00
commit 44c1c850e9
11 changed files with 82 additions and 24 deletions

View file

@ -2187,7 +2187,7 @@
UI.back.style.display = ''; UI.back.style.display = '';
UI.render.style.display = ''; UI.render.style.display = '';
UI.render.classList.add('lt-enabled'); UI.render.classList.add('lt-enabled');
KIRI.work.clear(); // KIRI.work.clear();
STACKS.clear(); STACKS.clear();
hideSlider(); hideSlider();
updateSpeeds(); updateSpeeds();

View file

@ -74,7 +74,7 @@
} }
const { polys, lines, faces, cface, paths, cpath, color, off } = layer; const { polys, lines, faces, cface, paths, cpath, color, off } = layer;
const meshes = this.meshes; const meshes = [];
const defstate = !off; const defstate = !off;
const mats = []; const mats = [];
mats.state = defstate; mats.state = defstate;
@ -185,6 +185,8 @@
mats.appendAll(mat); mats.appendAll(mat);
} }
this.new_meshes = meshes;
this.meshes.appendAll(meshes);
mats.forEach(mat => mat.visible = defstate); mats.forEach(mat => mat.visible = defstate);
return mats; return mats;
} }

View file

@ -390,7 +390,8 @@
*/ */
PRO.setTopZ = function(z) { PRO.setTopZ = function(z) {
let mesh = this.mesh, let mesh = this.mesh,
pos = this.track.pos; pos = this.track.pos,
ltz = this.last_top_z || {};
if (z) { if (z) {
pos.z = mesh.getBoundingBox().max.z - z; pos.z = mesh.getBoundingBox().max.z - z;
mesh.position.z = -pos.z - 0.01; mesh.position.z = -pos.z - 0.01;
@ -398,7 +399,12 @@
pos.z = 0; pos.z = 0;
mesh.position.z = 0; mesh.position.z = 0;
} }
this.modified = true; let ntz = {
pz: pos.z,
mpz: mesh.position.z
};
this.modified |= (ltz.pz !== ntz.pz || ltz.mpz !== ntz.mpz);
this.last_top_z = ntz;
} }
PRO.move = function(x, y, z, abs) { PRO.move = function(x, y, z, abs) {
@ -448,6 +454,7 @@
scale.x *= (x || 1.0); scale.x *= (x || 1.0);
scale.y *= (y || 1.0); scale.y *= (y || 1.0);
scale.z *= (z || 1.0); scale.z *= (z || 1.0);
this.modified = true;
}; };
PRO.rotate = function(x, y, z) { PRO.rotate = function(x, y, z) {
@ -478,6 +485,7 @@
rot.y += (y || 0); rot.y += (y || 0);
rot.z += (z || 0); rot.z += (z || 0);
} }
this.modified = true;
}; };
PRO.unrotate = function() { PRO.unrotate = function() {
@ -486,6 +494,7 @@
}); });
this.roto = []; this.roto = [];
this.center(); this.center();
this.modified = true;
}; };
PRO.mirror = function() { PRO.mirror = function() {
@ -511,6 +520,7 @@
geo.computeFaceNormals(); geo.computeFaceNormals();
geo.computeVertexNormals(); geo.computeVertexNormals();
o.mirror = !o.mirror; o.mirror = !o.mirror;
this.modified = true;
}; };
PRO.getGeoVertices = function() { PRO.getGeoVertices = function() {
@ -593,7 +603,6 @@
ondone(false, reply.error); ondone(false, reply.error);
} }
if (reply.done) { if (reply.done) {
widget.modified = false;
ondone(true); ondone(true);
} }
}); });
@ -609,7 +618,6 @@
onupdate(1.0, "transfer"); onupdate(1.0, "transfer");
widget.stats.slice_time = UTIL.time() - startTime; widget.stats.slice_time = UTIL.time() - startTime;
widget.modified = false;
ondone(); ondone();
}; };

View file

@ -305,6 +305,15 @@ self.kiri.loader.push(function() {
animating = true; animating = true;
stepsRemain--; stepsRemain--;
if (next.tool >= 0 && (!tool || tool.getNumber() !== next.tool)) { if (next.tool >= 0 && (!tool || tool.getNumber() !== next.tool)) {
// on real tool change, go to safe Z first
if (tool) {
let pos = last.point = {
x: last.point.x,
y: last.point.y,
z: stock.z
};
send.data({ mesh_move: { toolID, pos }});
}
updateTool(next.tool, send); updateTool(next.tool, send);
} }
const id = toolID; const id = toolID;

View file

@ -10,6 +10,7 @@
PRO = CAM.process, PRO = CAM.process,
newPolygon = BASE.newPolygon, newPolygon = BASE.newPolygon,
newPoint = BASE.newPoint, newPoint = BASE.newPoint,
toolInfo,
isAnimate, isAnimate,
isArrange, isArrange,
isCamMode, isCamMode,
@ -33,6 +34,8 @@
UC = api.uc; UC = api.uc;
API = api; API = api;
toolInfo = $('tool-info');
api.event.on("mode.set", (mode) => { api.event.on("mode.set", (mode) => {
isCamMode = mode === 'CAM'; isCamMode = mode === 'CAM';
$('set-tools').style.display = isCamMode ? '' : 'none'; $('set-tools').style.display = isCamMode ? '' : 'none';
@ -239,18 +242,21 @@
alert = api.show.alert("[esc] key cancels trace editing"); alert = api.show.alert("[esc] key cancels trace editing");
KIRI.api.widgets.opacity(0.5); KIRI.api.widgets.opacity(0.5);
KIRI.api.widgets.for(widget => { KIRI.api.widgets.for(widget => {
if (widget.trace_stack) {
widget.adds.appendAll(widget.trace_stack.meshes);
widget.trace_stack.show();
return;
}
let stack = new KIRI.Stack(widget.mesh); let stack = new KIRI.Stack(widget.mesh);
widget.trace_stack = stack; widget.trace_stack = stack;
widget.traces.forEach(poly => { widget.traces.forEach(poly => {
let layers = new KIRI.Layers(); let layers = new KIRI.Layers();
layers.setLayer("trace", {line: 0x88aa55}, false).addPoly(poly); layers.setLayer("trace", {line: 0x88aa55}, false).addPoly(poly);
stack.addLayers(layers); stack.addLayers(layers);
stack.meshes.forEach(mesh => { stack.new_meshes.forEach(mesh => {
mesh.trace = {widget, poly}; mesh.trace = {widget, poly};
}); });
// reset so each mesh array is new for the layer widget.adds.appendAll(stack.new_meshes);
widget.adds.appendAll(stack.meshes);
stack.meshes = [];
}); });
// for (let [key, val] of Object.entries(widget.sindex)) { // for (let [key, val] of Object.entries(widget.sindex)) {
// console.log('sindex', {key, val}); // console.log('sindex', {key, val});
@ -276,8 +282,8 @@
api.feature.hoverAdds = false; api.feature.hoverAdds = false;
KIRI.api.widgets.for(widget => { KIRI.api.widgets.for(widget => {
if (widget.trace_stack) { if (widget.trace_stack) {
widget.trace_stack.hide();
widget.adds.removeAll(widget.trace_stack.meshes); widget.adds.removeAll(widget.trace_stack.meshes);
widget.trace_stack.destroy();
} }
}); });
}); });
@ -300,6 +306,18 @@
return; return;
} }
lastTrace = data.int.object; lastTrace = data.int.object;
if (lastTrace.selected) {
let traceInfo = lastTrace.trace.poly.traceInfo;
let tool = new CAM.Tool(current, traceInfo.tool);
toolInfo.innerText = [
` tool: ${tool.getName()}`,
` feed: ${traceInfo.speed}`,
`plunge: ${traceInfo.plunge}`
].join('\n');
toolInfo.style.display = 'flex';
} else {
toolInfo.style.display = '';
}
let material = lastTrace.material[0]; let material = lastTrace.material[0];
let color = material.color; let color = material.color;
let {r, g, b} = color; let {r, g, b} = color;
@ -310,7 +328,6 @@
}; };
func.traceHoverUp = function(int) { func.traceHoverUp = function(int) {
if (!int) return; if (!int) return;
console.log({traceHoverUp: int});
func.traceToggle(int.object); func.traceToggle(int.object);
}; };
func.traceToggle = function(obj) { func.traceToggle = function(obj) {
@ -461,13 +478,15 @@
} }
function clearTraces(widget) { function clearTraces(widget) {
Object.values(widget.traces || {}).forEach(rec => { let stack = widget.trace_stack;
console.log('clear',rec); if (stack) {
// widget.adds.remove(rec.box); stack.meshes.forEach(mesh => {
// widget.mesh.remove(rec.box); if (mesh.selected) {
func.traceToggle(mesh);
}
}); });
widget.traces = {}; }
widget.trace_stack = null; widget.trace = null;
delete API.widgets.annotate(widget.id).trace; delete API.widgets.annotate(widget.id).trace;
} }

View file

@ -42,8 +42,8 @@
KIRI.worker.traces = function(data, send) { KIRI.worker.traces = function(data, send) {
const { settings } = data; const { settings } = data;
const widgets = Object.values(cache); const widgets = Object.values(cache);
widgets.forEach(widget => CAM.traces(settings, widget)); const fresh = widgets.filter(widget => CAM.traces(settings, widget));
send.done(KIRI.codec.encode(widgets.map(widget => {return { send.done(KIRI.codec.encode(fresh.map(widget => {return {
id: widget.id, id: widget.id,
traces: widget.traces, traces: widget.traces,
// sindex: widget.sindex // sindex: widget.sindex

View file

@ -75,6 +75,8 @@
easeDown = process.camEaseDown, easeDown = process.camEaseDown,
depthFirst = process.camDepthFirst, depthFirst = process.camDepthFirst,
tolerance = process.camTolerance, tolerance = process.camTolerance,
contour = process.camContourXOn || process.camContourYOn,
contourCurves = process.camContourCurves,
drillDown = process.camDrillDown, drillDown = process.camDrillDown,
drillLift = process.camDrillLift, drillLift = process.camDrillLift,
drillDwell = process.camDrillDwell, drillDwell = process.camDrillDwell,
@ -550,7 +552,7 @@
printPoint = depthOutlinePath(printPoint, 0, flatLevels, toolDiam, polyEmit, true); printPoint = depthOutlinePath(printPoint, 0, flatLevels, toolDiam, polyEmit, true);
} }
// two modes for deferred outlining: x then y or combined // two modes for deferred outlining: x then y or combined
if (process.camContourCurves) { if (contour && contourCurves) {
lastMode = PRO.CONTOUR_X; lastMode = PRO.CONTOUR_X;
setTool(process.camContourTool, process.camContourSpeed, process.camContourPlunge); setTool(process.camContourTool, process.camContourSpeed, process.camContourPlunge);
spindle = Math.min(spindleMax, process.camContourSpindle); spindle = Math.min(spindleMax, process.camContourSpindle);
@ -567,7 +569,7 @@
newLayer(); newLayer();
return lastPoint; return lastPoint;
}); });
} else { } else if (contour) {
setTool(process.camContourTool, process.camContourSpeed, process.camContourPlunge); setTool(process.camContourTool, process.camContourSpeed, process.camContourPlunge);
spindle = Math.min(spindleMax, process.camContourSpindle); spindle = Math.min(spindleMax, process.camContourSpindle);
// deferred contour x outlining // deferred contour x outlining

View file

@ -503,7 +503,6 @@
.addPolys(slice.topPolys()) .addPolys(slice.topPolys())
sliceAll.push(slice); sliceAll.push(slice);
maxToolDiam = Math.max(maxToolDiam, traceToolDiam); maxToolDiam = Math.max(maxToolDiam, traceToolDiam);
console.log({slice});
}); });
} }
@ -537,6 +536,10 @@ console.log({slice});
}; };
CAM.traces = function computeTraces(settings, widget) { CAM.traces = function computeTraces(settings, widget) {
if (widget.traces) {
// do no work if cached
return false;
}
let slicer = new KIRI.slicer2(widget.getPoints(), { let slicer = new KIRI.slicer2(widget.getPoints(), {
zlist: true, zlist: true,
zline: true zline: true
@ -615,6 +618,7 @@ console.log({slice});
slicer.slice(indices, opts); slicer.slice(indices, opts);
widget.traces = traces; widget.traces = traces;
// widget.sindex = sindex; // widget.sindex = sindex;
return true;
}; };
// drilling op // drilling op

View file

@ -28,6 +28,10 @@
return this.tool.id; return this.tool.id;
} }
getName() {
return this.tool.name;
}
getType() { getType() {
return this.tool.type; return this.tool.type;
} }

View file

@ -1196,6 +1196,15 @@ th, tr, td, label {
right: 5px; right: 5px;
color: #000; color: #000;
} }
#tool-info {
position: fixed;
white-space: pre;
font-family: monospace;
font-size: 12px;
bottom: 5px;
left: 5px;
color: #000;
}
#winfo { #winfo {
position: fixed; position: fixed;
font-size: 10px; font-size: 10px;

View file

@ -390,6 +390,7 @@
<p>this site uses cookies to preserve application preferences</p> <p>this site uses cookies to preserve application preferences</p>
<button id="gotit" class="f-col j-center">got it</button> <button id="gotit" class="f-col j-center">got it</button>
</div> </div>
<div id="tool-info" class="noshow"></div>
<div id="fps" class="noshow"></div> <div id="fps" class="noshow"></div>
<div id="layer-animate" class="f-col a-center"></div> <div id="layer-animate" class="f-col a-center"></div>
<div id="layer-toolpos" class="f-row a-center"></div> <div id="layer-toolpos" class="f-row a-center"></div>