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) {
|
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;
|
slice.camLines = offset;
|
||||||
if (false) slice.output()
|
if (true) slice.output()
|
||||||
.setLayer("slice", {line: 0xaaaa00}, true)
|
.setLayer("slice", {line: 0xaaaa00}, true)
|
||||||
.addPolys(slice.topPolys())
|
.addPolys(slice.topPolys())
|
||||||
// .setLayer("top shadow", {line: 0x0000aa})
|
// .setLayer("top shadow", {line: 0x0000aa})
|
||||||
|
|
@ -1571,28 +1575,25 @@ class OpShadow extends CamOp {
|
||||||
|
|
||||||
// union triangles > z (opt cap < ztop) into polygon(s)
|
// union triangles > z (opt cap < ztop) into polygon(s)
|
||||||
CAM.shadowAt = function(widget, z, ztop) {
|
CAM.shadowAt = function(widget, z, ztop) {
|
||||||
const geo = widget.cache.geo || new THREE.BufferGeometry()
|
const geo = widget.cache.geo;
|
||||||
.setAttribute('position', new THREE.BufferAttribute(widget.vertices, 3));
|
const length = geo.length;
|
||||||
widget.cache.geo = geo;
|
|
||||||
const { position } = geo.attributes;
|
|
||||||
const { itemSize, count, array } = position;
|
|
||||||
// cache faces with normals up
|
// cache faces with normals up
|
||||||
if (!widget._shadow_faces) {
|
if (!widget.cache.shadow) {
|
||||||
const faces = [];
|
const faces = [];
|
||||||
for (let i=0, ip=0; i<count; i += itemSize) {
|
for (let i=0, ip=0; i<length; i += 3) {
|
||||||
const a = new THREE.Vector3(array[ip++], array[ip++], array[ip++]);
|
const a = new THREE.Vector3(geo[ip++], geo[ip++], geo[ip++]);
|
||||||
const b = new THREE.Vector3(array[ip++], array[ip++], array[ip++]);
|
const b = new THREE.Vector3(geo[ip++], geo[ip++], geo[ip++]);
|
||||||
const c = new THREE.Vector3(array[ip++], array[ip++], array[ip++]);
|
const c = new THREE.Vector3(geo[ip++], geo[ip++], geo[ip++]);
|
||||||
const n = THREE.computeFaceNormal(a,b,c);
|
const n = THREE.computeFaceNormal(a,b,c);
|
||||||
if (n.z > 0.001) {
|
if (n.z > 0.001) {
|
||||||
faces.push(a,b,c);
|
faces.push(a,b,c);
|
||||||
// faces.push(newPoint(...a), newPoint(...b), newPoint(...c));
|
// faces.push(newPoint(...a), newPoint(...b), newPoint(...c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
widget._shadow_faces = faces;
|
widget.cache.shadow = faces;
|
||||||
}
|
}
|
||||||
const found = [];
|
const found = [];
|
||||||
const faces = widget._shadow_faces;
|
const faces = widget.cache.shadow;
|
||||||
const { checkOverUnderOn, intersectPoints } = self.kiri.cam_slicer;
|
const { checkOverUnderOn, intersectPoints } = self.kiri.cam_slicer;
|
||||||
for (let i=0; i<faces.length; ) {
|
for (let i=0; i<faces.length; ) {
|
||||||
const a = faces[i++];
|
const a = faces[i++];
|
||||||
|
|
|
||||||
|
|
@ -297,6 +297,11 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
||||||
point.y += wmy;
|
point.y += wmy;
|
||||||
point.z += zadd;
|
point.z += zadd;
|
||||||
|
|
||||||
|
// carry rotation forward when not overridden
|
||||||
|
if (point.a === undefined && lastPoint) {
|
||||||
|
point.a = lastPoint.a;
|
||||||
|
}
|
||||||
|
|
||||||
// console.log(point.z);
|
// console.log(point.z);
|
||||||
if (nextIsMove) {
|
if (nextIsMove) {
|
||||||
cut = 0;
|
cut = 0;
|
||||||
|
|
@ -417,6 +422,7 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
||||||
};
|
};
|
||||||
|
|
||||||
let ops = {
|
let ops = {
|
||||||
|
stock,
|
||||||
setTool,
|
setTool,
|
||||||
setDrill,
|
setDrill,
|
||||||
setSpindle,
|
setSpindle,
|
||||||
|
|
|
||||||
|
|
@ -247,9 +247,9 @@ CAM.slice = function(settings, widget, onupdate, ondone) {
|
||||||
let points = base.verticesToPoints(widget.getGeoVertices(true, true));
|
let points = base.verticesToPoints(widget.getGeoVertices(true, true));
|
||||||
state.slicer = new kiri.cam_slicer(points, {
|
state.slicer = new kiri.cam_slicer(points, {
|
||||||
zlist: true,
|
zlist: true,
|
||||||
zline: true,
|
zline: true
|
||||||
nobucket: true // b/c negative Z when rotated
|
|
||||||
});
|
});
|
||||||
|
shadows = {};
|
||||||
new CAM.OPS.shadow(state, { type: "shadow", silent: true }).slice(progress => {
|
new CAM.OPS.shadow(state, { type: "shadow", silent: true }).slice(progress => {
|
||||||
// console.log('reshadow', progress.round(3));
|
// 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 bucketCount = Math.max(1, Math.ceil(zMax / (zSum / points.length)) - 1);
|
||||||
let zScale = this.zScale = 1 / (zMax / bucketCount);
|
let zScale = this.zScale = 1 / (zMax / bucketCount);
|
||||||
let buckets = this.buckets = {};
|
let buckets = this.buckets = {};
|
||||||
if (bucketCount > 1) {// && !this.options.nobucket) {
|
if (bucketCount > 1) {
|
||||||
// create empty buckets
|
// create empty buckets
|
||||||
let min = Math.floor(bounds.min.z * zScale);
|
let min = Math.floor(bounds.min.z * zScale);
|
||||||
let max = Math.ceil(bounds.max.z * zScale);
|
let max = Math.ceil(bounds.max.z * zScale);
|
||||||
for (let i = min; i <= max; i++) {
|
for (let i = min; i <= max; i++) {
|
||||||
buckets[i] = [];
|
buckets[i] = [];
|
||||||
}
|
}
|
||||||
// for (let i = 0; i <= bucketCount + 1; i++) {
|
|
||||||
// buckets.push([]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// copy triples into all matching z-buckets
|
// copy triples into all matching z-buckets
|
||||||
for (let i = 0, il = points.length; i < il; ) {
|
for (let i = 0, il = points.length; i < il; ) {
|
||||||
let p1 = points[i++],
|
let p1 = points[i++],
|
||||||
|
|
|
||||||
|
|
@ -667,7 +667,6 @@ class Widget {
|
||||||
// if indexed, return points rotated about X and then offset
|
// if indexed, return points rotated about X and then offset
|
||||||
let track = this.track;
|
let track = this.track;
|
||||||
if (translate && track.indexed) {
|
if (translate && track.indexed) {
|
||||||
let delta = track.delta;
|
|
||||||
pos = pos.clone()
|
pos = pos.clone()
|
||||||
.applyMatrix4( new THREE.Matrix4().makeRotationX(-track.indexRad) );
|
.applyMatrix4( new THREE.Matrix4().makeRotationX(-track.indexRad) );
|
||||||
}
|
}
|
||||||
|
|
@ -688,6 +687,9 @@ class Widget {
|
||||||
} else if (translate) {
|
} else if (translate) {
|
||||||
pos = pos.slice();
|
pos = pos.slice();
|
||||||
}
|
}
|
||||||
|
// used by CAM.shadowAt()
|
||||||
|
this.cache.geo = pos;
|
||||||
|
this.cache.shadow = undefined;
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue