From c1386ded5c13909afd61bfc7feac69ca0682c9cc Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Tue, 14 Feb 2023 19:37:51 -0500 Subject: [PATCH] allow z middle anchor offsetting, mostly driven by lathe requirements --- src/kiri-mode/cam/client.js | 4 ++-- src/kiri-mode/cam/topo4.js | 23 +++++++++++++++-------- src/kiri/platform.js | 8 ++++++-- src/kiri/widget.js | 8 ++++++-- web/kiri/lang/en.js | 2 +- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/kiri-mode/cam/client.js b/src/kiri-mode/cam/client.js index bffea6e2..af3178fe 100644 --- a/src/kiri-mode/cam/client.js +++ b/src/kiri-mode/cam/client.js @@ -254,14 +254,14 @@ CAM.init = function(kiri, api) { api.event.on("preview.end", () => { isParsed = false; - if (isCamMode && camStock) { + if (isCamMode) { let bounds = STACKS.getStack("bounds"); if (bounds) bounds.button("animate", animate); } }); api.event.on("code.loaded", (info) => { - if (isCamMode && camStock) { + if (isCamMode) { isParsed = true; let parse = STACKS.getStack("parse", SPACE.world); if (parse) parse.button("animate", animate); diff --git a/src/kiri-mode/cam/topo4.js b/src/kiri-mode/cam/topo4.js index f8c460ef..610c63d8 100644 --- a/src/kiri-mode/cam/topo4.js +++ b/src/kiri-mode/cam/topo4.js @@ -67,6 +67,7 @@ class Topo4 { this.tool = tool.generateProfile(resolution).profile; this.maxo = tool.profileDim.maxo * resolution; this.diam = tool.fluteDiameter(); + this.zoff = widget.track.top || 0; onupdate(0, "lathe"); @@ -82,13 +83,13 @@ class Topo4 { const lathe = await this.lathe(scale(onupdate, 0.75, 0.25)); - // ondone([...slices, ...lathe]); onupdate(1, "lathe"); ondone(lathe); + // ondone([...slices, ...lathe]); } async slice(onupdate) { - const { vertices, resolution, tabverts } = this; + const { vertices, resolution, tabverts, zoff } = this; const range = this.range = { min: Infinity, max: -Infinity }; const box = this.box = new THREE.Box2(); @@ -96,7 +97,7 @@ class Topo4 { // swap XZ in shared array for (let i=0, l=vertices.length; i { @@ -160,7 +160,11 @@ function platformUpdateTopZ(zdelta) { widget.setTopZ(stock.z - zdelta); break; 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; case 'bottom': widget.setTopZ(wzmax + zdelta); diff --git a/src/kiri/widget.js b/src/kiri/widget.js index 943a5063..8de81c15 100644 --- a/src/kiri/widget.js +++ b/src/kiri/widget.js @@ -430,6 +430,10 @@ class Widget { } } + get isIndexed() { + return this.track.indexed ? true : false; + } + setIndexed(z) { if (z !== this.track.indexed) { this.track.indexed = z; @@ -456,7 +460,7 @@ class Widget { track = this.track, mbb = mesh.getBoundingBox(), mbz = mbb.max.z; - if (z) { + if (z != undefined) { track.top = z; } else { track.top = mbz; @@ -510,7 +514,7 @@ class Widget { let dx = Math.sin(rad) * ln; let dy = ln - Math.cos(rad) * ln; this.mesh.rotation.x = -rad; - z = 0; + z = top; } else { this.mesh.rotation.x = 0; z += tz; diff --git a/web/kiri/lang/en.js b/web/kiri/lang/en.js index 62a04a65..0c6a1d52 100644 --- a/web/kiri/lang/en.js +++ b/web/kiri/lang/en.js @@ -679,7 +679,7 @@ self.kiri.lang['en-us'] = { ou_zanc_s: "z anchor", ou_zanc_l: ["controls the position of the part","when stock Z exceeds part Z"], 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_l: ["offset from part bottom","to limit cutting depth","in workspace units"], ou_zclr_s: "z clearance",