refactor cam stock visualization

This commit is contained in:
Stewart Allen 2020-11-14 11:12:12 -05:00
commit 8a1118d6c1
12 changed files with 253 additions and 189 deletions

View file

@ -1,12 +1,14 @@
# Kiri:Moto todo # Kiri:Moto todo
## 2.3 remaining ## 2.3 remaining
* stock to outline for slice mode * adaptive shadow-line generation for small parts collision detection
* test path clearance for every move > % of tool diam and ...
* contour tabs support * contour tabs support
* path arrows, retracts, and engages * path arrows, retracts, and engages
* cap path ends * cap path ends
* help dialog * help dialog
* full bug reports * full bug reports
* onshape mouse mapping option
## 2.4 ## 2.4
* cnc: tracing, visualization, manual tabs * cnc: tracing, visualization, manual tabs

View file

@ -1,6 +1,6 @@
{ {
"name": "grid-apps", "name": "grid-apps",
"version": "2.3.8D", "version": "2.3.9D",
"description": "grid.space 3d slice & modeling tools", "description": "grid.space 3d slice & modeling tools",
"author": "Stewart Allen <sa@grid.space>", "author": "Stewart Allen <sa@grid.space>",
"license": "MIT", "license": "MIT",

View file

@ -453,6 +453,7 @@
camStockY: 0, camStockY: 0,
camStockZ: 0, camStockZ: 0,
camStockOffset: true, camStockOffset: true,
camStockOn: false,
camConventional: false, // outputClockwise camConventional: false, // outputClockwise
outputOriginCenter: false, outputOriginCenter: false,
outputInvertX: false, outputInvertX: false,

View file

@ -136,7 +136,7 @@
control.decimate = UI.decimate.checked; control.decimate = UI.decimate.checked;
SPACE.view.setZoom(control.reverseZoom, control.zoomSpeed); SPACE.view.setZoom(control.reverseZoom, control.zoomSpeed);
platform.layout(); platform.layout();
platform.update_stock(); // platform.update_stock();
API.conf.save(); API.conf.save();
API.mode.set_expert(control.expert); API.mode.set_expert(control.expert);
API.platform.update_size(); API.platform.update_size();
@ -145,6 +145,7 @@
}); });
UC.setHoverPop(control.hoverPop); UC.setHoverPop(control.hoverPop);
updateFPS(); updateFPS();
API.event.emit('boolean.update');
} }
function updateFPS() { function updateFPS() {
@ -170,6 +171,7 @@
} }
API.conf.update(); API.conf.update();
DOC.activeElement.blur(); DOC.activeElement.blur();
// API.event.emit("boolean.click");
} }
function inputHasFocus() { function inputHasFocus() {
@ -1483,6 +1485,7 @@
camContourOver: UC.newInput(LANG.cc_sovr_s, {title:LANG.cc_sovr_l, convert:UC.toFloat, bound:UC.bound(0.05,1.0), modes:CAM}), camContourOver: UC.newInput(LANG.cc_sovr_s, {title:LANG.cc_sovr_l, convert:UC.toFloat, bound:UC.bound(0.05,1.0), modes:CAM}),
camContourSpeed: UC.newInput(LANG.cc_feed_s, {title:LANG.cc_feed_l, convert:UC.toInt, modes:CAM, units:true}), camContourSpeed: UC.newInput(LANG.cc_feed_s, {title:LANG.cc_feed_l, convert:UC.toInt, modes:CAM, units:true}),
camContourAngle: UC.newInput(LANG.cf_angl_s, {title:LANG.cf_angl_l, convert:UC.toFloat, bound:UC.bound(45,90), modes:CAM}), camContourAngle: UC.newInput(LANG.cf_angl_s, {title:LANG.cf_angl_l, convert:UC.toFloat, bound:UC.bound(45,90), modes:CAM}),
camTolerance: UC.newInput(LANG.ou_toll_s, {title:LANG.ou_toll_l, convert:UC.toFloat, bound:UC.bound(0.001,1.0), modes:CAM, units:true}),
camContourCurves: UC.newBoolean(LANG.cf_curv_s, onBooleanClick, {title:LANG.cf_curv_l, modes:CAM}), camContourCurves: UC.newBoolean(LANG.cf_curv_s, onBooleanClick, {title:LANG.cf_curv_l, modes:CAM}),
camContourIn: UC.newBoolean(LANG.cf_olin_s, onBooleanClick, {title:LANG.cf_olin_l, modes:CAM}), camContourIn: UC.newBoolean(LANG.cf_olin_s, onBooleanClick, {title:LANG.cf_olin_l, modes:CAM}),
camContourSep: UC.newBlank({class:"pop-sep"}), camContourSep: UC.newBlank({class:"pop-sep"}),
@ -1518,6 +1521,8 @@
camStockY: UC.newInput(LANG.cs_dpth_s, {title:LANG.cs_dpth_l, convert:UC.toFloat, bound:UC.bound(0,9999), modes:CAM, units:true}), camStockY: UC.newInput(LANG.cs_dpth_s, {title:LANG.cs_dpth_l, convert:UC.toFloat, bound:UC.bound(0,9999), modes:CAM, units:true}),
camStockZ: UC.newInput(LANG.cs_hght_s, {title:LANG.cs_hght_l, convert:UC.toFloat, bound:UC.bound(0,9999), modes:CAM, units:true}), camStockZ: UC.newInput(LANG.cs_hght_s, {title:LANG.cs_hght_l, convert:UC.toFloat, bound:UC.bound(0,9999), modes:CAM, units:true}),
camStockOffset: UC.newBoolean(LANG.cs_offs_s, onBooleanClick, {title:LANG.cs_offs_l, modes:CAM}), camStockOffset: UC.newBoolean(LANG.cs_offs_s, onBooleanClick, {title:LANG.cs_offs_l, modes:CAM}),
camStockSep: UC.newBlank({class:"pop-sep"}),
camStockOn: UC.newBoolean(LANG.cs_offe_s, onBooleanClick, {title:LANG.cs_offe_l, modes:CAM}),
camCommon: UC.newGroup(LANG.cc_menu, null, {modes:CAM}), camCommon: UC.newGroup(LANG.cc_menu, null, {modes:CAM}),
camZTopOffset: UC.newInput(LANG.ou_ztof_s, {title:LANG.ou_ztof_l, convert:UC.toFloat, modes:CAM, units:true}), camZTopOffset: UC.newInput(LANG.ou_ztof_s, {title:LANG.ou_ztof_l, convert:UC.toFloat, modes:CAM, units:true}),
@ -1526,7 +1531,6 @@
camZThru: UC.newInput(LANG.ou_ztru_s, {title:LANG.ou_ztru_l, convert:UC.toFloat, bound:UC.bound(0.0,100), modes:CAM, units:true, show:() => { return UI.camZBottom.value == 0 }}), camZThru: UC.newInput(LANG.ou_ztru_s, {title:LANG.ou_ztru_l, convert:UC.toFloat, bound:UC.bound(0.0,100), modes:CAM, units:true, show:() => { return UI.camZBottom.value == 0 }}),
camFastFeedZ: UC.newInput(LANG.cc_rzpd_s, {title:LANG.cc_rzpd_l, convert:UC.toFloat, modes:CAM, units:true}), camFastFeedZ: UC.newInput(LANG.cc_rzpd_s, {title:LANG.cc_rzpd_l, convert:UC.toFloat, modes:CAM, units:true}),
camFastFeed: UC.newInput(LANG.cc_rapd_s, {title:LANG.cc_rapd_l, convert:UC.toFloat, modes:CAM, units:true}), camFastFeed: UC.newInput(LANG.cc_rapd_s, {title:LANG.cc_rapd_l, convert:UC.toFloat, modes:CAM, units:true}),
camTolerance: UC.newInput(LANG.ou_toll_s, {title:LANG.ou_toll_l, convert:UC.toFloat, bound:UC.bound(0.001,1.0), modes:CAM, units:true}),
laserLayout: UC.newGroup(LANG.lo_menu, null, {modes:LASER, group:"lz-lo"}), laserLayout: UC.newGroup(LANG.lo_menu, null, {modes:LASER, group:"lz-lo"}),
outputTileSpacing: UC.newInput(LANG.ou_spac_s, {title:LANG.ou_spac_l, convert:UC.toInt, modes:LASER}), outputTileSpacing: UC.newInput(LANG.ou_spac_s, {title:LANG.ou_spac_l, convert:UC.toInt, modes:LASER}),
@ -1900,7 +1904,8 @@
widget.move(delta.x, delta.y, 0); widget.move(delta.x, delta.y, 0);
API.event.emit('widget.move', {widget, delta}); API.event.emit('widget.move', {widget, delta});
}); });
platform.update_stock(); // platform.update_stock();
API.event.emit('selection.drag', delta);
} else { } else {
return API.selection.meshes().length > 0; return API.selection.meshes().length > 0;
} }

View file

@ -50,8 +50,7 @@
viewMode = VIEWS.ARRANGE, viewMode = VIEWS.ARRANGE,
layoutOnAdd = true, layoutOnAdd = true,
local = SETUP.local, local = SETUP.local,
camStock = null, topZD = 0,
camTopZ = 0,
topZ = 0, topZ = 0,
busy = 0, busy = 0,
showFavorites = SDB.getItem('dev-favorites') === 'true', showFavorites = SDB.getItem('dev-favorites') === 'true',
@ -98,7 +97,7 @@
compute_max_z: platformComputeMaxZ, compute_max_z: platformComputeMaxZ,
update_origin: platformUpdateOrigin, update_origin: platformUpdateOrigin,
update_bounds: platformUpdateBounds, update_bounds: platformUpdateBounds,
update_stock: platformUpdateStock, // update_stock: platformUpdateStock,
update_size: platformUpdateSize, update_size: platformUpdateSize,
update_top_z: platformUpdateTopZ, update_top_z: platformUpdateTopZ,
update_selected: platformUpdateSelected, update_selected: platformUpdateSelected,
@ -108,7 +107,8 @@
group_done: platformGroupDone, group_done: platformGroupDone,
set_font: SPACE.platform.setFont, set_font: SPACE.platform.setFont,
set_axes: SPACE.platform.setAxes, set_axes: SPACE.platform.setAxes,
set_volume: SPACE.platform.setVolume set_volume: SPACE.platform.setVolume,
top_z: () => { return topZ }
}; };
const color = { const color = {
@ -296,7 +296,8 @@
update_slider: updateSlider, update_slider: updateSlider,
update_fields: updateFields, update_fields: updateFields,
wireframe: setWireframe, wireframe: setWireframe,
snapshot: null snapshot: null,
unit_scale: unitScale
}, },
widgets: { widgets: {
new: newWidget, new: newWidget,
@ -437,12 +438,17 @@
} }
function sendOnEvent(name, data) { function sendOnEvent(name, data) {
if (name && onEvent[name]) onEvent[name].forEach(function(fn) { if (name && onEvent[name]) {
fn(data); onEvent[name].forEach(function(fn) {
fn(data, name);
}); });
} }
}
function addOnEvent(name, handler) { function addOnEvent(name, handler) {
if (Array.isArray(name)) {
return name.forEach(n => addOnEvent(n, handler));
}
if (name && typeof(name) === 'string' && typeof(handler) === 'function') { if (name && typeof(name) === 'string' && typeof(handler) === 'function') {
onEvent[name] = onEvent[name] || []; onEvent[name] = onEvent[name] || [];
onEvent[name].push(handler); onEvent[name].push(handler);
@ -786,20 +792,6 @@
hideSlider(true); hideSlider(true);
// kick off slicing it hasn't been done already
for (let i=0; i < WIDGETS.length; i++) {
if (!WIDGETS[i].slices || WIDGETS[i].isModified()) {
prepareSlices(function() {
if (!WIDGETS[i].slices || WIDGETS[i].isModified()) {
alert2("nothing to print");
} else {
preparePreview(callback);
}
});
return;
}
}
let isCam = MODE === MODES.CAM, pMode = getMode(); let isCam = MODE === MODES.CAM, pMode = getMode();
if (feature.preview) { if (feature.preview) {
@ -901,13 +893,15 @@
function setOpacity(value) { function setOpacity(value) {
forAllWidgets(function (w) { w.setOpacity(value) }); forAllWidgets(function (w) { w.setOpacity(value) });
// UI.modelOpacity.value = value * 100;
SPACE.update(); SPACE.update();
} }
function moveSelection(x, y, z, abs) { function moveSelection(x, y, z, abs) {
forSelectedGroups(function (w) { w.move(x, y, z, abs) }); forSelectedGroups(function (w) {
platform.update_stock(); w.move(x, y, z, abs);
});
API.event.emit('selection.move', {x, y, z, abs});
// platform.update_stock();
SPACE.update(); SPACE.update();
} }
@ -916,13 +910,14 @@
forSelectedGroups(function (w) { forSelectedGroups(function (w) {
w.scale(...args); w.scale(...args);
}); });
platform.compute_max_z();
API.event.emit('selection.scale', [...arguments]);
// skip update if last argument is strictly 'false' // skip update if last argument is strictly 'false'
if ([...arguments].pop() === false) { if ([...arguments].pop() === false) {
return; return;
} }
updateSelectedInfo(); updateSelectedInfo();
platform.compute_max_z(); // platform.update_stock(true);
platform.update_stock(true);
SPACE.update(); SPACE.update();
} }
@ -930,9 +925,10 @@
forSelectedGroups(function (w) { forSelectedGroups(function (w) {
w.rotate(x, y, z); w.rotate(x, y, z);
}); });
updateSelectedInfo();
platform.compute_max_z(); platform.compute_max_z();
platform.update_stock(true); API.event.emit('selection.rotate', {x, y, z});
updateSelectedInfo();
// platform.update_stock(true);
SPACE.update(); SPACE.update();
} }
@ -942,9 +938,14 @@
function platformUpdateOrigin() { function platformUpdateOrigin() {
platform.update_bounds(); platform.update_bounds();
// return;
let dev = settings.device; let dev = settings.device;
let proc = settings.process; let proc = settings.process;
let ruler = settings.controller.showRulers; let ruler = settings.controller.showRulers;
let stock = settings.stock;
let stockCenter = stock.center || {};
let hasStock = stock.x && stock.y && stock.z;
let center = MODE === MODES.FDM ? dev.originCenter : let center = MODE === MODES.FDM ? dev.originCenter :
MODE === MODES.SLA ? false : MODE === MODES.SLA ? false :
MODE === MODES.CAM ? proc.outputOriginCenter : MODE === MODES.CAM ? proc.outputOriginCenter :
@ -953,15 +954,15 @@
let y = 0; let y = 0;
let z = 0; let z = 0;
if (MODE === MODES.CAM && proc.camOriginTop) { if (MODE === MODES.CAM && proc.camOriginTop) {
z = camTopZ + 0.01; z = (topZ + topZD) + 0.01;
if (!camStock) { // if (!hasStock) {
z += proc.camZTopOffset * unitScale(); // z += proc.camZTopOffset * unitScale();
} // }
} }
if (!center) { if (!center) {
if (camStock) { if (hasStock) {
x = (-camStock.scale.x / 2) + camStock.position.x; x = (-stock.x / 2) + stockCenter.x;
y = (camStock.scale.y / 2) - camStock.position.y; y = (stock.y / 2) - stockCenter.y;
} else { } else {
if (MODE === MODES.LASER && proc.outputOriginBounds) { if (MODE === MODES.LASER && proc.outputOriginBounds) {
let b = settings.bounds; let b = settings.bounds;
@ -972,9 +973,9 @@
y = dev.bedDepth / 2; y = dev.bedDepth / 2;
} }
} }
} else if (camStock) { } else if (hasStock) {
x = camStock.position.x; x = stockCenter.x;
y = -camStock.position.y; y = -stockCenter.y;
} }
settings.origin = {x, y, z}; settings.origin = {x, y, z};
SPACE.platform.setRulers(ruler, ruler, center); SPACE.platform.setRulers(ruler, ruler, center);
@ -985,10 +986,14 @@
} }
} }
function platformUpdateTopZ() { function platformUpdateTopZ(zdelta) {
topZD = zdelta !== undefined ? zdelta : topZD;
let stock = settings.stock;
let hasStock = stock.x && stock.y && stock.z;
let alignTopOk = WIDGETS.length > 1 && settings.controller.alignTop; let alignTopOk = WIDGETS.length > 1 && settings.controller.alignTop;
let camz = (MODE === MODES.CAM) && (settings.stock.z || alignTopOk); let camz = (MODE === MODES.CAM) && (hasStock || alignTopOk);
let ztop = camz ? camTopZ - settings.process.camZTopOffset * unitScale() : 0; let czto = hasStock ? settings.process.camZTopOffset * unitScale() : 0;
let ztop = camz ? (topZ + topZD) - czto : 0;
forAllWidgets(function(widget) { forAllWidgets(function(widget) {
widget.setTopZ(ztop); widget.setTopZ(ztop);
}); });
@ -1040,6 +1045,7 @@
wb.max.y += wp.y; wb.max.y += wp.y;
bounds.union(wb); bounds.union(wb);
}); });
// console.log(JSON.stringify(bounds))
return settings.bounds = bounds; return settings.bounds = bounds;
} }
@ -1203,7 +1209,9 @@
selectedMeshes.remove(widget.mesh); selectedMeshes.remove(widget.mesh);
updateSliderMax(); updateSliderMax();
platform.compute_max_z(); platform.compute_max_z();
if (MODE !== MODES.FDM) platform.layout(); if (MODE !== MODES.FDM) {
platform.layout();
}
SPACE.update(); SPACE.update();
platformUpdateSelected(); platformUpdateSelected();
if (layoutOnAdd) platform.layout(); if (layoutOnAdd) platform.layout();
@ -1218,8 +1226,7 @@
let auto = UI.autoLayout.checked, let auto = UI.autoLayout.checked,
proc = settings.process, proc = settings.process,
oldmode = viewMode, oldmode = viewMode,
layout = (viewMode === VIEWS.ARRANGE && auto), layout = (viewMode === VIEWS.ARRANGE && auto);
topZ = MODE === MODES.CAM ? camTopZ - proc.camZTopOffset * unitScale() : 0;
switch (MODE) { switch (MODE) {
case MODES.SLA: case MODES.SLA:
@ -1239,11 +1246,13 @@
// only auto-layout when in arrange mode // only auto-layout when in arrange mode
if (oldmode !== VIEWS.ARRANGE) { if (oldmode !== VIEWS.ARRANGE) {
API.event.emit('platform.layout');
return SPACE.update(); return SPACE.update();
} }
// do not layout when switching back from slice view // do not layout when switching back from slice view
if (!auto || (!space && !layout)) { if (!auto || (!space && !layout)) {
API.event.emit('platform.layout');
return SPACE.update(); return SPACE.update();
} }
@ -1277,92 +1286,9 @@
// m.material.visible = true; // m.material.visible = true;
} }
if (MODE === MODES.CAM) {
platform.update_stock(true);
}
platform.update_origin(); platform.update_origin();
SPACE.update(); API.event.emit('platform.layout');
}
function updateStockVisibility() {
if (camStock) {
camStock.material.visible = settings.mode === 'CAM';// && viewMode === VIEWS.ARRANGE;
}
}
function platformUpdateStock(refresh) {
let sd = settings.process;
let offset = UI.camStockOffset.checked;
let stockSet = offset || (sd.camStockX && sd.camStockY && sd.camStockZ > 0);
let scale = unitScale();
settings.stock = { };
camTopZ = topZ;
// create/inject cam stock if stock size other than default
if (MODE === MODES.CAM && stockSet && WIDGETS.length) {
// UI.stock.style.display = offset ? 'inline-block' : 'none';
let csx = sd.camStockX * scale;
let csy = sd.camStockY * scale;
let csz = sd.camStockZ * scale;
let csox = 0;
let csoy = 0;
if (offset) {
let min = { x: Infinity, y: Infinity, z: 0 };
let max = { x: -Infinity, y: -Infinity, z: -Infinity };
forAllWidgets(function(widget) {
let wbnd = widget.getBoundingBox(refresh);
let wpos = widget.track.pos;
min = {
x: Math.min(min.x, wpos.x + wbnd.min.x),
y: Math.min(min.y, wpos.y + wbnd.min.y),
z: 0
};
max = {
x: Math.max(max.x, wpos.x + wbnd.max.x),
y: Math.max(max.y, wpos.y + wbnd.max.y),
z: Math.max(max.z, wbnd.max.z)
};
});
csx += max.x - min.x;
csy += max.y - min.y;
csz += max.z - min.z;
csox = min.x + ((max.x - min.x) / 2);
csoy = min.y + ((max.y - min.y) / 2);
}
if (!camStock) {
let geo = new THREE.BoxGeometry(1, 1, 1);
let mat = new THREE.MeshBasicMaterial({
color: 0x777777,
opacity: 0.2,
transparent: true,
side:THREE.DoubleSide
});
let cube = new THREE.Mesh(geo, mat);
SPACE.platform.add(cube);
camStock = cube;
cube.renderOrder = 2;
}
settings.stock = {
x: csx,
y: csy,
z: csz
};
camStock.scale.x = csx;
camStock.scale.y = csy;
camStock.scale.z = csz;
camStock.position.x = csox;
camStock.position.y = csoy;
camStock.position.z = csz / 2;
updateStockVisibility();
camTopZ = csz;
} else if (camStock) {
// UI.stock.style.display = 'none';
SPACE.platform.remove(camStock);
camStock = null;
camTopZ = topZ;
}
platform.update_top_z();
platform.update_origin();
SPACE.update(); SPACE.update();
} }
@ -1513,7 +1439,7 @@
updateSettingsFromFields(device.extruders[device.internal]); updateSettingsFromFields(device.extruders[device.internal]);
} }
API.conf.save(); API.conf.save();
platform.update_stock(); // platform.update_stock();
$('mode-device').innerText = settings.device.deviceName; $('mode-device').innerText = settings.device.deviceName;
$('mode-profile').innerText = settings.process.processName; $('mode-profile').innerText = settings.process.processName;
} }
@ -1694,7 +1620,7 @@
updateFields(); updateFields();
platform.update_size(); platform.update_size();
platform.update_stock(); // platform.update_stock();
let fz = SPACE.scene.freeze(true); let fz = SPACE.scene.freeze(true);
SPACE.view.reset(); SPACE.view.reset();
@ -1969,7 +1895,7 @@
viewMode = mode; viewMode = mode;
platform.deselect(); platform.deselect();
updateSelectedInfo(); updateSelectedInfo();
updateStockVisibility(); // updateStockVisibility();
switch (mode) { switch (mode) {
case VIEWS.ARRANGE: case VIEWS.ARRANGE:
UI.back.style.display = ''; UI.back.style.display = '';
@ -1999,7 +1925,7 @@
DBUG.log("invalid view mode: "+mode); DBUG.log("invalid view mode: "+mode);
return; return;
} }
API.event.emit('view.mode', mode); API.event.emit('view.set', mode);
DOC.activeElement.blur(); DOC.activeElement.blur();
} }
@ -2045,7 +1971,7 @@
API.event.emit('device.set', currentDeviceName()); API.event.emit('device.set', currentDeviceName());
} }
// really belongs in CAM driver (lots of work / abstraction needed) // really belongs in CAM driver (lots of work / abstraction needed)
updateStockVisibility(); // updateStockVisibility();
// updates right-hand menu by enabling/disabling fields // updates right-hand menu by enabling/disabling fields
setViewMode(VIEWS.ARRANGE); setViewMode(VIEWS.ARRANGE);
UC.setMode(MODE); UC.setMode(MODE);

View file

@ -618,12 +618,6 @@
} }
}; };
PRO.getCamBounds = function(settings) {
let bounds = this.getBoundingBox().clone();
bounds.max.z += settings.process.camZTopOffset;
return bounds;
};
/** /**
* render to provided stack * render to provided stack
*/ */

View file

@ -3,7 +3,7 @@
let terms = { let terms = {
COPYRIGHT: "Copyright (C) Stewart Allen <sa@grid.space> - All Rights Reserved", COPYRIGHT: "Copyright (C) Stewart Allen <sa@grid.space> - All Rights Reserved",
LICENSE: "See the license.md file included with the source distribution", LICENSE: "See the license.md file included with the source distribution",
VERSION: "2.3.D8" VERSION: "2.3.D9"
}; };
if (typeof(module) === 'object') { if (typeof(module) === 'object') {

View file

@ -9,16 +9,35 @@
CAM = KIRI.driver.CAM, CAM = KIRI.driver.CAM,
PRO = CAM.process, PRO = CAM.process,
newPolygon = BASE.newPolygon, newPolygon = BASE.newPolygon,
newPoint = BASE.newPoint; newPoint = BASE.newPoint,
isArrange,
isCamMode,
camStock,
API, SPACE, MODES, VIEWS, UI, UC;
CAM.init = function(kiri, api) { CAM.init = function(kiri, api) {
// console.log({kiri,api})
SPACE = api.const.SPACE;
MODES = api.const.MODES;
VIEWS = api.const.VIEWS;
UI = api.ui;
UC = api.uc;
API = api;
api.event.on("mode.set", (mode) => { api.event.on("mode.set", (mode) => {
const isCAM = mode === 'CAM'; isCamMode = mode === 'CAM';
$('set-tools').style.display = isCAM ? '' : 'none'; $('set-tools').style.display = isCamMode ? '' : 'none';
kiri.space.platform.setColor(isCAM ? 0xeeeeee : 0xcccccc); kiri.space.platform.setColor(isCamMode ? 0xeeeeee : 0xcccccc);
updateStock(undefined, 'internal');
}); });
api.event.on("view.set", (mode) => {
isArrange = (mode === VIEWS.ARRANGE);
});
api.event.on("settings.saved", (settings) => { api.event.on("settings.saved", (settings) => {
const proc = settings.process; const proc = settings.process;
// show/hide dots in enabled process pop buttons
api.ui.camTabs.marker.style.display = proc.camTabsOn ? 'flex' : 'none'; api.ui.camTabs.marker.style.display = proc.camTabsOn ? 'flex' : 'none';
api.ui.camRough.marker.style.display = proc.camRoughOn ? 'flex' : 'none'; api.ui.camRough.marker.style.display = proc.camRoughOn ? 'flex' : 'none';
api.ui.camDrill.marker.style.display = api.ui.camDrill.marker.style.display =
@ -26,32 +45,142 @@
api.ui.camOutline.marker.style.display = proc.camOutlineOn ? 'flex' : 'none'; api.ui.camOutline.marker.style.display = proc.camOutlineOn ? 'flex' : 'none';
api.ui.camContour.marker.style.display = api.ui.camContour.marker.style.display =
proc.camContourXOn || proc.camContourYOn ? 'flex' : 'none'; proc.camContourXOn || proc.camContourYOn ? 'flex' : 'none';
updateStock(settings, 'settings.saved.internal');
}); });
function updateStock() { api.event.on([
const STACKS = api.const.STACKS; "init-done",
const SPACE = api.const.SPACE; // update stock when modes change?
const stock = api.conf.get().stock; "slice.end",
"preview.end",
// update stock when preferences change
// "boolean.click",
"boolean.update",
// update stock when objects move
"platform.layout",
"selection.drag",
"selection.move",
// force bounds update, too
"selection.scale",
"selection.rotate"
], updateStock);
};
function updateStock(args, event) {
const SPACE = API.const.SPACE;
if (!isCamMode) {
if (camStock) {
SPACE.platform.remove(camStock);
camStock = null;
}
return;
}
const STACKS = API.const.STACKS;
const refresh = (event === "selection.scale" || event === 'selection.rotate');
let settings = API.conf.get();
let widgets = API.widgets.all();
let proc = settings.process;
let enabled = UI.camStockOn.checked;
let offset = UI.camStockOffset.checked;
let stockSet = offset || (proc.camStockX && proc.camStockY && proc.camStockZ > 0);
let scale = API.view.unit_scale();
let topZ = API.platform.top_z();
let delta = 0;
let csox = 0;
let csoy = 0;
let stock = settings.stock = { };
// create/inject cam stock if stock size other than default
if (enabled && stockSet && widgets.length) {
// UI.stock.style.display = offset ? 'inline-block' : 'none';
let csx = proc.camStockX * scale;
let csy = proc.camStockY * scale;
let csz = proc.camStockZ * scale;
if (offset) {
let min = { x: Infinity, y: Infinity, z: 0 };
let max = { x: -Infinity, y: -Infinity, z: -Infinity };
widgets.forEach(function(widget) {
let wbnd = widget.getBoundingBox(refresh);
let wpos = widget.track.pos;
min = {
x: Math.min(min.x, wpos.x + wbnd.min.x),
y: Math.min(min.y, wpos.y + wbnd.min.y),
z: 0
};
max = {
x: Math.max(max.x, wpos.x + wbnd.max.x),
y: Math.max(max.y, wpos.y + wbnd.max.y),
z: Math.max(max.z, wbnd.max.z)
};
});
csx += max.x - min.x;
csy += max.y - min.y;
csz += max.z - min.z;
csox = min.x + ((max.x - min.x) / 2);
csoy = min.y + ((max.y - min.y) / 2);
}
if (!camStock) {
let geo = new THREE.BoxGeometry(1, 1, 1);
let mat = new THREE.MeshBasicMaterial({
color: 0x777777,
opacity: 0.2,
transparent: true,
side:THREE.DoubleSide
});
camStock = new THREE.Mesh(geo, mat);
camStock.renderOrder = 2;
SPACE.platform.add(camStock);
}
stock = settings.stock = {
x: csx,
y: csy,
z: csz,
center: {
x: csox,
y: csoy,
z: csz / 2
}
};
camStock.scale.x = csx + 0.005;
camStock.scale.y = csy + 0.005;
camStock.scale.z = csz + 0.005;
camStock.position.x = csox;
camStock.position.y = csoy;
camStock.position.z = csz / 2;
delta = csz - topZ;
} else if (camStock) {
SPACE.platform.remove(camStock);
camStock = null;
delta = 0;
}
if (isArrange) {
STACKS.clear();
}
const {x, y, z} = stock; const {x, y, z} = stock;
if (x && y && z) { if (x && y && z) {
const render = new KIRI.Render().setLayer('bounds', { face: 0xaaaaaa, line: 0xaaaaaa }, true); const render = new KIRI.Render().setLayer('bounds', { face: 0xaaaaaa, line: 0xaaaaaa });
const stack = STACKS.create('bounds', SPACE.platform.world); const stack = STACKS.create('bounds', SPACE.platform.world);
stack.add(render.addPolys([ stack.add(render.addPolys([
newPolygon().centerRectangle({x:0, y:0, z:0}, x, y), newPolygon().centerRectangle({x:csox, y:csoy, z:0}, x, y),
newPolygon().centerRectangle({x:0, y:0, z}, x, y) newPolygon().centerRectangle({x:csox, y:csoy, z}, x, y)
], { thin: true } )); ], { thin: true } ));
const hx = x/2, hy = y/2; const hx = x/2, hy = y/2;
stack.add(render.addLines([ stack.add(render.addLines([
newPoint( hx, -hy, 0), newPoint( hx, -hy, stock.z), newPoint(csox + hx, csoy - hy, 0), newPoint(csox + hx, csoy - hy, stock.z),
newPoint( hx, hy, 0), newPoint( hx, hy, stock.z), newPoint(csox + hx, csoy + hy, 0), newPoint(csox + hx, csoy + hy, stock.z),
newPoint(-hx, -hy, 0), newPoint(-hx, -hy, stock.z), newPoint(csox - hx, csoy - hy, 0), newPoint(csox - hx, csoy - hy, stock.z),
newPoint(-hx, hy, 0), newPoint(-hx, hy, stock.z), newPoint(csox - hx, csoy + hy, 0), newPoint(csox - hx, csoy + hy, stock.z),
], { thin: true })); ], { thin: true }));
} }
API.platform.update_top_z(delta);
API.platform.update_origin();
SPACE.update();
} }
api.event.on("slice.end", updateStock);
api.event.on("preview.end", updateStock);
};
})(); })();

