enable compound loop path code as parameter

This commit is contained in:
Stewart Allen 2022-01-16 16:20:42 -05:00
commit f4f89bc1ed
4 changed files with 37 additions and 39 deletions

View file

@ -45,8 +45,8 @@ function init() {
opacity: 0, opacity: 0,
color: 0xdddddd, color: 0xdddddd,
zoom: { reverse: true, speed: 1 }, zoom: { reverse: true, speed: 1 },
size: { width: 2000, depth: 2000, height: 0.001, maxz: 200 }, size: { width: 2000, depth: 2000, height: 0.05, maxz: 200 },
grid: { major: 25, minor: 5, grid: { major: 25, minor: 5, zOffset: 0,
colorMajor: 0xcccccc, colorMinor: 0xeeeeee, colorMajor: 0xcccccc, colorMinor: 0xeeeeee,
colorX: 0xff7777, colorY: 0x7777ff }, colorX: 0xff7777, colorY: 0x7777ff },
}); });

View file

@ -319,7 +319,7 @@ let tool = {
} }
}, },
analyze(models) { analyze(models, opt = { compound: false }) {
models = fallback(models); models = fallback(models);
api.log.emit('analyzing mesh(es)...').pin(); api.log.emit('analyzing mesh(es)...').pin();
let promises = []; let promises = [];
@ -327,7 +327,7 @@ let tool = {
let mcore = new Matrix4().makeRotationX(Math.PI / 2); let mcore = new Matrix4().makeRotationX(Math.PI / 2);
for (let m of models) { for (let m of models) {
// todo - translate vertices with source model's matrix // 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 { areas, edges } = data.mapped;
let nm = areas.map(area => new mesh.model({ let nm = areas.map(area => new mesh.model({
file: (area.length/3).toString(), file: (area.length/3).toString(),

View file

@ -400,41 +400,38 @@ mesh.tool = class MeshTool {
// new patch areas // new patch areas
let areas = this.areas = []; let areas = this.areas = [];
// start disabled code path for complex (nested) paths if (opt.compound) {
if (false) { // 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) // return nested mapping
// then attempt to nest them (find holes) let nested = geom.nest(polys.map(p => p.points));
let polys = loops.map(loop => { // recover and map loops from point arrays
return emitLoop(loop); for (let rec of nested) {
}); rec.loop = polys.filter(loop => loop.points === rec.points)[0];
// keep parent/child winding reversed
// return nested mapping let CCW = rec.depth % 2 === 0;
let nested = geom.nest(polys.map(p => p.points)); if ((CCW && rec.area > 0) || (!CCW && rec.area < 0)) {
// recover and map loops from point arrays rec.points = rec.loop.points = rec.points.group(3).reverse().flat();
for (let rec of nested) { rec.loop.index = rec.loop.index.reverse();
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 // extract tops which have nesting depth mod 2 === 0
let tops = nested.filter(rec => rec.depth % 2 === 0); let tops = nested.filter(rec => rec.depth % 2 === 0);
for (let top of tops) { for (let top of tops) {
areas.push(emitTop(top)); areas.push(emitTop(top));
} }
} else {
} // end of disbled code // create area faces covering loops
for (let loop of loops) {
// create area faces covering loops let l2 = emitLoop(loop);
for (let loop of loops) { let fs = emitFaces(l2);
let l2 = emitLoop(loop); areas.push(fs);
let fs = emitFaces(l2); }
areas.push(fs);
} }
// auto-merge newly found enclosed areas // auto-merge newly found enclosed areas

View file

@ -179,8 +179,9 @@ let model = {
return { o1, o2 }; return { o1, o2 };
}, },
analyze(id) { analyze(data) {
let tool = analyze(id, { mapped: true }); let { id, opt } = data;
let tool = analyze(id, { mapped: true, ...opt });
let { stats, mapped } = tool; let { stats, mapped } = tool;
let { cull, dups, faces } = stats; let { cull, dups, faces } = stats;
log(`${id} | face count=${faces} bad=${cull} dup=${dups}`); log(`${id} | face count=${faces} bad=${cull} dup=${dups}`);