better linear XY finishing near part through and edges. cleaner code

This commit is contained in:
Stewart Allen 2020-03-26 21:29:40 -04:00
commit 1def9e0dc9

View file

@ -184,20 +184,15 @@ var gs_kiri_cam = exports;
let tx = profile[i++] + x; let tx = profile[i++] + x;
let ty = profile[i++] + y; let ty = profile[i++] + y;
let tz = profile[i++]; let tz = profile[i++];
// if outside max topo steps, skip
if (tx < 0 || tx >= sx || ty < 0 || ty >= sy) { if (tx < 0 || tx >= sx || ty < 0 || ty >= sy) {
continue; // if outside max topo steps, use 0
} gv = 0;
// lookup grid value @ tx, ty } else {
gv = topo.data[tx * sy + ty]; // lookup grid value @ tx, ty
// outside the topo gv = topo.data[tx * sy + ty] || 0;
if (gv === undefined) {
console.log("outside");
continue;
} }
// inside the topo but off the part // inside the topo but off the part
if (floormax && gv === 0) { if (floormax && gv === 0) {
// console.log("off topo");
// return topo.bounds.max.z; // return topo.bounds.max.z;
gv = topo.bounds.max.z; gv = topo.bounds.max.z;
} }
@ -205,7 +200,7 @@ var gs_kiri_cam = exports;
mz = Math.max(tz + gv, mz); mz = Math.max(tz + gv, mz);
} }
return Math.max(mz,0);//mz >= 0.0 ? mz : topo.bounds.max.z; return Math.max(mz,0);
}; };
/** /**
@ -342,8 +337,12 @@ var gs_kiri_cam = exports;
toolStep = diameter * proc.finishingOver, toolStep = diameter * proc.finishingOver,
traceJoin = diameter / 2, traceJoin = diameter / 2,
bounds = widget.getBoundingBox().clone(), bounds = widget.getBoundingBox().clone(),
boundsX = bounds.max.x - bounds.min.x, minX = bounds.min.x,// - diameter,
boundsY = bounds.max.y - bounds.min.y, maxX = bounds.max.x,// + diameter,
minY = bounds.min.y,// - diameter,
maxY = bounds.max.y,// + diameter,
boundsX = maxX - minX,
boundsY = maxY - minY,
maxangle = proc.finishingAngle, maxangle = proc.finishingAngle,
curvesOnly = proc.finishCurvesOnly, curvesOnly = proc.finishCurvesOnly,
R2A = 180 / Math.PI, R2A = 180 / Math.PI,
@ -366,7 +365,7 @@ var gs_kiri_cam = exports;
sliceout, sliceout,
latent, latent,
lastP, lastP,
slice, lx, ly, lv, slice, lx, ly,
startTime = time(); startTime = time();
// return highest z within tools radius // return highest z within tools radius
@ -412,8 +411,6 @@ var gs_kiri_cam = exports;
gridy, gridy,
gridi, // index gridi, // index
gridv, // value gridv, // value
miny = bounds.min.y,
maxy = bounds.max.y,
zMin = MAX(bounds.min.z, outp.camZBottom) + 0.0001, zMin = MAX(bounds.min.z, outp.camZBottom) + 0.0001,
x, y, tv, ltv; x, y, tv, ltv;
@ -423,7 +420,7 @@ var gs_kiri_cam = exports;
lines = slice.lines; lines = slice.lines;
gridy = 0; gridy = 0;
// slices have x/z swapped // slices have x/z swapped
for (y = miny; y <= maxy; y += resolution) { for (y = minY; y <= maxY; y += resolution) {
gridi = gridx * stepsy + gridy; gridi = gridx * stepsy + gridy;
gridv = data[gridi] || 0; gridv = data[gridi] || 0;
// strategy using raw lines (faster slice, but more lines) // strategy using raw lines (faster slice, but more lines)
@ -455,8 +452,8 @@ var gs_kiri_cam = exports;
if (proc.finishingXOn) { if (proc.finishingXOn) {
startTime = time(); startTime = time();
// emit slice per X // emit slice per X
gridx = 0; for (x = minX; x <= maxX; x += toolStep) {
for (x = bounds.min.x; x <= bounds.max.x; x += toolStep) { gridx = Math.round(((x - minX) / boundsX) * stepsx);
ly = gridy = 0; ly = gridy = 0;
slice = newSlice(gridx, mesh.newGroup ? mesh.newGroup() : null); slice = newSlice(gridx, mesh.newGroup ? mesh.newGroup() : null);
slice.camMode = CPRO.FINISH_X; slice.camMode = CPRO.FINISH_X;
@ -464,25 +461,19 @@ var gs_kiri_cam = exports;
newtop = slice.addTop(newPolygon().setOpen()).poly; newtop = slice.addTop(newPolygon().setOpen()).poly;
newtrace = newPolygon().setOpen(); newtrace = newPolygon().setOpen();
sliceout = slice.tops[0].traces = [ ]; sliceout = slice.tops[0].traces = [ ];
for (y = bounds.min.y; y < bounds.max.y; y += resolution) { for (y = minY; y < maxY; y += resolution) {
gridv = data[gridx * stepsy + gridy]; tv = maxzat(gridx, gridy);
if (gridv === undefined) { if (tv === 0) {
// off topo
gridy++;
continue;
}
if (!curvesOnly && gridv === 0) {
// off part // off part
end_poly(); end_poly();
gridy++; gridy++;
ly = 0; ly = 0;
continue; continue;
} }
tv = maxzat(gridx, gridy);
if (ly) { if (ly) {
if (mesh) newlines.push(newLine( if (mesh) newlines.push(newLine(
newPoint(x,ly,lv), newPoint(x,ly,ltv),
newPoint(x,y,gridv) newPoint(x,y,tv)
)); ));
let ang = Math.abs((Math.atan2(ltv - tv, resolution) * R2A) % 90); let ang = Math.abs((Math.atan2(ltv - tv, resolution) * R2A) % 90);
// over max angle, turn into square edge (up or down) // over max angle, turn into square edge (up or down)
@ -498,7 +489,6 @@ var gs_kiri_cam = exports;
} }
push_point(x,y,tv); push_point(x,y,tv);
ly = y; ly = y;
lv = gridv;
ltv = tv; ltv = tv;
gridy++; gridy++;
} }
@ -506,7 +496,6 @@ var gs_kiri_cam = exports;
if (sliceout.length > 0) { if (sliceout.length > 0) {
newslices.push(slice); newslices.push(slice);
} }
gridx = Math.round(((x - bounds.min.x + toolStep) / boundsX) * stepsx);
onupdate(0.70 + (gridx/stepsx) * 0.15, "linear x"); onupdate(0.70 + (gridx/stepsx) * 0.15, "linear x");
} }
} }
@ -515,8 +504,8 @@ var gs_kiri_cam = exports;
if (proc.finishingYOn) { if (proc.finishingYOn) {
startTime = time(); startTime = time();
// emit slice per Y // emit slice per Y
gridy = 0; for (y = minY; y < maxY; y += toolStep) {
for (y = bounds.min.y; y < bounds.max.y; y += toolStep) { gridy = Math.round(((y - minY) / boundsY) * stepsy);
lx = gridx = 0; lx = gridx = 0;
slice = newSlice(gridy, mesh.newGroup ? mesh.newGroup() : null); slice = newSlice(gridy, mesh.newGroup ? mesh.newGroup() : null);
slice.camMode = CPRO.FINISH_Y; slice.camMode = CPRO.FINISH_Y;
@ -524,25 +513,19 @@ var gs_kiri_cam = exports;
newtop = slice.addTop(newPolygon().setOpen()).poly; newtop = slice.addTop(newPolygon().setOpen()).poly;
newtrace = newPolygon().setOpen(); newtrace = newPolygon().setOpen();
sliceout = slice.tops[0].traces = [ ]; sliceout = slice.tops[0].traces = [ ];
for (x = bounds.min.x; x <= bounds.max.x; x += resolution) { for (x = minX; x <= maxX; x += resolution) {
gridv = data[gridx * stepsy + gridy]; tv = maxzat(gridx, gridy);
if (gridv === undefined) { if (tv === 0) {
// off topo
gridx++;
continue;
}
if (!curvesOnly && gridv === 0) {
// off part // off part
end_poly(); end_poly();
gridx++; gridx++;
lx = 0; lx = 0;
continue; continue;
} }
tv = maxzat(gridx, gridy);
if (lx) { if (lx) {
if (mesh) newlines.push(newLine( if (mesh) newlines.push(newLine(
newPoint(lx,y,lv), newPoint(lx,y,ltv),
newPoint(x,y,gridv) newPoint(x,y,tv)
)); ));
let ang = Math.abs((Math.atan2(ltv - tv, resolution) * R2A) % 90); let ang = Math.abs((Math.atan2(ltv - tv, resolution) * R2A) % 90);
// over max angle, turn into square edge (up or down) // over max angle, turn into square edge (up or down)
@ -558,7 +541,6 @@ var gs_kiri_cam = exports;
} }
push_point(x,y,tv); push_point(x,y,tv);
lx = x; lx = x;
lv = gridv;
ltv = tv; ltv = tv;
gridx++; gridx++;
} }
@ -566,7 +548,6 @@ var gs_kiri_cam = exports;
if (sliceout.length > 0) { if (sliceout.length > 0) {
newslices.push(slice); newslices.push(slice);
} }
gridy = Math.round(((y - bounds.min.y + toolStep) / boundsY) * stepsy);
onupdate(0.85 + (gridy/stepsy) * 0.15, "linear y"); onupdate(0.85 + (gridy/stepsy) * 0.15, "linear y");
} }
} }