diff --git a/src/mode/fdm/slice.js b/src/mode/fdm/slice.js index 0922a21e..e640bc80 100644 --- a/src/mode/fdm/slice.js +++ b/src/mode/fdm/slice.js @@ -1409,11 +1409,13 @@ }; let { position } = geo.attributes; let { itemSize, count, array } = position; + let v3cache = new Vector3Cache(); + let coplane = new Coplanars(); for (let i = 0; i 0; }; + class Vector3Cache { + constructor() { + this.cache = {}; + } + + get(x, y, z) { + let key = [x.round(4),y.round(4),z.round(4)].sort().join(','); + let val = this.cache[key]; + if (!val) { + val = new THREE.Vector3(x, y, z); + this.cache[key] = val; + } + return val; + } + } + + class Coplanars { + constructor() { + this.cache = {}; + } + + put(a, b, c, norm) { + let key = norm.round(4).toString(); + let arr = this.cache[key]; + if (!arr) { + arr = []; + this.cache[key] = arr; + } + arr.push([a,b,c]); + } + + group() { + let out = {}; + for (let norm in this.cache) { + let arr = this.cache[norm]; + let groups = []; + for (let face of arr) { + let match = undefined; + // see if face matches vertices in any group + outer: for (let group of groups) { + for (let el of group) { + if ( + el.indexOf(face[0]) >= 0 || + el.indexOf(face[1]) >= 0 || + el.indexOf(face[2]) >= 0 + ) { + match = group; + break outer; + } + } + } + if (match) { + match.push(face); + } else { + groups.push([face]); + } + } + out[norm] = groups; + } + // console.log(out); + return out; + } + } + })();