From f4f89bc1edc05b92339a0fda76de788e00ae2ccf Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sun, 16 Jan 2022 16:20:42 -0500 Subject: [PATCH] enable compound loop path code as parameter --- src/main/mesh.js | 4 ++-- src/mesh/api.js | 4 ++-- src/mesh/tool.js | 61 +++++++++++++++++++++++------------------------- src/mesh/work.js | 5 ++-- 4 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/main/mesh.js b/src/main/mesh.js index 13a0bafe..8df31fbe 100644 --- a/src/main/mesh.js +++ b/src/main/mesh.js @@ -45,8 +45,8 @@ function init() { opacity: 0, color: 0xdddddd, zoom: { reverse: true, speed: 1 }, - size: { width: 2000, depth: 2000, height: 0.001, maxz: 200 }, - grid: { major: 25, minor: 5, + size: { width: 2000, depth: 2000, height: 0.05, maxz: 200 }, + grid: { major: 25, minor: 5, zOffset: 0, colorMajor: 0xcccccc, colorMinor: 0xeeeeee, colorX: 0xff7777, colorY: 0x7777ff }, }); diff --git a/src/mesh/api.js b/src/mesh/api.js index 6181ebb8..1985559c 100644 --- a/src/mesh/api.js +++ b/src/mesh/api.js @@ -319,7 +319,7 @@ let tool = { } }, - analyze(models) { + analyze(models, opt = { compound: false }) { models = fallback(models); api.log.emit('analyzing mesh(es)...').pin(); let promises = []; @@ -327,7 +327,7 @@ let tool = { let mcore = new Matrix4().makeRotationX(Math.PI / 2); for (let m of models) { // todo - translate vertices with source model's matrix - let p = worker.model_analyze(m.id).then(data => { + let p = worker.model_analyze({ id: m.id, opt }).then(data => { let { areas, edges } = data.mapped; let nm = areas.map(area => new mesh.model({ file: (area.length/3).toString(), diff --git a/src/mesh/tool.js b/src/mesh/tool.js index 9244ad78..cdfa5538 100644 --- a/src/mesh/tool.js +++ b/src/mesh/tool.js @@ -400,41 +400,38 @@ mesh.tool = class MeshTool { // new patch areas let areas = this.areas = []; - // start disabled code path for complex (nested) paths - if (false) { + if (opt.compound) { + // group loops by normal (using swap as crude proxy for now) + // then attempt to nest them (find holes) + let polys = loops.map(loop => { + return emitLoop(loop); + }); - // group loops by normal (using swap as crude proxy for now) - // then attempt to nest them (find holes) - let polys = loops.map(loop => { - return emitLoop(loop); - }); - - // return nested mapping - let nested = geom.nest(polys.map(p => p.points)); - // recover and map loops from point arrays - for (let rec of nested) { - rec.loop = polys.filter(loop => loop.points === rec.points)[0]; - // keep parent/child winding reversed - let CCW = rec.depth % 2 === 0; - if ((CCW && rec.area > 0) || (!CCW && rec.area < 0)) { - rec.points = rec.loop.points = rec.points.group(3).reverse().flat(); - rec.loop.index = rec.loop.index.reverse(); + // return nested mapping + let nested = geom.nest(polys.map(p => p.points)); + // recover and map loops from point arrays + for (let rec of nested) { + rec.loop = polys.filter(loop => loop.points === rec.points)[0]; + // keep parent/child winding reversed + let CCW = rec.depth % 2 === 0; + if ((CCW && rec.area > 0) || (!CCW && rec.area < 0)) { + rec.points = rec.loop.points = rec.points.group(3).reverse().flat(); + rec.loop.index = rec.loop.index.reverse(); + } } - } - // extract tops which have nesting depth mod 2 === 0 - let tops = nested.filter(rec => rec.depth % 2 === 0); - for (let top of tops) { - areas.push(emitTop(top)); - } - - } // end of disbled code - - // create area faces covering loops - for (let loop of loops) { - let l2 = emitLoop(loop); - let fs = emitFaces(l2); - areas.push(fs); + // extract tops which have nesting depth mod 2 === 0 + let tops = nested.filter(rec => rec.depth % 2 === 0); + for (let top of tops) { + areas.push(emitTop(top)); + } + } else { + // create area faces covering loops + for (let loop of loops) { + let l2 = emitLoop(loop); + let fs = emitFaces(l2); + areas.push(fs); + } } // auto-merge newly found enclosed areas diff --git a/src/mesh/work.js b/src/mesh/work.js index 0f06795b..97601f69 100644 --- a/src/mesh/work.js +++ b/src/mesh/work.js @@ -179,8 +179,9 @@ let model = { return { o1, o2 }; }, - analyze(id) { - let tool = analyze(id, { mapped: true }); + analyze(data) { + let { id, opt } = data; + let tool = analyze(id, { mapped: true, ...opt }); let { stats, mapped } = tool; let { cull, dups, faces } = stats; log(`${id} | face count=${faces} bad=${cull} dup=${dups}`);