avoid slicing directly on z flat faces
This commit is contained in:
parent
36f47bec58
commit
309ac1d813
3 changed files with 34 additions and 19 deletions
|
|
@ -115,6 +115,11 @@ var gs_kiri_slicer = exports;
|
||||||
i, j = 0, k, p1, p2, p3, px,
|
i, j = 0, k, p1, p2, p3, px,
|
||||||
CPRO = KIRI.driver.CAM.process;
|
CPRO = KIRI.driver.CAM.process;
|
||||||
|
|
||||||
|
function countZ(z) {
|
||||||
|
z = UTIL.round(z,5);
|
||||||
|
zList[z] = (zList[z] || 0) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
// gather z-index stats
|
// gather z-index stats
|
||||||
// these are used for auto-slicing in laser
|
// these are used for auto-slicing in laser
|
||||||
// and to flats detection in CAM mode
|
// and to flats detection in CAM mode
|
||||||
|
|
@ -125,14 +130,13 @@ var gs_kiri_slicer = exports;
|
||||||
zSum += (Math.abs(p1.z - p2.z) + Math.abs(p2.z - p3.z) + Math.abs(p3.z - p1.z));
|
zSum += (Math.abs(p1.z - p2.z) + Math.abs(p2.z - p3.z) + Math.abs(p3.z - p1.z));
|
||||||
// laser auto-detect z slice points
|
// laser auto-detect z slice points
|
||||||
if (zInc === 0) {
|
if (zInc === 0) {
|
||||||
zList[UTIL.round(p1.z,5)] = 1;
|
countZ(p1.z);
|
||||||
zList[UTIL.round(p2.z,5)] = 1;
|
countZ(p2.z);
|
||||||
zList[UTIL.round(p3.z,5)] = 1;
|
countZ(p3.z);
|
||||||
}
|
}
|
||||||
// cam auto-detect flats
|
// auto-detect flats for cam faces and to avoid slicing directly on flats
|
||||||
if (options.cam) {
|
|
||||||
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) {
|
||||||
var zkey = p1.z < bounds.max.z ? p1.z + 0.001 : p1.z,
|
var zkey = UTIL.round(p1.z, 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;
|
||||||
|
|
@ -141,7 +145,6 @@ var gs_kiri_slicer = exports;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/** bucket polygons into z-bounded groups */
|
/** bucket polygons into z-bounded groups */
|
||||||
var bucketCount = Math.max(1, Math.ceil(zMax / (zSum / points.length)) - 1);
|
var bucketCount = Math.max(1, Math.ceil(zMax / (zSum / points.length)) - 1);
|
||||||
|
|
@ -192,7 +195,7 @@ var gs_kiri_slicer = exports;
|
||||||
for (key in zFlat) {
|
for (key in zFlat) {
|
||||||
// todo make threshold for flat detection configurable
|
// todo make threshold for flat detection configurable
|
||||||
if (!zFlat.hasOwnProperty(key) || zFlat[key] < 100) continue;
|
if (!zFlat.hasOwnProperty(key) || zFlat[key] < 100) continue;
|
||||||
key = parseFloat(key);
|
key = parseFloat(key) + 0.001;
|
||||||
if (!zIndexes.contains(key) && key >= zMin) zIndexes.push(key);
|
if (!zIndexes.contains(key) && key >= zMin) zIndexes.push(key);
|
||||||
}
|
}
|
||||||
// sort top down
|
// sort top down
|
||||||
|
|
@ -318,6 +321,18 @@ var gs_kiri_slicer = exports;
|
||||||
* @param {number} z
|
* @param {number} z
|
||||||
*/
|
*/
|
||||||
function sliceZ(z) {
|
function sliceZ(z) {
|
||||||
|
z = UTIL.round(z,5);
|
||||||
|
|
||||||
|
// avoid slicing directly on flat faces as it greatly increases
|
||||||
|
// the chances of artifacts, broken joins and excessive path walks
|
||||||
|
if (zFlat[z]) {
|
||||||
|
if (z) {
|
||||||
|
z -= 0.001;
|
||||||
|
} else {
|
||||||
|
z += 0.001;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var phash = {},
|
var phash = {},
|
||||||
lines = [],
|
lines = [],
|
||||||
slice = newSlice(z, options.view ? options.view.newGroup() : null),
|
slice = newSlice(z, options.view ? options.view.newGroup() : null),
|
||||||
|
|
|
||||||
|
|
@ -1094,7 +1094,7 @@ self.kiri.license = exports.LICENSE;
|
||||||
} else if (xhtr.status === 401) {
|
} else if (xhtr.status === 401) {
|
||||||
$('gpapik').style.display = '';
|
$('gpapik').style.display = '';
|
||||||
} else {
|
} else {
|
||||||
console.log("invalid grid-print host");
|
console.log("invalid grid:host url");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -1144,7 +1144,7 @@ self.kiri.license = exports.LICENSE;
|
||||||
alert("print to "+target+": "+data.status);
|
alert("print to "+target+": "+data.status);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
alert("grid:print error\nstatus: "+status+"\nmessage: "+xhtr.responseText);
|
alert("grid:host error\nstatus: "+status+"\nmessage: "+xhtr.responseText);
|
||||||
}
|
}
|
||||||
setProgress(0);
|
setProgress(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,13 +38,13 @@
|
||||||
|
|
||||||
<div class="print-sel" id="send-to-gridprint">
|
<div class="print-sel" id="send-to-gridprint">
|
||||||
<table>
|
<table>
|
||||||
<tr><th colspan="2"><button id="print-gridprint">send to grid:print</button></th></tr>
|
<tr><th colspan="2"><button id="print-gridprint">send to grid:host</button></th></tr>
|
||||||
<tr><th>host:port</th><td><input id="grid-host" size="35" placeholder="http(s)://host:port" /></td></tr>
|
<tr><th>host:port</th><td><input id="grid-host" size="35" placeholder="http(s)://host:port" /></td></tr>
|
||||||
<tr id="gpapik"><th>api key</th><td><input id="grid-apik" size="35" /></td></tr>
|
<tr id="gpapik"><th>api key</th><td><input id="grid-apik" size="35" /></td></tr>
|
||||||
<tr><th>target</th><td>
|
<tr><th>target</th><td>
|
||||||
<!--<input id="grid-target" size="35" />-->
|
<!--<input id="grid-target" size="35" />-->
|
||||||
<select id="grid-target"></select>
|
<select id="grid-target"></select>
|
||||||
</td></tr>
|
</td></tr>
|
||||||
<tr><td colspan="2"><span id="grid-hint">setup <a href="https://github.com/stewartoallen/grid-print" target="_help">grid:print</a> for your network</span></td></tr>
|
<tr><td colspan="2"><span id="grid-hint">setup <a href="https://github.com/GridSpace/grid-host" target="_help">grid:host</a> for your network</span></td></tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue