borrow bucket map from cam slicer to allow negative z indices
This commit is contained in:
parent
6812644a3a
commit
5a56453390
2 changed files with 16 additions and 6 deletions
|
|
@ -22,6 +22,14 @@ THREE.computeFaceNormal = function(vA,vB,vC) {
|
||||||
return cb;
|
return cb;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// https://www.npmjs.com/package/three-mesh-bvh
|
||||||
|
THREE.addBVH = function() {
|
||||||
|
const { computeBoundsTree, disposeBoundsTree, acceleratedRaycast } = MeshBVHLib;
|
||||||
|
THREE.BufferGeometry.prototype.computeBoundsTree = computeBoundsTree;
|
||||||
|
THREE.BufferGeometry.prototype.disposeBoundsTree = disposeBoundsTree;
|
||||||
|
THREE.Mesh.prototype.raycast = acceleratedRaycast;
|
||||||
|
};
|
||||||
|
|
||||||
THREE.dispose = function(obj) {
|
THREE.dispose = function(obj) {
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ async function slice(points, options = {}) {
|
||||||
zScale, // bucket span in z units
|
zScale, // bucket span in z units
|
||||||
zSum = 0.0, // sanity check that points enclose non-zere volume
|
zSum = 0.0, // sanity check that points enclose non-zere volume
|
||||||
buckets = [], // banded/grouped faces to speed up slice/search
|
buckets = [], // banded/grouped faces to speed up slice/search
|
||||||
|
bucketMap = {},
|
||||||
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() {},
|
||||||
|
|
@ -161,11 +162,6 @@ async function slice(points, options = {}) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// create empty buckets
|
|
||||||
for (i = 0; i < bucketCount; i++) {
|
|
||||||
buckets.push({ points: [], slices: [] });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bucketCount > 1) {
|
if (bucketCount > 1) {
|
||||||
let failAt = (points.length * overlapMax) | 0, bucket;
|
let failAt = (points.length * overlapMax) | 0, bucket;
|
||||||
// copy triples into all matching z-buckets
|
// copy triples into all matching z-buckets
|
||||||
|
|
@ -179,7 +175,12 @@ async function slice(points, options = {}) {
|
||||||
bM = Math.min(Math.ceil(zM * zScale), bucketCount);
|
bM = Math.min(Math.ceil(zM * zScale), bucketCount);
|
||||||
// add point to all buckets in range
|
// add point to all buckets in range
|
||||||
for (j = bm; j < bM; j++) {
|
for (j = bm; j < bM; j++) {
|
||||||
bucket = buckets[j].points;
|
let map = bucketMap[j];
|
||||||
|
if (!map) {
|
||||||
|
map = bucketMap[j] = { points: [], slices: [] };
|
||||||
|
buckets.push(map);
|
||||||
|
}
|
||||||
|
bucket = map.points;
|
||||||
bucket.push(p1);
|
bucket.push(p1);
|
||||||
bucket.push(p2);
|
bucket.push(p2);
|
||||||
bucket.push(p3);
|
bucket.push(p3);
|
||||||
|
|
@ -196,6 +197,7 @@ async function slice(points, options = {}) {
|
||||||
// fallback if we can't partition point space
|
// fallback if we can't partition point space
|
||||||
if (bucketCount === 1) {
|
if (bucketCount === 1) {
|
||||||
buckets = [{ points, slices: [] }];
|
buckets = [{ points, slices: [] }];
|
||||||
|
bucketMap[0] = buckets[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// create buckets data structure
|
// create buckets data structure
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue