fix stock and origin settings when switching states

This commit is contained in:
Stewart Allen 2020-03-01 21:24:14 -05:00
commit 450d42a4cb
2 changed files with 36 additions and 21 deletions

View file

@ -928,23 +928,23 @@ var gs_kiri_cam = exports;
settings = print.settings, settings = print.settings,
device = settings.device, device = settings.device,
process = settings.process, process = settings.process,
stock = settings.stock,
widgetIndex = index || 0, widgetIndex = index || 0,
widgetArray = print.widgets, widgetArray = print.widgets,
widgetCount = widgetArray.length, widgetCount = widgetArray.length,
widget = widgetArray[widgetIndex]; widget = widgetArray[widgetIndex];
if (widgetIndex >= widgetCount || !widget) return; if (widgetIndex >= widgetCount || !widget) return;
var slices = widget.slices, var slices = widget.slices,
bounds = widget.getCamBounds(settings), bounds = widget.getCamBounds(settings),
hasStock = process.camStockZ && process.camStockX && process.camStockY, hasStock = process.camStockZ && process.camStockX && process.camStockY,
startCenter = process.outputOriginCenter, startCenter = process.outputOriginCenter,
zclear = process.camZClearance || 1, zclear = process.camZClearance || 1,
zadd = hasStock ? process.camStockZ - bounds.max.z : 0, zadd = hasStock ? stock.z - bounds.max.z : 0,
zmax = hasStock ? process.camStockZ + zclear : bounds.max.z + zclear, zmax = hasStock ? stock.z + zclear : bounds.max.z + zclear,
originx = startCenter ? 0 : hasStock ? -process.camStockX / 2 : bounds.min.x, originx = startCenter ? 0 : hasStock ? -stock.x / 2 : bounds.min.x,
originy = startCenter ? 0 : hasStock ? -process.camStockY / 2 : bounds.min.y, originy = startCenter ? 0 : hasStock ? -stock.y / 2 : bounds.min.y,
origin = hasStock ? newPoint(originx, originy, process.camStockZ) : newPoint(originx, originy, bounds.max.z + zclear), origin = hasStock ? newPoint(originx, originy, stock.z) : newPoint(originx, originy, bounds.max.z + zclear),
output = print.output, output = print.output,
modes = CPRO, modes = CPRO,
depthFirst = process.camDepthFirst, depthFirst = process.camDepthFirst,
@ -1413,7 +1413,7 @@ var gs_kiri_cam = exports;
point, point,
points = 0, points = 0,
hasStock = spro.camStockZ && spro.camStockX && spro.camStockY, hasStock = spro.camStockZ && spro.camStockX && spro.camStockY,
zmax = hasStock ? spro.camStockZ : bounds.max.z, zmax = hasStock ? settings.stock.z : bounds.max.z,
runbox = { runbox = {
max: { x:-Infinity, y:-Infinity, z:-Infinity}, max: { x:-Infinity, y:-Infinity, z:-Infinity},
min: { x:Infinity, y:Infinity, z:Infinity} min: { x:Infinity, y:Infinity, z:Infinity}

View file

@ -213,6 +213,7 @@ self.kiri.license = exports.LICENSE;
{ name: "triangle" } { name: "triangle" }
], ],
// CAM only // CAM only
stock: {},
tools:[ tools:[
{ {
id: 1000, id: 1000,
@ -539,6 +540,7 @@ self.kiri.license = exports.LICENSE;
mouseMoved = false, mouseMoved = false,
camStock = null, camStock = null,
camTopZ = 0, camTopZ = 0,
topZ = 0,
showFavorites = SDB['dev-favorites'] === 'true'; showFavorites = SDB['dev-favorites'] === 'true';
// seed defaults. will get culled on save // seed defaults. will get culled on save
@ -934,10 +936,16 @@ self.kiri.license = exports.LICENSE;
clearPrint(); clearPrint();
setOpacity(0); setOpacity(0);
currentPrint = kiri.newPrint(settings, []); currentPrint = kiri.newPrint(settings, []);
let offset = settings.process.outputOriginCenter ? null : { let center = settings.process.outputOriginCenter;
let offset = center ? {x:0, y:0, z:camTopZ} : {
x: -settings.device.bedWidth / 2, x: -settings.device.bedWidth / 2,
y: -settings.device.bedDepth / 2, y: -settings.device.bedDepth / 2,
}; };
if (MODE === MODES.CAM && settings.stock.x && !center) {
offset.x = -settings.stock.x / 2;
offset.y = -settings.stock.y / 2;
offset.z = settings.stock.z;
}
switch (type) { switch (type) {
case 'svg': case 'svg':
currentPrint.parseSVG(code, offset); currentPrint.parseSVG(code, offset);
@ -1605,11 +1613,11 @@ self.kiri.license = exports.LICENSE;
} }
function platformComputeMaxZ() { function platformComputeMaxZ() {
var maxZ = 0; topZ = 0;
forAllWidgets(function(widget) { forAllWidgets(function(widget) {
maxZ = Math.max(maxZ, widget.mesh.getBoundingBox().max.z); topZ = Math.max(topZ, widget.mesh.getBoundingBox().max.z);
}); });
SPACE.platform.setMaxZ(maxZ); SPACE.platform.setMaxZ(topZ);
} }
function platformAdd(widget, shift, nolayout) { function platformAdd(widget, shift, nolayout) {
@ -1695,7 +1703,7 @@ self.kiri.license = exports.LICENSE;
proc = settings.process, proc = settings.process,
modified = false, modified = false,
oldmode = viewMode, oldmode = viewMode,
topZ = MODE === MODES.CAM ? camTopZ : 0; topZ = MODE === MODES.CAM ? camTopZ - proc.camZTopOffset : 0;
switch (MODE) { switch (MODE) {
case MODES.CAM: case MODES.CAM:
@ -1752,7 +1760,7 @@ self.kiri.license = exports.LICENSE;
m.fit.x += m.w / 2 + p.pad; m.fit.x += m.w / 2 + p.pad;
m.fit.y += m.h / 2 + p.pad; m.fit.y += m.h / 2 + p.pad;
m.widget.move(p.max.w / 2 - m.fit.x, p.max.h / 2 - m.fit.y, 0, true); m.widget.move(p.max.w / 2 - m.fit.x, p.max.h / 2 - m.fit.y, 0, true);
m.widget.setTopZ(topZ); // m.widget.setTopZ(topZ);
m.material.visible = true; m.material.visible = true;
} }
@ -1895,8 +1903,9 @@ self.kiri.license = exports.LICENSE;
return settings; return settings;
} }
function camUpdateWidgetZ() { function updateWidgetsTopZ() {
var ztop = MODE === MODES.CAM ? camTopZ : 0; let camz = MODE === MODES.CAM && settings.stock.z;
let ztop = camz ? camTopZ - settings.process.camZTopOffset : 0;
forAllWidgets(function(widget) { forAllWidgets(function(widget) {
widget.setTopZ(ztop); widget.setTopZ(ztop);
}); });
@ -1938,6 +1947,11 @@ self.kiri.license = exports.LICENSE;
$('stock-width').innerText = (csx).toFixed(2); $('stock-width').innerText = (csx).toFixed(2);
$('stock-depth').innerText = (csy).toFixed(2); $('stock-depth').innerText = (csy).toFixed(2);
$('stock-height').innerText = (csz).toFixed(2); $('stock-height').innerText = (csz).toFixed(2);
settings.stock = {
x: csx,
y: csy,
z: csz
};
} }
if (!camStock) { if (!camStock) {
var geo = new THREE.BoxGeometry(1, 1, 1); var geo = new THREE.BoxGeometry(1, 1, 1);
@ -1953,16 +1967,17 @@ self.kiri.license = exports.LICENSE;
camStock.position.y = csoy; camStock.position.y = csoy;
camStock.position.z = csz / 2; camStock.position.z = csz / 2;
camStock.material.visible = settings.mode === 'CAM'; camStock.material.visible = settings.mode === 'CAM';
camTopZ = csz - sd.camZTopOffset; camTopZ = csz;
camUpdateWidgetZ(); updateWidgetsTopZ();
SPACE.update(); SPACE.update();
} else if (camStock) { } else if (camStock) {
settings.stock = {};
UI.stock.style.display = 'none'; UI.stock.style.display = 'none';
SPACE.platform.remove(camStock); SPACE.platform.remove(camStock);
SPACE.update(); SPACE.update();
camStock = null; camStock = null;
camTopZ = 0; camTopZ = topZ;
camUpdateWidgetZ(); updateWidgetsTopZ();
} }
updateOrigin(); updateOrigin();
} }
@ -2078,8 +2093,8 @@ self.kiri.license = exports.LICENSE;
let x = 0; let x = 0;
let y = 0; let y = 0;
let z = 0; let z = 0;
if (proc.camOriginTop) { if (MODE === MODES.CAM && proc.camOriginTop) {
z = camTopZ + proc.camZTopOffset + 0.01; z = camTopZ + 0.01;
} }
if (!proc.outputOriginCenter) { if (!proc.outputOriginCenter) {
if (camStock) { if (camStock) {