From 3452297dc60e1a8177d0535174610f4caf923c22 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Tue, 8 Nov 2022 14:46:40 -0500 Subject: [PATCH] fix re-shadow after index rotations, carry angle through synth points --- src/kiri-mode/cam/ops.js | 27 ++++++++++++++------------- src/kiri-mode/cam/prepare.js | 6 ++++++ src/kiri-mode/cam/slice.js | 4 ++-- src/kiri-mode/cam/slicer.js | 6 +----- src/kiri/widget.js | 4 +++- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/kiri-mode/cam/ops.js b/src/kiri-mode/cam/ops.js index 14967e0c..8e64c28f 100644 --- a/src/kiri-mode/cam/ops.js +++ b/src/kiri-mode/cam/ops.js @@ -49,6 +49,10 @@ class OpIndex extends CamOp { } prepare(ops, progress) { + const { lastPoint, zmax, camOut, stock } = ops; + // max point of stock corner radius when rotating (safe z when indexing) + const rzmax = (Math.max(stock.y, stock.z) * Math.sqrt(2)) / 2; + camOut(lastPoint().clone().setZ(rzmax), 0); } } @@ -352,7 +356,7 @@ class OpRough extends CamOp { }); slice.camLines = offset; - if (false) slice.output() + if (true) slice.output() .setLayer("slice", {line: 0xaaaa00}, true) .addPolys(slice.topPolys()) // .setLayer("top shadow", {line: 0x0000aa}) @@ -1571,28 +1575,25 @@ class OpShadow extends CamOp { // union triangles > z (opt cap < ztop) into polygon(s) CAM.shadowAt = function(widget, z, ztop) { - const geo = widget.cache.geo || new THREE.BufferGeometry() - .setAttribute('position', new THREE.BufferAttribute(widget.vertices, 3)); - widget.cache.geo = geo; - const { position } = geo.attributes; - const { itemSize, count, array } = position; + const geo = widget.cache.geo; + const length = geo.length; // cache faces with normals up - if (!widget._shadow_faces) { + if (!widget.cache.shadow) { const faces = []; - for (let i=0, ip=0; i 0.001) { faces.push(a,b,c); // faces.push(newPoint(...a), newPoint(...b), newPoint(...c)); } } - widget._shadow_faces = faces; + widget.cache.shadow = faces; } const found = []; - const faces = widget._shadow_faces; + const faces = widget.cache.shadow; const { checkOverUnderOn, intersectPoints } = self.kiri.cam_slicer; for (let i=0; i { // console.log('reshadow', progress.round(3)); }); diff --git a/src/kiri-mode/cam/slicer.js b/src/kiri-mode/cam/slicer.js index 8d6d8af3..e06c55ef 100644 --- a/src/kiri-mode/cam/slicer.js +++ b/src/kiri-mode/cam/slicer.js @@ -132,17 +132,13 @@ class Slicer { let bucketCount = Math.max(1, Math.ceil(zMax / (zSum / points.length)) - 1); let zScale = this.zScale = 1 / (zMax / bucketCount); let buckets = this.buckets = {}; - if (bucketCount > 1) {// && !this.options.nobucket) { + if (bucketCount > 1) { // create empty buckets let min = Math.floor(bounds.min.z * zScale); let max = Math.ceil(bounds.max.z * zScale); for (let i = min; i <= max; i++) { buckets[i] = []; } - // for (let i = 0; i <= bucketCount + 1; i++) { - // buckets.push([]); - // } - // copy triples into all matching z-buckets for (let i = 0, il = points.length; i < il; ) { let p1 = points[i++], diff --git a/src/kiri/widget.js b/src/kiri/widget.js index 55d116cd..d5522f75 100644 --- a/src/kiri/widget.js +++ b/src/kiri/widget.js @@ -667,7 +667,6 @@ class Widget { // if indexed, return points rotated about X and then offset let track = this.track; if (translate && track.indexed) { - let delta = track.delta; pos = pos.clone() .applyMatrix4( new THREE.Matrix4().makeRotationX(-track.indexRad) ); } @@ -688,6 +687,9 @@ class Widget { } else if (translate) { pos = pos.slice(); } + // used by CAM.shadowAt() + this.cache.geo = pos; + this.cache.shadow = undefined; return pos; }