allow recompute of workspace units in op chains. fix bounding box changes in indexed op chains
This commit is contained in:
parent
0c44b82985
commit
b6573a4990
2 changed files with 60 additions and 56 deletions
|
|
@ -30,66 +30,68 @@ const POLY = polygons;
|
||||||
*/
|
*/
|
||||||
CAM.slice = async function(settings, widget, onupdate, ondone) {
|
CAM.slice = async function(settings, widget, onupdate, ondone) {
|
||||||
let proc = settings.process,
|
let proc = settings.process,
|
||||||
stock = settings.stock || {},
|
|
||||||
isIndexed = proc.camStockIndexed,
|
|
||||||
camOps = widget.camops = [],
|
|
||||||
sliceAll = widget.slices = [],
|
sliceAll = widget.slices = [],
|
||||||
bounds = widget.getBoundingBox(),
|
// slices = widget.slices = [],
|
||||||
track = widget.track,
|
camOps = widget.camops = [],
|
||||||
{ camZTop, camZBottom, camZThru } = proc,
|
isIndexed = proc.camStockIndexed;
|
||||||
// widget top z as defined by setTopz()
|
|
||||||
wztop = track.top,
|
let stock, bounds, track,
|
||||||
// distance between top of part and top of stock
|
camZTop, camZBottom, camZThru, wztop, ztOff, zbOff,
|
||||||
ztOff = isIndexed ? 0 : (stock.z - wztop),
|
zBottom, zMin, zMax, zThru, zTop,
|
||||||
// distance between bottom of part and bottom of stock
|
minToolDiam, maxToolDiam, dark, color, tabs, unsafe, units,
|
||||||
zbOff = isIndexed ? 0 : (wztop - track.box.d),
|
axisRotation, axisIndex,
|
||||||
// defined z bottom offset by distance to stock bottom
|
part_size,
|
||||||
// keeps the z bottom relative to the part when z align changes
|
bottom_gap, bottom_part, bottom_stock, bottom_thru, bottom_z, bottom_cut,
|
||||||
zBottom = isIndexed ? camZBottom : camZBottom - zbOff,
|
top_stock, top_part, top_gap, top_z,
|
||||||
// greater of widget bottom and z bottom
|
workarea;
|
||||||
zMin = isIndexed ? bounds.min.z : Math.max(bounds.min.z, zBottom),
|
|
||||||
zMax = bounds.max.z,
|
// allow recomputing later if widget or settings changes
|
||||||
zThru = camZThru,
|
const var_compute = () => {
|
||||||
zTop = zMax + ztOff,
|
stock = settings.stock || {};
|
||||||
minToolDiam = Infinity,
|
bounds = widget.getBoundingBox();
|
||||||
maxToolDiam = -Infinity,
|
track = widget.track;
|
||||||
dark = settings.controller.dark ? true : false,
|
({ camZTop, camZBottom, camZThru } = proc);
|
||||||
color = dark ? 0xbbbbbb : 0,
|
wztop = track.top;
|
||||||
tabs = widget.anno.tab,
|
ztOff = isIndexed ? 0 : (stock.z - wztop);
|
||||||
unsafe = proc.camExpertFast,
|
zbOff = isIndexed ? 0 : (wztop - track.box.d);
|
||||||
units = settings.controller.units === 'in' ? 25.4 : 1,
|
zBottom = isIndexed ? camZBottom : camZBottom - zbOff;
|
||||||
axisRotation,
|
zMin = isIndexed ? bounds.min.z : Math.max(bounds.min.z, zBottom);
|
||||||
axisIndex,
|
zMax = bounds.max.z;
|
||||||
// new work area tracking
|
zThru = camZThru;
|
||||||
part_size = bounds.dim,
|
zTop = zMax + ztOff;
|
||||||
bottom_gap = zbOff,
|
minToolDiam = Infinity;
|
||||||
bottom_part = 0,
|
maxToolDiam = -Infinity;
|
||||||
bottom_stock = -bottom_gap,
|
dark = !!settings.controller.dark;
|
||||||
bottom_thru = zThru,
|
color = dark ? 0xbbbbbb : 0;
|
||||||
|
tabs = widget.anno.tab;
|
||||||
|
unsafe = proc.camExpertFast;
|
||||||
|
units = settings.controller.units === 'in' ? 25.4 : 1;
|
||||||
|
axisRotation = axisIndex = undefined;
|
||||||
|
part_size = bounds.dim;
|
||||||
|
bottom_gap = zbOff;
|
||||||
|
bottom_part = 0;
|
||||||
|
bottom_stock = -bottom_gap;
|
||||||
|
bottom_thru = zThru;
|
||||||
bottom_z = Math.max(
|
bottom_z = Math.max(
|
||||||
(camZBottom ? bottom_stock + camZBottom : bottom_part) - bottom_thru,
|
(camZBottom ? bottom_stock + camZBottom : bottom_part) - bottom_thru,
|
||||||
(camZBottom ? bottom_stock + camZBottom : bottom_stock - bottom_thru)
|
(camZBottom ? bottom_stock + camZBottom : bottom_stock - bottom_thru)
|
||||||
),
|
);
|
||||||
bottom_cut = Math.max(bottom_z, -zThru),
|
bottom_cut = Math.max(bottom_z, -zThru);
|
||||||
top_stock = zTop,
|
top_stock = zTop;
|
||||||
top_part = zMax,
|
top_part = zMax;
|
||||||
top_gap = ztOff,
|
top_gap = ztOff;
|
||||||
top_z = camZTop ? bottom_stock + camZTop : top_stock,
|
top_z = camZTop ? bottom_stock + camZTop : top_stock;
|
||||||
workarea = util.round({
|
workarea = util.round({
|
||||||
top_stock,
|
top_stock, top_part, top_gap, top_z,
|
||||||
top_part,
|
bottom_stock, bottom_part, bottom_gap,
|
||||||
top_gap,
|
bottom_z, bottom_cut
|
||||||
top_z,
|
|
||||||
bottom_stock,
|
|
||||||
bottom_part,
|
|
||||||
bottom_gap,
|
|
||||||
bottom_z,
|
|
||||||
bottom_cut
|
|
||||||
}, 3);
|
}, 3);
|
||||||
|
|
||||||
// console.table({ workarea });
|
return structuredClone(workarea);
|
||||||
// console.table({ part_size });
|
};
|
||||||
// console.table({ stock });
|
|
||||||
|
// initial setup
|
||||||
|
var_compute();
|
||||||
|
|
||||||
if (tabs) {
|
if (tabs) {
|
||||||
// make tab polygons
|
// make tab polygons
|
||||||
|
|
@ -267,12 +269,11 @@ CAM.slice = async function(settings, widget, onupdate, ondone) {
|
||||||
|
|
||||||
// call slice() function on all ops in order
|
// call slice() function on all ops in order
|
||||||
let tracker = setSliceTracker({ rotation: 0 });
|
let tracker = setSliceTracker({ rotation: 0 });
|
||||||
let workarea_orig = structuredClone(workarea);
|
|
||||||
setAxisIndex();
|
setAxisIndex();
|
||||||
for (let op of opList) {
|
for (let op of opList) {
|
||||||
let weight = op.weight();
|
let weight = op.weight();
|
||||||
// apply operation override vars
|
// apply operation override vars
|
||||||
let workover = structuredClone(workarea_orig);
|
let workover = var_compute();
|
||||||
let valz = op.op;
|
let valz = op.op;
|
||||||
if (valz.ov_topz) {
|
if (valz.ov_topz) {
|
||||||
workover.top_z = bottom_stock + valz.ov_topz;
|
workover.top_z = bottom_stock + valz.ov_topz;
|
||||||
|
|
|
||||||
|
|
@ -704,7 +704,10 @@ class Widget {
|
||||||
|
|
||||||
getBoundingBox(refresh) {
|
getBoundingBox(refresh) {
|
||||||
if (!this.bounds || refresh || this.boundingBoxNeedsUpdate) {
|
if (!this.bounds || refresh || this.boundingBoxNeedsUpdate) {
|
||||||
this.bounds = new THREE.Box3().setFromArray(this.getGeoVertices());
|
this.bounds = new THREE.Box3().setFromArray(this.getGeoVertices({
|
||||||
|
translate: true,
|
||||||
|
unroll: false
|
||||||
|
}));
|
||||||
this.boundingBoxNeedsUpdate = false;
|
this.boundingBoxNeedsUpdate = false;
|
||||||
}
|
}
|
||||||
return this.bounds;
|
return this.bounds;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue