apply axis rotations to trace lines in op area

This commit is contained in:
Stewart Allen 2025-12-29 17:53:17 -05:00
commit 07da144aee
3 changed files with 13 additions and 6 deletions

View file

@ -794,11 +794,12 @@ export class Polygon {
return [this.first().key, this.last().key, this.length].join('~~'); return [this.first().key, this.last().key, this.length].join('~~');
} }
applyRotations() { applyRotations(deg) {
for (let point of this.points) { for (let point of this.points) {
if (point.a) { let angleDeg = deg ?? point.a;
if (angleDeg) {
let p2 = new Vector3(point.x, point.y, point.z) let p2 = new Vector3(point.x, point.y, point.z)
.applyAxisAngle(XAXIS, point.a * DEG2RAD); .applyAxisAngle(XAXIS, angleDeg * DEG2RAD);
point.x = p2.x; point.x = p2.x;
point.y = p2.y; point.y = p2.y;
point.z = p2.z; point.z = p2.z;

View file

@ -29,7 +29,7 @@ class OpArea extends CamOp {
let { op, state } = this; let { op, state } = this;
let { direction, down, expand, flats, flatOff, follow } = op; let { direction, down, expand, flats, flatOff, follow } = op;
let { mode, outline, over, rename, smooth, tool } = op; let { mode, outline, over, rename, smooth, tool } = op;
let { addSlices, color, cutTabs, settings } = state; let { addSlices, axisIndex, color, cutTabs, settings } = state;
let { shadowAt, setToolDiam, tabs, widget, workarea } = state; let { shadowAt, setToolDiam, tabs, widget, workarea } = state;
let areaTool = new Tool(settings, tool); let areaTool = new Tool(settings, tool);
@ -75,6 +75,10 @@ class OpArea extends CamOp {
let poly = newPolygon().fromArray(arr); let poly = newPolygon().fromArray(arr);
aminz = Math.min(aminz, poly.minZ()); aminz = Math.min(aminz, poly.minZ());
polys.push(poly); polys.push(poly);
if (axisIndex) {
// traces come from unrotatead widget edges
poly.applyRotations(axisIndex);
}
} }
// connect open poly edge segments into closed loops (when possible) // connect open poly edge segments into closed loops (when possible)

View file

@ -180,6 +180,8 @@ export async function cam_slice(settings, widget, onupdate, ondone) {
let slicer; let slicer;
let state = { let state = {
addSlices, addSlices,
axisIndex,
axisRotation,
bounds, bounds,
color, color,
computeShadows, computeShadows,
@ -261,8 +263,8 @@ export async function cam_slice(settings, widget, onupdate, ondone) {
} }
async function setAxisIndex(degrees = 0, absolute = true) { async function setAxisIndex(degrees = 0, absolute = true) {
axisIndex = absolute ? degrees : (axisIndex || 0) + degrees; state.axisIndex = axisIndex = absolute ? degrees : (axisIndex || 0) + degrees;
axisRotation = (Math.PI / 180) * axisIndex; state.axisRotation = axisRotation = (Math.PI / 180) * axisIndex;
widget.setAxisIndex(isIndexed ? -axisIndex : 0); widget.setAxisIndex(isIndexed ? -axisIndex : 0);
state.tabs = tabs = []; state.tabs = tabs = [];
for (let tab of tabW) { for (let tab of tabW) {