checkpoint manual tab work

This commit is contained in:
Stewart Allen 2020-11-25 16:46:51 -05:00
commit 7f842c7a8b
2 changed files with 82 additions and 36 deletions

View file

@ -1,6 +1,6 @@
# Kiri:Moto todo # Kiri:Moto todo and notes
## 2.4 tentative list ## 2.4 roadmap
* cnc * cnc
* tracing (chamfer, engrave) * tracing (chamfer, engrave)
* auto feature detection (slicing), manual tabs * auto feature detection (slicing), manual tabs
@ -14,6 +14,15 @@
* memory optimization (worker and client proactive cleanup) * memory optimization (worker and client proactive cleanup)
* circular fit/layout when no-layout to prevent collisions * circular fit/layout when no-layout to prevent collisions
## 2.5 roadmap
# cnc
# lathe?
# complex process order
# fdm
# redo automatic supports using faces instead of deltas
# bind process to z ranges or boxed regions
# non-planar actual
## `C` cosmetic, `F` functional, `P` performance, `B` bug fix ## `C` cosmetic, `F` functional, `P` performance, `B` bug fix
* `F` 2D image import * `F` 2D image import

View file

@ -15,9 +15,11 @@
isCamMode, isCamMode,
isParsed, isParsed,
camStock, camStock,
func = {},
API, FDM, SPACE, STACKS, MODES, VIEWS, UI, UC; API, FDM, SPACE, STACKS, MODES, VIEWS, UI, UC;
let zaxis = {x: 0, y: 0, z: 1},
func = {};
CAM.init = function(kiri, api) { CAM.init = function(kiri, api) {
FDM = KIRI.driver.FDM; FDM = KIRI.driver.FDM;
@ -56,6 +58,11 @@
updateStock(settings, 'settings.saved.internal'); updateStock(settings, 'settings.saved.internal');
}); });
api.event.on("settings.load", (settings) => {
if (!isCamMode) return;
restoreTabs(api.widgets.all());
});
api.event.on([ api.event.on([
"init-done", "init-done",
// update stock when modes change? // update stock when modes change?
@ -134,20 +141,22 @@
} }
const {widget, x, y, z} = rot; const {widget, x, y, z} = rot;
if (x || y) { if (x || y) {
// clearWidgetSupports(widget); clearTabs(widget);
} else { } else {
let ann = API.widgets.annotate(widget.id); let tabs = API.widgets.annotate(widget.id).tab || [];
let tabs = ann.support || []; tabs.forEach(rec => {
// tabs.forEach(sup => { let { id, pos } = rec;
// let wsup = widget.tabs[sup.id]; let tab = widget.tabs[id];
// let vc = new THREE.Vector3(sup.x, sup.y, sup.z); let vc = new THREE.Vector3(pos.x, pos.y, pos.z);
// let m4 = new THREE.Matrix4(); let m4 = new THREE.Matrix4();
// m4 = m4.makeRotationFromEuler(new THREE.Euler(x || 0, y || 0, z || 0)); m4 = m4.makeRotationFromEuler(new THREE.Euler(x || 0, y || 0, z || 0));
// vc.applyMatrix4(m4); vc.applyMatrix4(m4);
// wsup.box.position.x = wsup.x = sup.x = vc.x; tab.box.geometry.applyMatrix4(m4);
// wsup.box.position.y = wsup.y = sup.y = vc.y; tab.box.position.x = pos.x = vc.x;
// wsup.box.position.z = wsup.z = sup.z = vc.z; tab.box.position.y = pos.y = vc.y;
// }); tab.box.position.z = pos.z = vc.z;
});
SPACE.update();
} }
}); });
api.event.on("mouse.hover.up", int => { api.event.on("mouse.hover.up", int => {
@ -175,14 +184,19 @@
let ip = iw.track.pos; let ip = iw.track.pos;
let wa = api.widgets.annotate(iw.id); let wa = api.widgets.annotate(iw.id);
let wt = (wa.tab = wa.tab || []); let wt = (wa.tab = wa.tab || []);
let x = ic.x - ip.x, y = -ic.z - ip.y, z = 0, id = Date.now(); let pos = {
let rec = {x, y, z, dw:10, dh:10, id}; x: showTab.pos.x - ip.x,
y: -showTab.pos.z - ip.y,
z: showTab.pos.y + ip.z,
}
let id = Date.now();
let { dim, rot } = showTab;
let rec = { pos, dim, rot, id };
wt.push(Object.clone(rec)); wt.push(Object.clone(rec));
addWidgetTab(iw, rec); addWidgetTab(iw, rec);
API.conf.save(); API.conf.save();
}); });
const zaxis = {x: 0, y: 0, z: 1}; let showTab, lastTab, tab, iw, ic;
let lastTab, tab, iw, ic;
api.event.on("mouse.hover", data => { api.event.on("mouse.hover", data => {
if (!isCamMode) { if (!isCamMode) {
return; return;
@ -211,35 +225,58 @@
if (Math.abs(n.z) > 0.1) { if (Math.abs(n.z) > 0.1) {
return; return;
} }
showTab = createTabBox(iw, ic, n);
});
};
function createTabBox(iw, ic, n) {
const { track } = iw; const { track } = iw;
const { stock, bounds, process } = API.conf.get(); const { stock, bounds, process } = API.conf.get();
const { camTabsWidth, camTabsHeight } = process; const { camTabsWidth, camTabsHeight } = process;
const zp = stock.z - track.box.d + process.camZBottom - process.camZTopOffset + camTabsHeight / 2; const zp = stock.z - track.box.d + process.camZBottom - process.camZTopOffset + camTabsHeight / 2;
ic.x += n.x * 2.5; ic.x += n.x * 2.5; // offset from part
ic.z -= n.y * 2.5; ic.z -= n.y * 2.5; // offset swap z,y
ic.y = zp; // swap in world space y,z ic.y = zp; // offset swap in world space y,z
const q = new THREE.Quaternion().setFromAxisAngle(zaxis, Math.atan2(n.y, n.x)); const rot = new THREE.Quaternion().setFromAxisAngle(zaxis, Math.atan2(n.y, n.x));
addbox({x:ic.x, y:ic.y, z:ic.z}, 0x0000dd, 'supp', { const pos = { x:ic.x, y:ic.y, z:ic.z };
x:5, y:camTabsWidth, z:camTabsHeight const dim = { x:5, y:camTabsWidth, z:camTabsHeight };
}, { rotate: q }); const tab = addbox(pos, 0x0000dd, 'supp', dim, { rotate: rot });
}); return { pos, dim, rot, tab, width: camTabsWidth, height: camTabsHeight };
}; }
function addWidgetTab(widget, pos) { function addWidgetTab(widget, rec) {
const { x, y, z, dw, dh, id } = pos; const { pos, dim, rot, id } = rec;
const tabs = widget.tabs = (widget.tabs || {}); const tabs = widget.tabs = (widget.tabs || {});
// prevent duplicate restore from repeated settings load calls // prevent duplicate restore from repeated settings load calls
if (!tabs[id]) { if (!tabs[id]) {
pos.box = addbox( pos.box = addbox(
{ x, y, z }, 0x0000dd, 'supp', pos, 0x0000dd, id,
{ x:dw, y:dw, z:dh }, { group: widget.mesh } dim, { group: widget.mesh, rotate: rot }
); );
pos.box.tab = Object.assign({widget}, pos); pos.box.tab = Object.assign({widget}, pos);
tabs[id] = pos;
widget.adds.push(pos.box); widget.adds.push(pos.box);
tabs[id] = pos;
} }
} }
function restoreTabs(widgets) {
widgets.forEach(widget => {
const tabs = API.widgets.annotate(widget.id).tab || [];
tabs.forEach(rec => {
addWidgetTab(widget, rec);
});
});
}
function clearTabs(widget) {
Object.values(widget.tabs || {}).forEach(rec => {
widget.adds.remove(rec.box);
widget.mesh.remove(rec.box);
});
widget.tabs = {};
delete API.widgets.annotate(widget.id).tab;
}
function addbox() { return FDM.addbox(...arguments)}; function addbox() { return FDM.addbox(...arguments)};
function delbox() { return FDM.delbox(...arguments)}; function delbox() { return FDM.delbox(...arguments)};