more pluggable bits for replacing fdm/cam slicers
This commit is contained in:
parent
818cb8a7fd
commit
0d536736c5
1 changed files with 27 additions and 7 deletions
|
|
@ -31,13 +31,15 @@ async function slice(points, options = {}) {
|
||||||
let zMin = options.zmin || 0,
|
let zMin = options.zmin || 0,
|
||||||
zMax = options.zmax || 0,
|
zMax = options.zmax || 0,
|
||||||
zInc = options.zinc || 0,
|
zInc = options.zinc || 0,
|
||||||
|
zGen = options.zGen, // optional z index generator function
|
||||||
zIndexes = options.indices || [],
|
zIndexes = options.indices || [],
|
||||||
minStep = options.minstep || 0,
|
minStep = options.minstep || 0,
|
||||||
zFlat = {}, // map area of z index flat areas
|
zFlat = {}, // map area of z index flat areas
|
||||||
zList = {}, // fast map of z indexes
|
zList = {}, // fast map of z indexes
|
||||||
zScale, // bucket span in z units
|
zLine = [], // map of line counts co-linear to z plane
|
||||||
zSum = 0.0, // sanity check that points enclose non-zere volume
|
zScale, // bucket span in z units
|
||||||
buckets = [], // banded/grouped faces to speed up slice/search
|
zSum = 0.0, // sanity check that points enclose non-zere volume
|
||||||
|
buckets = [], // banded/grouped faces to speed up slice/search
|
||||||
overlapMax = options.overlap || 0.75,
|
overlapMax = options.overlap || 0.75,
|
||||||
bucketMax = options.bucketmax || 100,
|
bucketMax = options.bucketmax || 100,
|
||||||
onupdate = options.onupdate || function() {},
|
onupdate = options.onupdate || function() {},
|
||||||
|
|
@ -85,6 +87,13 @@ async function slice(points, options = {}) {
|
||||||
} else {
|
} else {
|
||||||
zFlat[zkey] += area;
|
zFlat[zkey] += area;
|
||||||
}
|
}
|
||||||
|
zLine[zkey] = (zLine[zkey] || 0) + 1;
|
||||||
|
} else if (p1.z === p2.z) {
|
||||||
|
zLine[p1.z] = (zLine[p1.z] || 0) + 1;
|
||||||
|
} else if (p2.z === p3.z) {
|
||||||
|
zLine[p2.z] = (zLine[p2.z] || 0) + 1;
|
||||||
|
} else if (p3.z === p1.z) {
|
||||||
|
zLine[p3.z] = (zLine[p3.z] || 0) + 1;
|
||||||
}
|
}
|
||||||
if (autoDim) {
|
if (autoDim) {
|
||||||
zMin = Math.min(zMin, p1.z, p2.z, p3.z);
|
zMin = Math.min(zMin, p1.z, p2.z, p3.z);
|
||||||
|
|
@ -114,6 +123,12 @@ async function slice(points, options = {}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// allow zGen to override or update zIndexes
|
||||||
|
// FDM, CAM, Laser slicers will use this to align or interpolate layers
|
||||||
|
if (zGen) {
|
||||||
|
zIndexes = zGen({ zMin, zMax, zLine, zFlat, zIndexes, options });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bucket polygons into z-bounded groups (inside or crossing)
|
* bucket polygons into z-bounded groups (inside or crossing)
|
||||||
* to reduce the search space in complex models
|
* to reduce the search space in complex models
|
||||||
|
|
@ -189,10 +204,15 @@ async function slice(points, options = {}) {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
let opt = { ...options, zMin, zMax };
|
let opt = { ...options, zMin, zMax };
|
||||||
|
|
||||||
for (let bucket of buckets) {
|
for (let i = 0, l = buckets.length; i < l; i++) {
|
||||||
|
let bucket = buckets[i];
|
||||||
let { points, slices } = bucket;
|
let { points, slices } = bucket;
|
||||||
for (let z of slices) {
|
for (let z of slices) {
|
||||||
output.push(await sliceFn(z, points, opt));
|
output.push(await sliceFn(z, points, {
|
||||||
|
...opt,
|
||||||
|
bucket: i, // pass which bucket we are (sharding)
|
||||||
|
buckets: l // pass total bucket count (sharding)
|
||||||
|
}));
|
||||||
onupdate(0.1 + (count++ / zIndexes.length) * 0.9);
|
onupdate(0.1 + (count++ / zIndexes.length) * 0.9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue