fix first cut depth in cnc, trace poly render, comments, z cut height on cnc flats
This commit is contained in:
parent
9fcc9e60c1
commit
0625ee04ef
3 changed files with 64 additions and 54 deletions
|
|
@ -134,25 +134,24 @@ let gs_kiri_layer = exports;
|
||||||
this.changed = true;
|
this.changed = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
LP.noodle = function(poly, offset, color, traceColor) {
|
LP.noodle = function(poly, offset, color, traceColor, open) {
|
||||||
let layer = this;
|
|
||||||
if (Array.isArray(poly)) {
|
if (Array.isArray(poly)) {
|
||||||
poly = POLY.flatten(poly, [], true);
|
poly = POLY.flatten(poly, [], true);
|
||||||
} else {
|
} else {
|
||||||
poly = POLY.flatten([poly], [], true);
|
poly = POLY.flatten([poly], [], true);
|
||||||
}
|
}
|
||||||
if (!poly.length) return;
|
if (!poly.length) return;
|
||||||
poly = poly.map(p => p.clone());
|
|
||||||
let exp = [];
|
|
||||||
let z = poly[0].getZ();
|
let z = poly[0].getZ();
|
||||||
poly.forEach(p => {
|
poly.forEach(p => {
|
||||||
POLY.expand([p], offset, z, exp, 1);
|
let exp = [];
|
||||||
POLY.expand([p], -offset, z, exp, 1);
|
POLY.expand([p], offset, z-0.01, exp, 1);
|
||||||
|
POLY.expand([p], -offset, z-0.01, exp, 1);
|
||||||
|
POLY.nest(exp).forEach((p,i) => {
|
||||||
|
this.add(color, {solid: p});
|
||||||
|
p = p.clone(true).setZ(z + 0.01);
|
||||||
|
this.add(traceColor, {poly: p, deep: true, open});
|
||||||
|
});
|
||||||
})
|
})
|
||||||
POLY.nest(exp).forEach((p,i) => {
|
|
||||||
this.add(color, {solid: p});
|
|
||||||
this.add(traceColor, {poly: p, deep: true, open: false});
|
|
||||||
});
|
|
||||||
this.changed = true;
|
this.changed = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -577,8 +577,7 @@ let gs_kiri_slice = exports;
|
||||||
if (top.traces) {
|
if (top.traces) {
|
||||||
layer.poly(top.traces, trace_color, true, null);
|
layer.poly(top.traces, trace_color, true, null);
|
||||||
// layer.setTransparent(false);
|
// layer.setTransparent(false);
|
||||||
// layer.setOpacity(0.5);
|
// layer.noodle(top.traces, 0.19, 0x88aadd, 0x77bbcc);
|
||||||
// layer.noodle(top.traces, 0.19, 0x88aadd, 0x0);
|
|
||||||
}
|
}
|
||||||
if (top.polish) {
|
if (top.polish) {
|
||||||
layer.poly(top.polish.x, 0x880000, true, null);
|
layer.poly(top.polish.x, 0x880000, true, null);
|
||||||
|
|
@ -652,14 +651,17 @@ let gs_kiri_slice = exports;
|
||||||
render;
|
render;
|
||||||
|
|
||||||
layer.clear();
|
layer.clear();
|
||||||
|
// layer.setTransparent(false);
|
||||||
|
|
||||||
this.tops.forEach(function(top) {
|
this.tops.forEach(function(top) {
|
||||||
if (top.fill_lines) {
|
if (top.fill_lines) {
|
||||||
layer.lines(top.fill_lines, fill_color);
|
layer.lines(top.fill_lines, fill_color);
|
||||||
|
// layer.noodle(top.fill_lines, 0.19, 0x88aadd, 0x77bbcc, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
layer.render();
|
layer.render();
|
||||||
|
// layer.renderSolid();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ let gs_kiri_slicer = exports;
|
||||||
let topoMode = options.topo,
|
let topoMode = options.topo,
|
||||||
simpleMode = options.simple,
|
simpleMode = options.simple,
|
||||||
swap = options.swapX || options.swapY,
|
swap = options.swapX || options.swapY,
|
||||||
|
isCam = options.cam,
|
||||||
ox = 0,
|
ox = 0,
|
||||||
oy = 0;
|
oy = 0;
|
||||||
|
|
||||||
|
|
@ -110,10 +111,10 @@ let gs_kiri_slicer = exports;
|
||||||
zOff = true ? zInc / 2 : 0,
|
zOff = true ? zInc / 2 : 0,
|
||||||
zHeights = [], // heights for zIndexes in adaptive mode
|
zHeights = [], // heights for zIndexes in adaptive mode
|
||||||
zIndexes = [], // auto-detected z slicing offsets (laser/cam)
|
zIndexes = [], // auto-detected z slicing offsets (laser/cam)
|
||||||
zOrdered = [], // ordered list of Z vertices
|
zOrdered = [], // ordered list of Z indexes
|
||||||
zList = {}, // list of z indices for auto slicing (laser)
|
zList = {}, // map count of z index points for adaptive slicing
|
||||||
zFlat = {}, // area of z offset flat areas (cam)
|
zFlat = {}, // map area of z index flat areas (cam)
|
||||||
zLines = {}, // count of lines flat on a z index
|
zLines = {}, // map count of z index lines
|
||||||
zScale, // bucket span in z units
|
zScale, // bucket span in z units
|
||||||
timeStart = time(),
|
timeStart = time(),
|
||||||
slices = [],
|
slices = [],
|
||||||
|
|
@ -143,39 +144,38 @@ let gs_kiri_slicer = exports;
|
||||||
countZ(p2.z);
|
countZ(p2.z);
|
||||||
countZ(p3.z);
|
countZ(p3.z);
|
||||||
}
|
}
|
||||||
if (true || options.cam) {
|
// use co-flat and co-line detection to adjust slice Z
|
||||||
if (p1.z === p2.z && p2.z === p3.z && p1.z > bounds.min.z) {
|
if (p1.z === p2.z && p2.z === p3.z && p1.z > bounds.min.z) {
|
||||||
// auto-detect flats for cam faces and to avoid slicing directly on flats
|
// detect zFlat faces to avoid slicing directly on them
|
||||||
let zkey = p1.z.toFixed(5),
|
let zkey = p1.z.toFixed(5),
|
||||||
area = Math.abs(UTIL.area2(p1,p2,p3)) / 2;
|
area = Math.abs(UTIL.area2(p1,p2,p3)) / 2;
|
||||||
if (!zFlat[zkey]) {
|
if (!zFlat[zkey]) {
|
||||||
zFlat[zkey] = area;
|
zFlat[zkey] = area;
|
||||||
} else {
|
} else {
|
||||||
zFlat[zkey] += area;
|
zFlat[zkey] += area;
|
||||||
}
|
}
|
||||||
} else if (true || options.trace) {
|
} else if (true || options.trace) {
|
||||||
// detect zLines (curved region tops/bottoms)
|
// detect zLines (curved region tops/bottoms)
|
||||||
// mark these layers for ball mills only
|
// mark these layers for ball and v mill tracing
|
||||||
if (p1.z === p2.z && p1.z > bounds.min.z) {
|
if (p1.z === p2.z && p1.z > bounds.min.z) {
|
||||||
let zkey = p1.z.toFixed(5);
|
let zkey = p1.z.toFixed(5);
|
||||||
let zval = zLines[zkey];
|
let zval = zLines[zkey];
|
||||||
zLines[zkey] = (zval || 0) + 1;
|
zLines[zkey] = (zval || 0) + 1;
|
||||||
}
|
}
|
||||||
if (p2.z === p3.z && p2.z > bounds.min.z) {
|
if (p2.z === p3.z && p2.z > bounds.min.z) {
|
||||||
let zkey = p2.z.toFixed(5);
|
let zkey = p2.z.toFixed(5);
|
||||||
let zval = zLines[zkey];
|
let zval = zLines[zkey];
|
||||||
zLines[zkey] = (zval || 0) + 1;
|
zLines[zkey] = (zval || 0) + 1;
|
||||||
}
|
}
|
||||||
if (p3.z === p1.z && p3.z > bounds.min.z) {
|
if (p3.z === p1.z && p3.z > bounds.min.z) {
|
||||||
let zkey = p3.z.toFixed(5);
|
let zkey = p3.z.toFixed(5);
|
||||||
let zval = zLines[zkey];
|
let zval = zLines[zkey];
|
||||||
zLines[zkey] = (zval || 0) + 1;
|
zLines[zkey] = (zval || 0) + 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// find slice candidates to trace for ballmills and tapermills
|
// CAM: find slice candidates to trace for ballmills and tapermills
|
||||||
if (options.trace) {
|
if (options.trace) {
|
||||||
let zl = {};
|
let zl = {};
|
||||||
let le;
|
let le;
|
||||||
|
|
@ -199,7 +199,10 @@ let gs_kiri_slicer = exports;
|
||||||
zLines = zl;
|
zLines = zl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** bucket polygons into z-bounded groups */
|
/**
|
||||||
|
* bucket polygons into z-bounded groups (inside or crossing)
|
||||||
|
* to reduce the search space in complex models
|
||||||
|
*/
|
||||||
let bucketCount = Math.max(1, Math.ceil(zMax / (zSum / points.length)) - 1);
|
let bucketCount = Math.max(1, Math.ceil(zMax / (zSum / points.length)) - 1);
|
||||||
|
|
||||||
zScale = 1 / (zMax / bucketCount);
|
zScale = 1 / (zMax / bucketCount);
|
||||||
|
|
@ -244,7 +247,7 @@ let gs_kiri_slicer = exports;
|
||||||
for (i = 0; i < zl.length - 1; i++) {
|
for (i = 0; i < zl.length - 1; i++) {
|
||||||
zIndexes.push((zl[i] + zl[i+1]) / 2);
|
zIndexes.push((zl[i] + zl[i+1]) / 2);
|
||||||
}
|
}
|
||||||
} else if (options.cam) {
|
} else if (isCam) {
|
||||||
// re-divide slice height so that top and
|
// re-divide slice height so that top and
|
||||||
// bottom slices fall exactly on those faces
|
// bottom slices fall exactly on those faces
|
||||||
zInc = (zMax - zMin) / (Math.floor(zMax / zInc) + 1);
|
zInc = (zMax - zMin) / (Math.floor(zMax / zInc) + 1);
|
||||||
|
|
@ -265,6 +268,8 @@ let gs_kiri_slicer = exports;
|
||||||
zIndexes.sort(function(a,b) {
|
zIndexes.sort(function(a,b) {
|
||||||
return b-a;
|
return b-a;
|
||||||
});
|
});
|
||||||
|
// copy to store original z
|
||||||
|
zHeights = zIndexes.slice();
|
||||||
} else if (zIncMin) {
|
} else if (zIncMin) {
|
||||||
// FDM adaptive slicing
|
// FDM adaptive slicing
|
||||||
let zPos = zMin + zIncFirst,
|
let zPos = zMin + zIncFirst,
|
||||||
|
|
@ -317,7 +322,6 @@ let gs_kiri_slicer = exports;
|
||||||
zHeights.push(zInc);
|
zHeights.push(zInc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a Slice for each z offset in the zIndexes array
|
// create a Slice for each z offset in the zIndexes array
|
||||||
for (let i = 0; i < zIndexes.length; i++) {
|
for (let i = 0; i < zIndexes.length; i++) {
|
||||||
let ik = zIndexes[i].toFixed(5),
|
let ik = zIndexes[i].toFixed(5),
|
||||||
|
|
@ -327,16 +331,20 @@ let gs_kiri_slicer = exports;
|
||||||
if (zFlat[ik]) onFlat = true;
|
if (zFlat[ik]) onFlat = true;
|
||||||
if (zLines[ik]) onLine = true;
|
if (zLines[ik]) onLine = true;
|
||||||
if (onFlat || onLine) {
|
if (onFlat || onLine) {
|
||||||
zIndexes[i] += options.cam ? 0.001 : -0.001;
|
zIndexes[i] += isCam ? 0.001 : -0.001;
|
||||||
}
|
}
|
||||||
// slice next layer and add to slices[] array
|
// slice next layer and add to slices[] array
|
||||||
sliceZ(zIndexes[i], zHeights[i], onFlat, onLine);
|
let slice = sliceZ(zIndexes[i], zHeights[i], onFlat, onLine);
|
||||||
|
// override z in cam in case it was moved for a flat or line
|
||||||
|
if (isCam && slice) {
|
||||||
|
slice.z = zHeights[i];
|
||||||
|
}
|
||||||
onupdate(i / zIndexes.length);
|
onupdate(i / zIndexes.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// for cam, mark top and bottom as mandatory (hasFlats)
|
// for cam, bottom as mandatory (hasFlats)
|
||||||
if (options.cam && slices.length > 0) {
|
if (isCam && slices.length > 0) {
|
||||||
slices[0].hasFlats = true;
|
// slices[0].hasFlats = true;
|
||||||
slices[slices.length-1].hasFlats = true;
|
slices[slices.length-1].hasFlats = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -442,7 +450,7 @@ let gs_kiri_slicer = exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
// annotate slices with cam flats for finishing waterlines
|
// annotate slices with cam flats for finishing waterlines
|
||||||
if (onflat && options.cam) {
|
if (onflat && isCam) {
|
||||||
slice.hasFlats = true;
|
slice.hasFlats = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -529,6 +537,7 @@ let gs_kiri_slicer = exports;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
slices.push(slice);
|
slices.push(slice);
|
||||||
|
return slice;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue