allow newSlice to track a specified widget to aid 4th axis visuals

This commit is contained in:
Stewart Allen 2022-11-02 10:43:58 -04:00
commit f588e2e5cf
5 changed files with 33 additions and 14 deletions

View file

@ -471,7 +471,6 @@ class OpOutline extends CamOp {
if (op.down <= 0) {
throw `invalid step down "${op.down}"`;
}
let toolDiam = this.toolDiam = new CAM.Tool(settings, op.tool).fluteDiameter();
updateToolDiams(toolDiam);
@ -622,6 +621,9 @@ class OpOutline extends CamOp {
slice.camLines = offset;
});
// when top expand fails above, it creates an empty slice
slices = slices.filter(s => s.camLines);
// project empty up and render
for (let slice of slices) {
if (false) slice.output()

View file

@ -11,7 +11,7 @@
gapp.register("kiri-mode.cam.slice", [], (root, exports) => {
const { base, kiri } = root;
const { driver, newSlice } = kiri;
const { driver, newSlice, trackWidget } = kiri;
const { polygons, newPoint, newPolygon } = base;
const { CAM } = driver;
const { OPS } = CAM;
@ -149,7 +149,7 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
sliceAll.appendAll(slices);
if (axisIndex !== undefined) {
// update slice cam lines to add axis indexing
for (let slice of slices) {
for (let slice of slices.filter(s => s.camLines)) {
for (let poly of slice.camLines) {
for (let point of poly.points) {
point.a = -axisIndex;
@ -208,6 +208,7 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
state.ops = opList;
// call slice() function on all ops in order
trackWidget(widget);
setAxisIndex(undefined);
for (let op of opList) {
let weight = op.weight();
@ -215,7 +216,7 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
onupdate((opSum + (progress * weight)) / opTot, message || op.type());
});
// setup new state when indexing the workspace
if (false && op.op.type === "index") {
if (true && op.op.type === "index") {
let points = base.verticesToPoints(widget.getGeoVertices(true, true));
state.slicer = new kiri.cam_slicer(points, {
zlist: true,
@ -223,12 +224,13 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
nobucket: true // b/c negative Z when rotated
});
new CAM.OPS.shadow(state, { type: "shadow", silent: true }).slice(progress => {
console.log('reshadow', progress.round(3));
// console.log('reshadow', progress.round(3));
});
}
camOps.push(op);
opSum += weight;
}
trackWidget(undefined);
// reindex
sliceAll.forEach((slice, index) => slice.index = index);

View file

@ -404,7 +404,7 @@ kiri.Layers.prototype.encode = function(state) {
} : undefined,
cpath: layer.cpath || codec.undef,
rotation: layer.rotation,
posiiton: layer.position
position: layer.position
}
})
};

View file

@ -13,6 +13,12 @@ const { util } = base;
const POLY = base.polygons;
const NOKEY = key.NONE;
let tracked;
function trackWidget(widget) {
tracked = widget;
}
/**
* Object encapsulates a z-slice from an object. This code is shared by the
* client and the worker thread. As such, the view layers are ignored in the
@ -38,7 +44,15 @@ class Slice {
*/
output() {
if (this.layers) return this.layers;
return this.layers = new kiri.Layers();
let layers = this.layers = new kiri.Layers();
if (tracked) {
let { track } = tracked;
let { indexed, indexRad, delta } = track;
if (indexed) {
layers.setRotation(indexRad);
}
}
return layers;
};
/**
@ -239,7 +253,8 @@ gapp.overlay(kiri, {
Top,
Slice,
newTop,
newSlice
newSlice,
trackWidget
});
});

View file

@ -645,17 +645,17 @@ class Widget {
this.points = null;
}
getGeoVertices(unroll, index) {
getGeoVertices(unroll, translate) {
let geo = this.mesh.geometry;
let pos = geo.getAttribute('position');
// if indexed, return points rotated about X and then offset
let track = this.track;
if (index && track.indexed) {
if (translate && track.indexed) {
let delta = track.delta;
pos = pos.clone().applyMatrix4(
new THREE.Matrix4().makeRotationX(track.indexRad)
).applyMatrix4(
new THREE.Matrix4().makeTranslation(0, -delta.y, -delta.z + track.tzoff)
new THREE.Matrix4().makeRotationX(-track.indexRad)
// ).applyMatrix4(
// new THREE.Matrix4().makeTranslation(0, -delta.y, -delta.z + track.tzoff)
);
}
pos = pos.array;
@ -672,7 +672,7 @@ class Widget {
pp2[inc++] = pos[ip];
}
pos = pp2;
} else if (index) {
} else if (translate) {
pos = pos.slice();
}
return pos;