View file

@ -55,14 +55,14 @@
outer = settings.bounds, outer = settings.bounds,
outerz = outer.max.z, outerz = outer.max.z,
slices = widget.slices, slices = widget.slices,
bounds = widget.getCamBounds(settings), hasStock = stock.x && stock.y && stock.z && process.camStockOn,
boundsz = bounds.max.z,
hasStock = process.camStockOffset || (process.camStockZ && process.camStockX && process.camStockY),
startCenter = process.outputOriginCenter, startCenter = process.outputOriginCenter,
alignTop = settings.controller.alignTop, alignTop = settings.controller.alignTop,
zclear = (process.camZClearance || 1), zclear = (process.camZClearance || 1),
zmax_outer = hasStock ? stock.z + zclear : outerz + zclear, zmax_outer = hasStock ? stock.z + zclear : outerz + zclear,
ztOff = process.camZTopOffset, ztOff = hasStock ? process.camZTopOffset : 0,
bounds = widget.getBoundingBox(),
boundsz = bounds.max.z + ztOff,
zadd = hasStock ? stock.z - boundsz : alignTop ? outerz - boundsz : 0, zadd = hasStock ? stock.z - boundsz : alignTop ? outerz - boundsz : 0,
zmax = outerz + zclear, zmax = outerz + zclear,
wmpos = widget.mesh.position, wmpos = widget.mesh.position,
@ -247,8 +247,8 @@
deltaXY = 0; deltaXY = 0;
} }
} //else (TODO verify no else here b/c above could change isMove) } //else (TODO verify no else here b/c above could change isMove)
// move over things // move over things ... try checking path clearance tests for *every* move
if ((deltaXY > toolDiam || (deltaZ > toolDiam && deltaXY > tolerance)) && (isMove || absDeltaZ >= tolerance)) { if ((deltaXY > toolDiam || (deltaZ > tolerance && deltaXY > tolerance)) && (isMove || absDeltaZ >= tolerance)) {
let maxz = getZClearPath( let maxz = getZClearPath(
terrain, terrain,
lastPoint.x,// - wmx, lastPoint.x,// - wmx,

View file

@ -24,13 +24,15 @@
CAM.slice = function(settings, widget, onupdate, ondone) { CAM.slice = function(settings, widget, onupdate, ondone) {
let conf = settings, let conf = settings,
proc = conf.process, proc = conf.process,
stock = settings.stock || {},
hasStock = stock.x && stock.y && stock.z && proc.camStockOn,
sliceAll = widget.slices = [], sliceAll = widget.slices = [],
unitsName = settings.controller.units, unitsName = settings.controller.units,
roughTool = new CAM.Tool(conf, proc.camRoughTool), roughTool = new CAM.Tool(conf, proc.camRoughTool),
roughToolDiam = roughTool.fluteDiameter(), roughToolDiam = roughTool.fluteDiameter(),
drillTool = new CAM.Tool(conf, proc.camDrillTool), drillTool = new CAM.Tool(conf, proc.camDrillTool),
drillToolDiam = drillTool.fluteDiameter(), drillToolDiam = drillTool.fluteDiameter(),
procFacing = proc.camRoughOn && proc.camZTopOffset, procFacing = proc.camRoughOn && proc.camZTopOffset && hasStock,
procRough = proc.camRoughOn && proc.camRoughDown, procRough = proc.camRoughOn && proc.camRoughDown,
procOutlineIn = proc.camOutlineIn, procOutlineIn = proc.camOutlineIn,
procOutlineOn = proc.camOutlineOn, procOutlineOn = proc.camOutlineOn,
@ -54,13 +56,12 @@
zMin = Math.max(bounds.min.z, zBottom), zMin = Math.max(bounds.min.z, zBottom),
zMax = bounds.max.z, zMax = bounds.max.z,
zThru = zBottom === 0 ? (proc.camZThru || 0) : 0, zThru = zBottom === 0 ? (proc.camZThru || 0) : 0,
ztOff = proc.camZTopOffset, ztOff = hasStock ? proc.camZTopOffset : 0,
camRoughStock = proc.camRoughStock, camRoughStock = proc.camRoughStock,
camRoughDown = proc.camRoughDown, camRoughDown = proc.camRoughDown,
minStepDown = Math.min(1, roughDown, outlineDown), minStepDown = Math.min(1, roughDown, outlineDown),
maxToolDiam = 0, maxToolDiam = 0,
thruHoles, thruHoles;
stock = settings.stock || {};
if (stock.x && stock.y && stock.z) { if (stock.x && stock.y && stock.z) {
if (stock.x + 0.00001 < bounds.max.x - bounds.min.x) { if (stock.x + 0.00001 < bounds.max.x - bounds.min.x) {

View file

@ -84,12 +84,12 @@
freeze = false, freeze = false,
isRound = false, isRound = false,
platformMaterial = new THREE.MeshPhongMaterial({ platformMaterial = new THREE.MeshPhongMaterial({
color: 0xcccccc, color: 0xeeeeee,
specular: 0xcccccc, specular: 0xeeeeee,
shininess: 5, shininess: 0,
transparent: true, transparent: true,
opacity: 0.6, opacity: 0.6,
// side: THREE.DoubleSide side: THREE.DoubleSide
}), }),
hiddenKey, hiddenKey,
vizChange, vizChange,
@ -496,15 +496,16 @@
)); ));
pi4.position.x = 0.25; pi4.position.x = 0.25;
pi4.position.y = -0.25; pi4.position.y = -0.25;
group.add(new THREE.Mesh( let aa, bb, cc;
group.add(aa = new THREE.Mesh(
new THREE.RingGeometry(5, 5.5, 50), new THREE.RingGeometry(5, 5.5, 50),
rmat rmat
)); ));
group.add(new THREE.Mesh( group.add(bb = new THREE.Mesh(
new THREE.PlaneGeometry(0.5, 10), new THREE.PlaneGeometry(0.5, 10),
rmat rmat
)); ));
group.add(new THREE.Mesh( group.add(cc = new THREE.Mesh(
new THREE.PlaneGeometry(10, 0.5), new THREE.PlaneGeometry(10, 0.5),
rmat rmat
)); ));
@ -512,6 +513,9 @@
group.position.x = x; group.position.x = x;
group.position.y = z; group.position.y = z;
group.position.z = y; group.position.z = y;
[bb,cc].forEach(m => {
m.renderOrder = 3;
});
Space.scene.add(group); Space.scene.add(group);
Space.update(); Space.update();
} }

View file

@ -410,6 +410,8 @@ kiri.lang['en-us'] = {
cs_hght_l: "height (z) in workspace units\n0 defaults to part size", cs_hght_l: "height (z) in workspace units\n0 defaults to part size",
cs_offs_s: "offset", cs_offs_s: "offset",
cs_offs_l: "use width, depth, height\nas offsets from max\npart size on platform", cs_offs_l: "use width, depth, height\nas offsets from max\npart size on platform",
cs_offe_s: "enable",
cs_offe_l: "enable milling stock",
// ORIGIN (CAM & LASER) // ORIGIN (CAM & LASER)
or_bnds_s: "origin bounds", or_bnds_s: "origin bounds",