fix re-shadow after index rotations, carry angle through synth points
This commit is contained in:
parent
3f3fccbd2a
commit
3452297dc6
5 changed files with 26 additions and 21 deletions
|
|
@ -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<count; i += itemSize) {
|
||||
const a = new THREE.Vector3(array[ip++], array[ip++], array[ip++]);
|
||||
const b = new THREE.Vector3(array[ip++], array[ip++], array[ip++]);
|
||||
const c = new THREE.Vector3(array[ip++], array[ip++], array[ip++]);
|
||||
for (let i=0, ip=0; i<length; i += 3) {
|
||||
const a = new THREE.Vector3(geo[ip++], geo[ip++], geo[ip++]);
|
||||
const b = new THREE.Vector3(geo[ip++], geo[ip++], geo[ip++]);
|
||||
const c = new THREE.Vector3(geo[ip++], geo[ip++], geo[ip++]);
|
||||
const n = THREE.computeFaceNormal(a,b,c);
|
||||
if (n.z > 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<faces.length; ) {
|
||||
const a = faces[i++];
|
||||
|
|
|
|||
|
|
@ -297,6 +297,11 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
|||
point.y += wmy;
|
||||
point.z += zadd;
|
||||
|
||||
// carry rotation forward when not overridden
|
||||
if (point.a === undefined && lastPoint) {
|
||||
point.a = lastPoint.a;
|
||||
}
|
||||
|
||||
// console.log(point.z);
|
||||
if (nextIsMove) {
|
||||
cut = 0;
|
||||
|
|
@ -417,6 +422,7 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
|||
};
|
||||
|
||||
let ops = {
|
||||
stock,
|
||||
setTool,
|
||||
setDrill,
|
||||
setSpindle,
|
||||
|
|
|
|||
|
|
@ -247,9 +247,9 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
|
|||
let points = base.verticesToPoints(widget.getGeoVertices(true, true));
|
||||
state.slicer = new kiri.cam_slicer(points, {
|
||||
zlist: true,
|
||||
zline: true,
|
||||
nobucket: true // b/c negative Z when rotated
|
||||
zline: true
|
||||
});
|
||||
shadows = {};
|
||||
new CAM.OPS.shadow(state, { type: "shadow", silent: true }).slice(progress => {
|
||||
// console.log('reshadow', progress.round(3));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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++],
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue