add trace re-contouring when poly z varies, offset present, no step down
This commit is contained in:
parent
c6c5a8cd9f
commit
82e2742b8d
4 changed files with 41 additions and 20 deletions
|
|
@ -82,7 +82,6 @@ kiri.load(api => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
CAM.holes = function(indiv,rec,onProgress,onDone) {
|
CAM.holes = function(indiv,rec,onProgress,onDone) {
|
||||||
kiri.client.sync();
|
kiri.client.sync();
|
||||||
const settings = api.conf.get();
|
const settings = api.conf.get();
|
||||||
|
|
@ -93,13 +92,13 @@ kiri.load(api => {
|
||||||
//if a progress message,
|
//if a progress message,
|
||||||
onProgress(out.progress,out.msg)
|
onProgress(out.progress,out.msg)
|
||||||
}else{
|
}else{
|
||||||
api.hide.alert(alert)
|
api.hide.alert(alert);
|
||||||
onDone(out)
|
onDone(out);
|
||||||
res(out)
|
res(out);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kiri.worker) {
|
if (kiri.worker) {
|
||||||
|
|
|
||||||
|
|
@ -995,6 +995,8 @@ class OpTrace extends CamOp {
|
||||||
let traceOffset = camTool.traceOffset()
|
let traceOffset = camTool.traceOffset()
|
||||||
let cutdir = ov_conv;
|
let cutdir = ov_conv;
|
||||||
let polys = [];
|
let polys = [];
|
||||||
|
let reContour = false;
|
||||||
|
let canRecontour = offset !== 'none' && down === 0;
|
||||||
let stockRect = stock.center && stock.x && stock.y ?
|
let stockRect = stock.center && stock.x && stock.y ?
|
||||||
newPolygon().centerRectangle({x:0,y:0}, stock.x, stock.y) : undefined;
|
newPolygon().centerRectangle({x:0,y:0}, stock.x, stock.y) : undefined;
|
||||||
updateToolDiams(toolDiam);
|
updateToolDiams(toolDiam);
|
||||||
|
|
@ -1008,6 +1010,12 @@ class OpTrace extends CamOp {
|
||||||
let poly = newPolygon().fromArray(arr);
|
let poly = newPolygon().fromArray(arr);
|
||||||
POLY.setWinding([ poly ], cutdir, false);
|
POLY.setWinding([ poly ], cutdir, false);
|
||||||
polys.push(poly);
|
polys.push(poly);
|
||||||
|
let zs = poly.points.map(p => p.z);
|
||||||
|
let min = Math.min(...zs);
|
||||||
|
let max = Math.max(...zs);
|
||||||
|
if (max - min > 0.0001 && canRecontour) {
|
||||||
|
reContour = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (false) newSliceOut(0).output()
|
if (false) newSliceOut(0).output()
|
||||||
.setLayer("polys", {line: 0xaaaa00}, false)
|
.setLayer("polys", {line: 0xaaaa00}, false)
|
||||||
|
|
@ -1036,6 +1044,9 @@ class OpTrace extends CamOp {
|
||||||
if (camStockClipTo && stockRect) {
|
if (camStockClipTo && stockRect) {
|
||||||
slice.camLines = cutPolys([stockRect], slice.camLines, z, true);
|
slice.camLines = cutPolys([stockRect], slice.camLines, z, true);
|
||||||
}
|
}
|
||||||
|
if (reContour) {
|
||||||
|
state.contourPolys(widget, slice.camLines);
|
||||||
|
}
|
||||||
slice.output()
|
slice.output()
|
||||||
.setLayer("trace follow", {line: color}, false)
|
.setLayer("trace follow", {line: color}, false)
|
||||||
.addPolys(slice.camLines)
|
.addPolys(slice.camLines)
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,7 @@ CAM.slice = async function(settings, widget, onupdate, ondone) {
|
||||||
tabs,
|
tabs,
|
||||||
cutTabs,
|
cutTabs,
|
||||||
cutPolys,
|
cutPolys,
|
||||||
|
contourPolys,
|
||||||
healPolys,
|
healPolys,
|
||||||
shadowAt,
|
shadowAt,
|
||||||
slicer,
|
slicer,
|
||||||
|
|
@ -365,8 +366,6 @@ CAM.slice = async function(settings, widget, onupdate, ondone) {
|
||||||
ondone();
|
ondone();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CAM.addDogbones = function(poly, dist, reverse) {
|
CAM.addDogbones = function(poly, dist, reverse) {
|
||||||
if (Array.isArray(poly)) {
|
if (Array.isArray(poly)) {
|
||||||
return poly.forEach(p => CAM.addDogbones(p, dist));
|
return poly.forEach(p => CAM.addDogbones(p, dist));
|
||||||
|
|
@ -512,16 +511,16 @@ CAM.traces = async function(settings, widget, single) {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a list of holes in the model based on the given diameter.
|
* Generate a list of holes in the model based on the given diameter.
|
||||||
*
|
*
|
||||||
* @param {Object} settings - settings object
|
* @param {Object} settings - settings object
|
||||||
* @param {Object} widget - widget object
|
* @param {Object} widget - widget object
|
||||||
* @param {boolean} individual - if true, drill holes individually
|
* @param {boolean} individual - if true, drill holes individually
|
||||||
* @param {Object} rec - DrillOp record
|
* @param {Object} rec - DrillOp record
|
||||||
* @param {Function} onProgress - callback function to report progress
|
* @param {Function} onProgress - callback function to report progress
|
||||||
* @returns {Array} list of hole centers as objects with `x`, `y`, `z`, `depth`, and `selected` properties.
|
* @returns {Array} list of hole centers as objects with `x`, `y`, `z`, `depth`, and `selected` properties.
|
||||||
*/
|
*/
|
||||||
CAM.holes = async function(settings, widget, individual, rec,onProgress) {
|
CAM.holes = async function(settings, widget, individual, rec,onProgress) {
|
||||||
|
|
||||||
let {tool,mark,precision} = rec //TODO: display some visual difference if mark is selected
|
let {tool,mark,precision} = rec //TODO: display some visual difference if mark is selected
|
||||||
|
|
@ -603,7 +602,6 @@ CAM.holes = async function(settings, widget, individual, rec,onProgress) {
|
||||||
|
|
||||||
// //if on the same xy point,
|
// //if on the same xy point,
|
||||||
if (dist <= centerDiff ) {
|
if (dist <= centerDiff ) {
|
||||||
|
|
||||||
// console.log("overlap",center,circle);
|
// console.log("overlap",center,circle);
|
||||||
circle.overlapping.push(center);
|
circle.overlapping.push(center);
|
||||||
// if overlapping, don't add and continue
|
// if overlapping, don't add and continue
|
||||||
|
|
@ -669,6 +667,19 @@ function cutPolys(polys, offset, z, inter) {
|
||||||
return healPolys(noff);
|
return healPolys(noff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function contourPolys(widget, polys) {
|
||||||
|
const raycaster = new THREE.Raycaster();
|
||||||
|
raycaster.ray.direction.set(0, 0, -1); // ray pointing down Z
|
||||||
|
for (let poly of polys) {
|
||||||
|
for (let point of poly.points) {
|
||||||
|
raycaster.ray.origin.set(point.x, point.y, 10000);
|
||||||
|
const intersects = raycaster.intersectObject(widget.mesh, true);
|
||||||
|
const firstHit = intersects[0] || null;
|
||||||
|
point.z = firstHit.point.z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function healPolys(noff) {
|
function healPolys(noff) {
|
||||||
if (noff.length > 1) {
|
if (noff.length > 1) {
|
||||||
let heal = 0;
|
let heal = 0;
|
||||||
|
|
|
||||||
|
|
@ -493,7 +493,7 @@ const conf = exports({
|
||||||
camTracePlunge: 200,
|
camTracePlunge: 200,
|
||||||
camTraceOffOver: 0,
|
camTraceOffOver: 0,
|
||||||
camTraceDogbone: false,
|
camTraceDogbone: false,
|
||||||
camTraceMerge: true,
|
camTraceMerge: false,
|
||||||
camTraceLines: false,
|
camTraceLines: false,
|
||||||
camTraceZTop: 0,
|
camTraceZTop: 0,
|
||||||
camTraceZBottom: 0,
|
camTraceZBottom: 0,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue