add ease-down support
This commit is contained in:
parent
6f96e6c07a
commit
28765d8db0
1 changed files with 58 additions and 46 deletions
|
|
@ -325,7 +325,6 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
||||||
* @param {number} opts.factor speed scale factor
|
* @param {number} opts.factor speed scale factor
|
||||||
*/
|
*/
|
||||||
function camOut(point, cut,opts) {
|
function camOut(point, cut,opts) {
|
||||||
console.trace({camOut: point, cut, opts})
|
|
||||||
let {
|
let {
|
||||||
center = {},
|
center = {},
|
||||||
clockwise = true,
|
clockwise = true,
|
||||||
|
|
@ -463,10 +462,11 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
||||||
modifier = threshold / absDeltaZ;
|
modifier = threshold / absDeltaZ;
|
||||||
if (synthPlunge && threshold && modifier && deltaXY > tolerance) {
|
if (synthPlunge && threshold && modifier && deltaXY > tolerance) {
|
||||||
// use modifier to speed up long XY move plunge rates
|
// use modifier to speed up long XY move plunge rates
|
||||||
|
console.log('modifier', modifier);
|
||||||
rate = Math.round(plungeRate + ((feedRate - plungeRate) * modifier));
|
rate = Math.round(plungeRate + ((feedRate - plungeRate) * modifier));
|
||||||
cut = 1;
|
cut = 1;
|
||||||
} else {
|
} else {
|
||||||
rate = Math.min(feedRate, plungeRate);
|
rate = 1 / Math.hypot(deltaXY / feedRate , absDeltaZ / plungeRate );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -484,7 +484,6 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
||||||
arcPoints
|
arcPoints
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
console.log({center, arcPoints});
|
|
||||||
}else{
|
}else{
|
||||||
// for g1 moves
|
// for g1 moves
|
||||||
|
|
||||||
|
|
@ -727,17 +726,60 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
||||||
* @returns {Point} - the last point of the polygon
|
* @returns {Point} - the last point of the polygon
|
||||||
*/
|
*/
|
||||||
function polyEmit(poly, index, count, fromPoint) {
|
function polyEmit(poly, index, count, fromPoint) {
|
||||||
console.log('polyEmit', poly );
|
|
||||||
const arcDist = 0.001, // minimum dist for arc
|
const arcDist = 0.001, // minimum dist for arc
|
||||||
arcRes = 8, //8 degs max
|
arcRes = 8, //8 degs max
|
||||||
arcMax = Infinity; // no max arc radius
|
arcMax = Infinity; // no max arc radius
|
||||||
|
|
||||||
fromPoint = fromPoint || printPoint;
|
fromPoint = fromPoint || printPoint;
|
||||||
|
|
||||||
// console.log('polyEmit', poly, index, count);
|
console.log('polyEmit', poly, index, count);
|
||||||
|
|
||||||
let arcQ = [];
|
let arcQ = [];
|
||||||
|
|
||||||
|
let closest = poly.findClosestPointTo(fromPoint);
|
||||||
|
let lastPoint = closest.point;
|
||||||
|
let startIndex = closest.index;
|
||||||
|
|
||||||
|
// scale speed of first cutting poly since it engages the full bit
|
||||||
|
let scale = ((isRough || isPocket) && count === 1) ? engageFactor : 1;
|
||||||
|
|
||||||
|
|
||||||
|
if (easeDown && poly.isClosed()) { //if doing ease-down
|
||||||
|
|
||||||
|
let last = generateEaseDown((point,offset )=>{ //generate ease-down points
|
||||||
|
if(offset == 0) camOut(point.clone(), 0, {factor:scale});
|
||||||
|
camOut(point.clone(), 1, {factor:scale}); // and pass them to camOut
|
||||||
|
}, poly, fromPoint, easeAngle);
|
||||||
|
lastPoint = poly.points[last];
|
||||||
|
startIndex = last;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
poly.forEachPoint( ( point, pidx, points, offset) => {
|
||||||
|
// if(offset == 0) console.log("forEachPoint",point,pidx,points)
|
||||||
|
if(offset == 0){
|
||||||
|
// if first point, move to and call export function
|
||||||
|
console.log("offset 0")
|
||||||
|
camOut(point.clone(), 0, {factor:scale});
|
||||||
|
quePush(point);
|
||||||
|
}
|
||||||
|
else arcExport(point, lastPoint);
|
||||||
|
lastPoint = point;
|
||||||
|
}, poly.isClosed(), startIndex);
|
||||||
|
|
||||||
|
// console.log("at end of arcExport",structuredClone(arcQ));
|
||||||
|
if(arcQ.length > 3){
|
||||||
|
//if few points left, emit as lines
|
||||||
|
drainQ();
|
||||||
|
}
|
||||||
|
while (arcQ.length){
|
||||||
|
camOut(arcQ.shift(),1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function quePush(point){
|
||||||
|
arcQ.push(point);
|
||||||
|
}
|
||||||
|
|
||||||
function arcExport(point,lastp){
|
function arcExport(point,lastp){
|
||||||
// console.log("start",point,lastp)
|
// console.log("start",point,lastp)
|
||||||
let dist = lastp? point.distTo2D(lastp) : 0;
|
let dist = lastp? point.distTo2D(lastp) : 0;
|
||||||
|
|
@ -772,6 +814,7 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
||||||
// }
|
// }
|
||||||
} else {
|
} else {
|
||||||
radFault = true;
|
radFault = true;
|
||||||
|
console.log("too much angle")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cc) {
|
if (cc) {
|
||||||
|
|
@ -796,7 +839,7 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
||||||
// if (deem || depm || desp || dc > arcDist || cc.r < arcMin || cc.r > arcMax || dist > cc.r) {
|
// if (deem || depm || desp || dc > arcDist || cc.r < arcMin || cc.r > arcMax || dist > cc.r) {
|
||||||
if ( desp || dc * arcQ.center.length / arcQ.rSum > arcDist || dist > cc.r || cc.r > arcMax || radFault ) {
|
if ( desp || dc * arcQ.center.length / arcQ.rSum > arcDist || dist > cc.r || cc.r > arcMax || radFault ) {
|
||||||
// let debug = [deem, depm, desp, dc * arcQ.center.length / arcQ.rSum > arcDist, dist > cc.r, cc.r > arcMax, radFault];
|
// let debug = [deem, depm, desp, dc * arcQ.center.length / arcQ.rSum > arcDist, dist > cc.r, cc.r > arcMax, radFault];
|
||||||
console.log("point off the arc,",structuredClone(arcQ),);
|
// console.log("point off the arc,",structuredClone(arcQ),);
|
||||||
if (arcQ.length === 4) {
|
if (arcQ.length === 4) {
|
||||||
// not enough points for an arc, drop first point and recalc center
|
// not enough points for an arc, drop first point and recalc center
|
||||||
camOut(arcQ.shift(),1);
|
camOut(arcQ.shift(),1);
|
||||||
|
|
@ -829,8 +872,8 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if dist to small, output as a cut
|
// if dist to small, output as a cut
|
||||||
console.log('point too small', point,lastp,dist);
|
console.trace('point too small', point,lastp,dist);
|
||||||
// camOut(point, 1);
|
camOut(point, 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if first point, emit and set
|
// if first point, emit and set
|
||||||
|
|
@ -861,7 +904,6 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
||||||
arcQ.ySum = arcQ.center.reduce( (t, v) => t + v.y , 0 );
|
arcQ.ySum = arcQ.center.reduce( (t, v) => t + v.y , 0 );
|
||||||
arcQ.rSum = arcQ.center.reduce( (t, v) => t + v.r , 0 );
|
arcQ.rSum = arcQ.center.reduce( (t, v) => t + v.r , 0 );
|
||||||
let cl = arcQ.center.length;
|
let cl = arcQ.center.length;
|
||||||
let radius = arcQ.rSum / cl;
|
|
||||||
let center = newPoint(
|
let center = newPoint(
|
||||||
arcQ.xSum / cl,
|
arcQ.xSum / cl,
|
||||||
arcQ.ySum / cl,
|
arcQ.ySum / cl,
|
||||||
|
|
@ -869,9 +911,9 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
||||||
|
|
||||||
if(arcQ.length == poly.points.length){
|
if(arcQ.length == poly.points.length){
|
||||||
//if is a circle
|
//if is a circle
|
||||||
let arcStart = arcQ[0]
|
camOut(from,1);
|
||||||
camOut(arcStart,1);
|
camOut(from,1,{ center:center.sub(from), clockwise, arcPoints:[...arcQ]});
|
||||||
camOut(arcStart,1,{ center:center.sub(from), clockwise, arcPoints:[...arcQ]});
|
lastPoint = from.clone();
|
||||||
}else{
|
}else{
|
||||||
//if a non-circle arc
|
//if a non-circle arc
|
||||||
|
|
||||||
|
|
@ -879,6 +921,7 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
||||||
camOut(from,1);
|
camOut(from,1);
|
||||||
// rest of arc to final point
|
// rest of arc to final point
|
||||||
camOut(to,1,{ center:center.sub(from), clockwise, arcPoints:[...arcQ]});
|
camOut(to,1,{ center:center.sub(from), clockwise, arcPoints:[...arcQ]});
|
||||||
|
lastPoint = to.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -886,48 +929,17 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
||||||
for (let rec of arcQ) {
|
for (let rec of arcQ) {
|
||||||
camOut(rec,1);
|
camOut(rec,1);
|
||||||
}
|
}
|
||||||
|
lastPoint = arcQ.peek().clone();
|
||||||
}
|
}
|
||||||
last = arcQ.peek();
|
|
||||||
arcQ.length = 0;
|
arcQ.length = 0;
|
||||||
arcQ.center = undefined;
|
arcQ.center = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let {point:lastPoint, index:startIdx} = poly.findClosestPointTo(fromPoint);
|
|
||||||
let last = index;
|
|
||||||
// scale speed of first cutting poly since it engages the full bit
|
|
||||||
let scale = ((isRough || isPocket) && count === 1) ? engageFactor : 1;
|
|
||||||
|
|
||||||
if (easeDown && poly.isClosed()) { //if doing ease-down
|
|
||||||
last = generateEaseDown((point, )=>{ //generate ease-down points
|
|
||||||
camOut(point.clone(), 1, {factor:scale}); // and pass them to camOut
|
|
||||||
}, poly, lastPoint, easeAngle);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
poly.forEachPoint( ( point, pidx, points, offset) => {
|
|
||||||
// if(offset == 0) console.log("forEachPoint",point,pidx,points)
|
|
||||||
if(offset ==0 ) arcExport(point,lastPoint);
|
|
||||||
else arcExport(point, lastPoint);
|
|
||||||
last = pidx;
|
|
||||||
lastPoint = point;
|
|
||||||
}, poly.isClosed(), startIdx);
|
|
||||||
|
|
||||||
// console.log("at end of arcExport",structuredClone(arcQ));
|
|
||||||
if(arcQ.length <= 3){
|
|
||||||
//if few points left, emit as lines
|
|
||||||
while (arcQ.length){
|
|
||||||
camOut(arcQ.shift(),1);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
console.log("force draining",structuredClone(arcQ));
|
|
||||||
drainQ();
|
|
||||||
console.log("after draining",structuredClone(arcQ));
|
|
||||||
// camOut(arcQ.shift(),1);
|
|
||||||
}
|
|
||||||
|
|
||||||
newLayer();
|
newLayer();
|
||||||
return last;
|
return lastPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
function depthRoughPath(start, depth, levels, tops, emitter, fit, ease) {
|
function depthRoughPath(start, depth, levels, tops, emitter, fit, ease) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue