From a899b517e581f7306a048928c1391a2e86594480 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Wed, 8 Sep 2021 10:22:49 -0400 Subject: [PATCH] document healing. remove old code --- src/geo/mesh.js | 78 ++++++++++--------------------------------------- 1 file changed, 15 insertions(+), 63 deletions(-) diff --git a/src/geo/mesh.js b/src/geo/mesh.js index f6614579..7b40e780 100644 --- a/src/geo/mesh.js +++ b/src/geo/mesh.js @@ -22,7 +22,7 @@ * set vertices and faces of the mesh. if only vertices are provided * then the data is assumed to be un-indexed and will be indexed into * faces. if faces are provided, they are assumed to be index references - * into the vertex data. + * into the vertex data. removes invalid faces. * * the end result is face data mapped to an indexed set of unique vertices. * @@ -62,16 +62,15 @@ } fnew.push(vpos); if (fnew.length === 3) { + // cull invalid faces (shares 2 or more points) if (fnew[0] === fnew[1] || fnew[0] === fnew[2] || fnew[1] === fnew[2]) { - // console.log('invalid face', fnew); fnew = []; continue; } let key = fnew.slice().sort().join('-'); + // drop duplicate faces (even when reversed - thus the sort) if (!fcac[key]) { faces.appendAll(fnew); - // } else { - // console.log('dup face', key); } fcac[key] = key; fnew = []; @@ -96,10 +95,12 @@ return out; } + /** + * finds edge lines which are line segments on a single face. + * construct ordered line maps with array of connected edges. + * connect lines into polys. earcut polys into new faces. + */ heal() { - // construct ordered line map with array of connected lines - // for each point pair, create ordered line - // for each face triple, add lines to connect line array let vertices = this.vertices; let faces = this.faces; let hash = {}; // key to line map @@ -287,62 +288,13 @@ } } + + // filter out null and short loops this.loops = loops = loops.filter(l => l && l.length > 2); - // console.log({ - // loops, - // ends: loops.map(loop => { - // return [loop[0], loop.last()]; - // }), - // coor: loops.map(loop => { - // return [ - // getXYZ(loop[0].v1), - // getXYZ(loop[0].v2), - // getXYZ(loop.last().v2), - // getXYZ(loop.last().v1) - // ]; - // }) - // }); - // progressive boundary run algorithm - function emitLoop1(loop) { - while (loop.length > 2) { - console.log({loop}); - let nuloop = []; - // proceed through line pairs - for (let i=0, l=loop.length; i