change default stock visualization in slice and preview modes

This commit is contained in:
Stewart Allen 2020-11-13 22:09:08 -05:00
commit 9522821232
3 changed files with 52 additions and 16 deletions

View file

@ -1285,6 +1285,12 @@
SPACE.update();
}
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;
@ -1341,7 +1347,7 @@
camStock.position.x = csox;
camStock.position.y = csoy;
camStock.position.z = csz / 2;
camStock.material.visible = settings.mode === 'CAM';
updateStockVisibility();
camTopZ = csz;
} else if (camStock) {
// UI.stock.style.display = 'none';
@ -1957,6 +1963,7 @@
viewMode = mode;
platform.deselect();
updateSelectedInfo();
updateStockVisibility();
switch (mode) {
case VIEWS.ARRANGE:
UI.back.style.display = '';
@ -2032,9 +2039,7 @@
API.event.emit('device.set', currentDeviceName());
}
// really belongs in CAM driver (lots of work / abstraction needed)
if (camStock) {
camStock.material.visible = settings.mode === 'CAM';
}
updateStockVisibility();
// updates right-hand menu by enabling/disabling fields
setViewMode(VIEWS.ARRANGE);
UC.setMode(MODE);

View file

@ -5,17 +5,20 @@
(function() {
let KIRI = self.kiri,
BASE = self.base,
CAM = KIRI.driver.CAM,
PRO = CAM.process;
PRO = CAM.process,
newPolygon = BASE.newPolygon,
newPoint = BASE.newPoint;
CAM.init = function(kiri, api) {
api.event.on("mode.set", (mode) => {
let isCAM = mode === 'CAM';
const isCAM = mode === 'CAM';
$('set-tools').style.display = isCAM ? '' : 'none';
kiri.space.platform.setColor(isCAM ? 0xeeeeee : 0xcccccc);
});
api.event.on("settings.saved", (settings) => {
let proc = settings.process;
const proc = settings.process;
api.ui.camTabs.marker.style.display = proc.camTabsOn ? 'flex' : 'none';
api.ui.camRough.marker.style.display = proc.camRoughOn ? 'flex' : 'none';
api.ui.camDrill.marker.style.display =
@ -24,6 +27,31 @@
api.ui.camContour.marker.style.display =
proc.camContourXOn || proc.camContourYOn ? 'flex' : 'none';
});
function updateStock() {
const STACKS = api.const.STACKS;
const SPACE = api.const.SPACE;
const stock = api.conf.get().stock;
const {x, y, z} = stock;
if (x && y && z) {
const render = new KIRI.Render().setLayer('stock', { face: 0xaaaaaa, line: 0xaaaaaa }, true);
const stack = STACKS.create('stock', SPACE.platform.world);
stack.add(render.addPolys([
newPolygon().centerRectangle({x:0, y:0, z:0}, x, y),
newPolygon().centerRectangle({x:0, y:0, z}, x, y)
], { thin: true } ));
const hx = x/2, hy = y/2;
stack.add(render.addLines([
newPoint( hx, -hy, 0), newPoint( hx, -hy, stock.z),
newPoint( hx, hy, 0), newPoint( hx, hy, stock.z),
newPoint(-hx, -hy, 0), newPoint(-hx, -hy, stock.z),
newPoint(-hx, hy, 0), newPoint(-hx, hy, stock.z),
], { thin: true }));
}
}
api.event.on("slice.end", updateStock);
api.event.on("preview.end", updateStock);
};
})();

View file

@ -59,18 +59,21 @@
camRoughDown = proc.camRoughDown,
minStepDown = Math.min(1, roughDown, outlineDown),
maxToolDiam = 0,
thruHoles;
thruHoles,
stock = settings.stock || {};
if (settings.stock.x + 0.00001 < bounds.max.x - bounds.min.x) {
return ondone('stock X too small for part. disable stock or use offset stock');
}
if (stock.x && stock.y && stock.z) {
if (stock.x + 0.00001 < bounds.max.x - bounds.min.x) {
return ondone('stock X too small for part. disable stock or use offset stock');
}
if (settings.stock.y + 0.00001 < bounds.max.y - bounds.min.y) {
return ondone('stock Y too small for part. disable stock or use offset stock');
}
if (stock.y + 0.00001 < bounds.max.y - bounds.min.y) {
return ondone('stock Y too small for part. disable stock or use offset stock');
}
if (settings.stock.z + 0.00001 < bounds.max.z - bounds.min.z) {
return ondone('stock Z too small for part. disable stock or use offset stock');
if (stock.z + 0.00001 < bounds.max.z - bounds.min.z) {
return ondone('stock Z too small for part. disable stock or use offset stock');
}
}
if (sliceDepth <= 0.05) {