add shadow docs, add ztop limit to pocket and trace

This commit is contained in:
Stewart Allen 2025-02-07 17:52:41 -05:00
commit a48b0f1d80
7 changed files with 138 additions and 41 deletions

View file

@ -12,6 +12,7 @@
gapp.register("kiri-mode.cam.slice", (root, exports) => {
const { base, kiri } = root;
const { util } = base;
const { driver, newSlice, setSliceTracker } = kiri;
const { polygons, newPoint, newPolygon } = base;
const { CAM } = driver;
@ -35,6 +36,7 @@ CAM.slice = async function(settings, widget, onupdate, ondone) {
sliceAll = widget.slices = [],
bounds = widget.getBoundingBox(),
track = widget.track,
{ camZTop, camZBottom, camZThru } = proc,
// widget top z as defined by setTopz()
wztop = track.top,
// distance between top of part and top of stock
@ -43,11 +45,11 @@ CAM.slice = async function(settings, widget, onupdate, ondone) {
zbOff = isIndexed ? 0 : (wztop - track.box.d),
// defined z bottom offset by distance to stock bottom
// keeps the z bottom relative to the part when z align changes
zBottom = isIndexed ? proc.camZBottom : proc.camZBottom - zbOff,
zBottom = isIndexed ? camZBottom : camZBottom - zbOff,
// greater of widget bottom and z bottom
zMin = isIndexed ? bounds.min.z : Math.max(bounds.min.z, zBottom),
zMax = bounds.max.z,
zThru = proc.camZBottom ? 0 : (proc.camZThru || 0),
zThru = camZBottom ? 0 : (camZThru || 0),
zTop = zMax + ztOff,
minToolDiam = Infinity,
maxToolDiam = -Infinity,
@ -57,7 +59,30 @@ CAM.slice = async function(settings, widget, onupdate, ondone) {
unsafe = proc.camExpertFast,
units = settings.controller.units === 'in' ? 25.4 : 1,
axisRotation,
axisIndex;
axisIndex,
// new work area tracking
part_size = bounds.dim,
bottom_gap = zbOff,
bottom_part = 0,
bottom_stock = -bottom_gap,
bottom_thru = zThru,
bottom_z = (camZBottom ? bottom_stock + proc.camZBottom : bottom_part) - bottom_thru,
top_stock = zTop,
top_part = zMax,
top_gap = ztOff,
top_z = camZTop ? bottom_stock + camZTop : top_stock,
workarea = util.round({
top_stock,
top_part,
top_z,
bottom_stock,
bottom_part,
bottom_z
}, 3);
console.table({ workarea });
// console.table({ part_size });
// console.table({ stock });
if (tabs) {
// make tab polygons
@ -65,7 +90,7 @@ CAM.slice = async function(settings, widget, onupdate, ondone) {
let zero = newPoint(0,0,0);
let point = newPoint(tab.pos.x, tab.pos.y, tab.pos.z);
let poly = newPolygon().centerRectangle(zero, tab.dim.x, tab.dim.y);
let tslice = newSlice(0);
// let tslice = newSlice(0);
let m4 = new THREE.Matrix4().makeRotationFromQuaternion(
new THREE.Quaternion(tab.rot._x, tab.rot._y, tab.rot._z, tab.rot._w)
);
@ -202,7 +227,8 @@ CAM.slice = async function(settings, widget, onupdate, ondone) {
zTop,
unsafe,
color,
dark
dark,
workarea
};
let opList = [
@ -279,7 +305,7 @@ CAM.slice = async function(settings, widget, onupdate, ondone) {
// add shadow perimeter to terrain to catch outside moves off part
let tabpoly = tabs ? tabs.map(tab => tab.poly) : [];
let allpoly = POLY.union([...state.shadowTop.tops, ...tabpoly, ...state.shadowTop.slice.shadow], 0, true);
let allpoly = POLY.union([...state.shadow.base, ...tabpoly], 0, true);
let shadowOff = maxToolDiam < 0 ? allpoly :
POLY.offset(allpoly, [minToolDiam/2,maxToolDiam/2], { count: 2, flat: true, minArea: 0 });
state.terrain.forEach(level => level.tops.appendAll(shadowOff));