allow z middle anchor offsetting, mostly driven by lathe requirements
This commit is contained in:
parent
6c67c93988
commit
c1386ded5c
5 changed files with 30 additions and 15 deletions
|
|
@ -254,14 +254,14 @@ CAM.init = function(kiri, api) {
|
||||||
|
|
||||||
api.event.on("preview.end", () => {
|
api.event.on("preview.end", () => {
|
||||||
isParsed = false;
|
isParsed = false;
|
||||||
if (isCamMode && camStock) {
|
if (isCamMode) {
|
||||||
let bounds = STACKS.getStack("bounds");
|
let bounds = STACKS.getStack("bounds");
|
||||||
if (bounds) bounds.button("animate", animate);
|
if (bounds) bounds.button("animate", animate);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
api.event.on("code.loaded", (info) => {
|
api.event.on("code.loaded", (info) => {
|
||||||
if (isCamMode && camStock) {
|
if (isCamMode) {
|
||||||
isParsed = true;
|
isParsed = true;
|
||||||
let parse = STACKS.getStack("parse", SPACE.world);
|
let parse = STACKS.getStack("parse", SPACE.world);
|
||||||
if (parse) parse.button("animate", animate);
|
if (parse) parse.button("animate", animate);
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@ class Topo4 {
|
||||||
this.tool = tool.generateProfile(resolution).profile;
|
this.tool = tool.generateProfile(resolution).profile;
|
||||||
this.maxo = tool.profileDim.maxo * resolution;
|
this.maxo = tool.profileDim.maxo * resolution;
|
||||||
this.diam = tool.fluteDiameter();
|
this.diam = tool.fluteDiameter();
|
||||||
|
this.zoff = widget.track.top || 0;
|
||||||
|
|
||||||
onupdate(0, "lathe");
|
onupdate(0, "lathe");
|
||||||
|
|
||||||
|
|
@ -82,13 +83,13 @@ class Topo4 {
|
||||||
|
|
||||||
const lathe = await this.lathe(scale(onupdate, 0.75, 0.25));
|
const lathe = await this.lathe(scale(onupdate, 0.75, 0.25));
|
||||||
|
|
||||||
// ondone([...slices, ...lathe]);
|
|
||||||
onupdate(1, "lathe");
|
onupdate(1, "lathe");
|
||||||
ondone(lathe);
|
ondone(lathe);
|
||||||
|
// ondone([...slices, ...lathe]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async slice(onupdate) {
|
async slice(onupdate) {
|
||||||
const { vertices, resolution, tabverts } = this;
|
const { vertices, resolution, tabverts, zoff } = this;
|
||||||
|
|
||||||
const range = this.range = { min: Infinity, max: -Infinity };
|
const range = this.range = { min: Infinity, max: -Infinity };
|
||||||
const box = this.box = new THREE.Box2();
|
const box = this.box = new THREE.Box2();
|
||||||
|
|
@ -96,7 +97,7 @@ class Topo4 {
|
||||||
// swap XZ in shared array
|
// swap XZ in shared array
|
||||||
for (let i=0, l=vertices.length; i<l; i += 3) {
|
for (let i=0, l=vertices.length; i<l; i += 3) {
|
||||||
const x = vertices[i];
|
const x = vertices[i];
|
||||||
const z = vertices[i + 2];
|
const z = vertices[i + 2] + zoff;
|
||||||
vertices[i] = z;
|
vertices[i] = z;
|
||||||
vertices[i + 2] = x;
|
vertices[i + 2] = x;
|
||||||
range.min = Math.min(range.min, x);
|
range.min = Math.min(range.min, x);
|
||||||
|
|
@ -110,7 +111,7 @@ class Topo4 {
|
||||||
// merge in tab vertices here so they don't affect slice range / dimensions
|
// merge in tab vertices here so they don't affect slice range / dimensions
|
||||||
for (let i=0, l=tabverts.length; i<l; i += 3) {
|
for (let i=0, l=tabverts.length; i<l; i += 3) {
|
||||||
const x = tabverts[i];
|
const x = tabverts[i];
|
||||||
const z = tabverts[i + 2];
|
const z = tabverts[i + 2] + zoff;
|
||||||
tabverts[i] = z;
|
tabverts[i] = z;
|
||||||
tabverts[i + 2] = x;
|
tabverts[i + 2] = x;
|
||||||
}
|
}
|
||||||
|
|
@ -245,9 +246,10 @@ class Topo4 {
|
||||||
|
|
||||||
// iterate over all slices (real x = z)
|
// iterate over all slices (real x = z)
|
||||||
// find max real z using z ray intersect from tool point to slice lines + offset
|
// find max real z using z ray intersect from tool point to slice lines + offset
|
||||||
|
let lz = 0;
|
||||||
for (let si = 0; si < slen; si += sinc) {
|
for (let si = 0; si < slen; si += sinc) {
|
||||||
const rx = oslices[si].z;
|
const rx = oslices[si].z;
|
||||||
let mz = 0;
|
let mz = -Infinity;
|
||||||
// iterate over tool offsets
|
// iterate over tool offsets
|
||||||
for (let ti = 0; ti < tlen; ) {
|
for (let ti = 0; ti < tlen; ) {
|
||||||
// tool offset in grid units from present x (si)
|
// tool offset in grid units from present x (si)
|
||||||
|
|
@ -278,14 +280,19 @@ class Topo4 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
heights.push(rx, 0, Math.max(zBottom, mz));
|
if (mz === -Infinity) {
|
||||||
|
mz = Math.max(lz, 0);
|
||||||
|
} else if (zBottom && mz < zBottom) {
|
||||||
|
mz = zBottom;
|
||||||
|
}
|
||||||
|
heights.push(rx, 0, lz = mz);
|
||||||
}
|
}
|
||||||
|
|
||||||
return heights;
|
return heights;
|
||||||
}
|
}
|
||||||
|
|
||||||
async latheWorker(onupdate) {
|
async latheWorker(onupdate) {
|
||||||
const { sliced, tool } = this;
|
const { sliced, tool, zoff } = this;
|
||||||
|
|
||||||
const rota = this.angle * DEG2RAD;
|
const rota = this.angle * DEG2RAD;
|
||||||
const steps = (Math.PI * 2) / rota;
|
const steps = (Math.PI * 2) / rota;
|
||||||
|
|
@ -333,7 +340,7 @@ class Topo4 {
|
||||||
slice.camLines[0].push(poly.points[0].clone());
|
slice.camLines[0].push(poly.points[0].clone());
|
||||||
slice.output()
|
slice.output()
|
||||||
.setLayer("lathe", { line: 0xffff00 })
|
.setLayer("lathe", { line: 0xffff00 })
|
||||||
.addPoly(poly.clone().applyRotations());
|
.addPoly(poly.clone().applyRotations().move({ z: -zoff, x:0, y:0 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log({ tool, slices, paths });
|
// console.log({ tool, slices, paths });
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ function platformUpdateMidZ() {
|
||||||
space.platform.setMaxZ(topZ);
|
space.platform.setMaxZ(topZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
function platformUpdateTopZ(zdelta) {
|
function platformUpdateTopZ() {
|
||||||
const { process, stock } = current();
|
const { process, stock } = current();
|
||||||
const MODE = get_mode();
|
const MODE = get_mode();
|
||||||
api.widgets.each(widget => {
|
api.widgets.each(widget => {
|
||||||
|
|
@ -160,7 +160,11 @@ function platformUpdateTopZ(zdelta) {
|
||||||
widget.setTopZ(stock.z - zdelta);
|
widget.setTopZ(stock.z - zdelta);
|
||||||
break;
|
break;
|
||||||
case 'middle':
|
case 'middle':
|
||||||
widget.setTopZ(stock.z - (stock.z - wzmax) / 2);
|
if (widget.isIndexed) {
|
||||||
|
widget.setTopZ(zdelta);
|
||||||
|
} else {
|
||||||
|
widget.setTopZ(stock.z - (stock.z - wzmax) / 2 + zdelta);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'bottom':
|
case 'bottom':
|
||||||
widget.setTopZ(wzmax + zdelta);
|
widget.setTopZ(wzmax + zdelta);
|
||||||
|
|
|
||||||
|
|
@ -430,6 +430,10 @@ class Widget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isIndexed() {
|
||||||
|
return this.track.indexed ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
setIndexed(z) {
|
setIndexed(z) {
|
||||||
if (z !== this.track.indexed) {
|
if (z !== this.track.indexed) {
|
||||||
this.track.indexed = z;
|
this.track.indexed = z;
|
||||||
|
|
@ -456,7 +460,7 @@ class Widget {
|
||||||
track = this.track,
|
track = this.track,
|
||||||
mbb = mesh.getBoundingBox(),
|
mbb = mesh.getBoundingBox(),
|
||||||
mbz = mbb.max.z;
|
mbz = mbb.max.z;
|
||||||
if (z) {
|
if (z != undefined) {
|
||||||
track.top = z;
|
track.top = z;
|
||||||
} else {
|
} else {
|
||||||
track.top = mbz;
|
track.top = mbz;
|
||||||
|
|
@ -510,7 +514,7 @@ class Widget {
|
||||||
let dx = Math.sin(rad) * ln;
|
let dx = Math.sin(rad) * ln;
|
||||||
let dy = ln - Math.cos(rad) * ln;
|
let dy = ln - Math.cos(rad) * ln;
|
||||||
this.mesh.rotation.x = -rad;
|
this.mesh.rotation.x = -rad;
|
||||||
z = 0;
|
z = top;
|
||||||
} else {
|
} else {
|
||||||
this.mesh.rotation.x = 0;
|
this.mesh.rotation.x = 0;
|
||||||
z += tz;
|
z += tz;
|
||||||
|
|
|
||||||
|
|
@ -679,7 +679,7 @@ self.kiri.lang['en-us'] = {
|
||||||
ou_zanc_s: "z anchor",
|
ou_zanc_s: "z anchor",
|
||||||
ou_zanc_l: ["controls the position of the part","when stock Z exceeds part Z"],
|
ou_zanc_l: ["controls the position of the part","when stock Z exceeds part Z"],
|
||||||
ou_ztof_s: "z offset",
|
ou_ztof_s: "z offset",
|
||||||
ou_ztof_l: ["offset z anchor","in workspace units","has no effect when","anchor is middle"],
|
ou_ztof_l: ["offset z anchor","in workspace units"],
|
||||||
ou_zbot_s: "z bottom",
|
ou_zbot_s: "z bottom",
|
||||||
ou_zbot_l: ["offset from part bottom","to limit cutting depth","in workspace units"],
|
ou_zbot_l: ["offset from part bottom","to limit cutting depth","in workspace units"],
|
||||||
ou_zclr_s: "z clearance",
|
ou_zclr_s: "z clearance",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue