experiment with buckets object instead of array to handle negative z. avoid mutating output points in renderer
This commit is contained in:
parent
cda3dbd914
commit
54b9889ffa
3 changed files with 37 additions and 30 deletions
|
|
@ -125,17 +125,23 @@ class Slicer {
|
||||||
* to reduce the search space in complex models
|
* to reduce the search space in complex models
|
||||||
*/
|
*/
|
||||||
computeBuckets() {
|
computeBuckets() {
|
||||||
|
let bounds = this.bounds;
|
||||||
let zSum = this.zSum;
|
let zSum = this.zSum;
|
||||||
let zMax = this.bounds.max.z;
|
let zMax = this.bounds.max.z;
|
||||||
let points = this.points;
|
let points = this.points;
|
||||||
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) {// && !this.options.nobucket) {
|
||||||
// create empty buckets
|
// create empty buckets
|
||||||
for (let i = 0; i <= bucketCount + 1; i++) {
|
let min = Math.floor(bounds.min.z * zScale);
|
||||||
buckets.push([]);
|
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
|
// 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; ) {
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,7 @@ async function path(levels, update, opts = {}) {
|
||||||
let lastTool = null;
|
let lastTool = null;
|
||||||
let lastEnd = null;
|
let lastEnd = null;
|
||||||
let lastOut = null;
|
let lastOut = null;
|
||||||
|
let lastOutPoint = null;
|
||||||
let current = null;
|
let current = null;
|
||||||
let currentLaser = null;
|
let currentLaser = null;
|
||||||
let retracted = false;
|
let retracted = false;
|
||||||
|
|
@ -152,40 +153,38 @@ async function path(levels, update, opts = {}) {
|
||||||
}
|
}
|
||||||
if (retracted && out.emit) {
|
if (retracted && out.emit) {
|
||||||
retracted = false;
|
retracted = false;
|
||||||
engages.push(lastOut.point);
|
engages.push(lastOutPoint);
|
||||||
|
}
|
||||||
|
let outPoint = out.point;
|
||||||
|
// rotate 4th axis indexed points
|
||||||
|
// todo -- add spark lines
|
||||||
|
if (outPoint && outPoint.a) {
|
||||||
|
let { point } = out;
|
||||||
|
let p2 = new THREE.Vector3(point.x, point.y, point.z)
|
||||||
|
.applyAxisAngle(XAXIS, point.a * DEG2RAD);
|
||||||
|
outPoint = base.newPoint(p2.x, p2.y, p2.z);
|
||||||
|
// let sp = base.newPoint(outPoint.x * 1.1, outPoint.y * 1.1, outPoint.z * 1.1);
|
||||||
|
// sparks.push(outPoint, sp);
|
||||||
}
|
}
|
||||||
if (out.tool !== lastTool) {
|
if (out.tool !== lastTool) {
|
||||||
lastTool = out.tool;
|
lastTool = out.tool;
|
||||||
changes.push(out.point);
|
changes.push(outPoint);
|
||||||
}
|
}
|
||||||
if (out.retract) {
|
if (out.retract) {
|
||||||
retracts.push(out.point);
|
retracts.push(outPoint);
|
||||||
retracted = true;
|
retracted = true;
|
||||||
retractz++;
|
retractz++;
|
||||||
}
|
}
|
||||||
if (!out.point) {
|
if (!outPoint) {
|
||||||
// in cam mode, these are drilling or dwell ops
|
// in cam mode, these are drilling or dwell ops
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// rotate 4th axis indexed points
|
|
||||||
// todo -- add spark lines
|
|
||||||
if (out.point.a) {
|
|
||||||
let { point } = out;
|
|
||||||
let p2 = new THREE.Vector3(point.x, point.y, point.z)
|
|
||||||
.applyAxisAngle(XAXIS, point.a * DEG2RAD);
|
|
||||||
out.point.x = p2.x;
|
|
||||||
out.point.y = p2.y;
|
|
||||||
out.point.z = p2.z;
|
|
||||||
// let sp = base.newPoint(out.point.x * 1.1, out.point.y * 1.1, out.point.z * 1.1);
|
|
||||||
// sparks.push(out.point, sp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastOut) {
|
if (lastOut) {
|
||||||
if (arrowAll || lastOut.emit !== out.emit) {
|
if (arrowAll || lastOut.emit !== out.emit) {
|
||||||
heads.push({p1: lastOut.point, p2: out.point});
|
heads.push({p1: lastOutPoint, p2: outPoint});
|
||||||
}
|
}
|
||||||
const op = out.point, lp = lastOut.point;
|
const op = outPoint, lp = lastOutPoint;
|
||||||
// const moved = Math.max(
|
// const moved = Math.max(
|
||||||
// Math.abs(op.x - lp.x),
|
// Math.abs(op.x - lp.x),
|
||||||
// Math.abs(op.y - lp.y),
|
// Math.abs(op.y - lp.y),
|
||||||
|
|
@ -194,18 +193,18 @@ async function path(levels, update, opts = {}) {
|
||||||
if (out.emit) {
|
if (out.emit) {
|
||||||
if (!lastOut.emit || (ckspeed && out.speed !== lastOut.speed) || lastEnd) {
|
if (!lastOut.emit || (ckspeed && out.speed !== lastOut.speed) || lastEnd) {
|
||||||
current = newPolygon().setOpen();
|
current = newPolygon().setOpen();
|
||||||
current.push(lastOut.point);
|
current.push(lastOutPoint);
|
||||||
current.color = color(out);
|
current.color = color(out);
|
||||||
pushPrint(out.tool, current);
|
pushPrint(out.tool, current);
|
||||||
}
|
}
|
||||||
current.push(out.point);
|
current.push(outPoint);
|
||||||
} else {
|
} else {
|
||||||
if (lastOut.emit || lastEnd) {
|
if (lastOut.emit || lastEnd) {
|
||||||
current = newPolygon().setOpen();
|
current = newPolygon().setOpen();
|
||||||
current.push(lastOut.point);
|
current.push(lastOutPoint);
|
||||||
moves.push(current);
|
moves.push(current);
|
||||||
}
|
}
|
||||||
current.push(out.point);
|
current.push(outPoint);
|
||||||
}
|
}
|
||||||
if (out.type === 'laser') {
|
if (out.type === 'laser') {
|
||||||
current.isLaser = true;
|
current.isLaser = true;
|
||||||
|
|
@ -213,17 +212,17 @@ async function path(levels, update, opts = {}) {
|
||||||
if (!lastOut.emit || out.emit !== lastOut.emit) {
|
if (!lastOut.emit || out.emit !== lastOut.emit) {
|
||||||
// off to on or different power
|
// off to on or different power
|
||||||
currentLaser = newPolygon().setOpen();
|
currentLaser = newPolygon().setOpen();
|
||||||
currentLaser.push(lastOut.point);
|
currentLaser.push(lastOutPoint);
|
||||||
currentLaser.color = rate_to_color(out.emit, 1);
|
currentLaser.color = rate_to_color(out.emit, 1);
|
||||||
lasers.push(currentLaser);
|
lasers.push(currentLaser);
|
||||||
}
|
}
|
||||||
currentLaser.push(out.point);
|
currentLaser.push(outPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastEnd = null;
|
lastEnd = null;
|
||||||
} else {
|
} else {
|
||||||
current = newPolygon().setOpen();
|
current = newPolygon().setOpen();
|
||||||
current.push(out.point);
|
current.push(outPoint);
|
||||||
if (out.emit) {
|
if (out.emit) {
|
||||||
current.color = color(out);
|
current.color = color(out);
|
||||||
pushPrint(out.tool, current);
|
pushPrint(out.tool, current);
|
||||||
|
|
@ -232,6 +231,7 @@ async function path(levels, update, opts = {}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastOut = out;
|
lastOut = out;
|
||||||
|
lastOutPoint = outPoint;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!lastOut) {
|
if (!lastOut) {
|
||||||
|
|
|
||||||
|
|
@ -276,6 +276,7 @@ class Widget {
|
||||||
return new base.Mesh({precision, vertices: this.getVertices().array});
|
return new base.Mesh({precision, vertices: this.getVertices().array});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// should go away and be replaced by getGeoVertices
|
||||||
getVertices() {
|
getVertices() {
|
||||||
return this.mesh.geometry.attributes.position;
|
return this.mesh.geometry.attributes.position;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue