add mesh heal debug path

This commit is contained in:
Stewart Allen 2021-09-07 20:17:27 -04:00
commit 8eaf721648
2 changed files with 44 additions and 14 deletions

View file

@ -93,14 +93,14 @@
constructor(v1, v2) { constructor(v1, v2) {
this.v1 = v1; this.v1 = v1;
this.v2 = v2; this.v2 = v2;
this.peers = [];
this.faces = []; this.faces = [];
} }
addPeers(lines, face) { addFace(face) {
this.peers.appendAll(lines);
if (this.faces.indexOf(face) < 0) { if (this.faces.indexOf(face) < 0) {
this.faces.push(face); this.faces.push(face);
// } else {
// console.log('adding face to line twice', this, face);
} }
return this; return this;
} }
@ -139,6 +139,7 @@
// point order will be swapped for reconstructed faces // point order will be swapped for reconstructed faces
// to preserve chirality (assuming face normals are correct) // to preserve chirality (assuming face normals are correct)
line = hash[key] = new Line(v1, v2); line = hash[key] = new Line(v1, v2);
line.key = key;
lines.push(line); lines.push(line);
let lm1 = vmap[v1] = vmap[v1] || []; let lm1 = vmap[v1] = vmap[v1] || [];
let lm2 = vmap[v2] = vmap[v2] || []; let lm2 = vmap[v2] = vmap[v2] || [];
@ -152,18 +153,14 @@
let v1 = faces[i]; let v1 = faces[i];
let v2 = faces[i+1]; let v2 = faces[i+1];
let v3 = faces[i+2]; let v3 = faces[i+2];
let l1 = getLine(v1, v2); let l1 = getLine(v1, v2).addFace(i);
let l2 = getLine(v2, v3); let l2 = getLine(v2, v3).addFace(i);
let l3 = getLine(v3, v1); let l3 = getLine(v3, v1).addFace(i);
l1.addPeers([l2, l3], i);
l2.addPeers([l3, l1], i);
l3.addPeers([l1, l2], i);
} }
this.lines = lines; this.lines = lines;
// lines belonging to only one face or with only 2 peers // lines belonging to only one face are on the edge of a hole
// are on the edge of a hole
let edges = this.edges = lines.filter(l => l.faces.length === 1); let edges = this.edges = lines.filter(l => l.faces.length === 1);
let loops = this.loops = []; let loops = this.loops = [];
// console.log({edges}); // console.log({edges});
@ -174,7 +171,7 @@
if (line.used) { if (line.used) {
continue; continue;
} }
line.used = true; // line.used = true;
let loop = [ line ]; let loop = [ line ];
// build line through adjacent lines // build line through adjacent lines
while (true) { while (true) {
@ -185,7 +182,8 @@
break; break;
} }
if (adjacent.length > 2) { if (adjacent.length > 2) {
console.log('error adjacent', adjacent); console.log('error adjacent', line, adjacent, loops.length, loop.length);
line.error = adjacent;
// break; // break;
} }
if (adjacent.length === 1) { if (adjacent.length === 1) {

View file

@ -306,9 +306,41 @@ console.log/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
} }
}; };
PRO.heal = function() { PRO.heal = function(debug) {
let mesh = this.debugMesh(); let mesh = this.debugMesh();
mesh.heal(); mesh.heal();
if (debug) {
let verts = mesh.vertices;
let edges = mesh.edges;
let error = mesh.edges.filter(l => l.error);
let layrz = new KIRI.Layers();
layrz.setLayer("edges", {line: 0xff0000});
for (let line of edges) {
layrz.addLine(
BASE.newPoint(verts[line.v1], verts[line.v1+1], verts[line.v1+2]),
BASE.newPoint(verts[line.v2], verts[line.v2+1], verts[line.v2+2])
);
}
for (let l=0; l<mesh.loops.length; l++) {
layrz.setLayer(`loop ${l}`, {line: l % 2 === 0 ? 0xff00ff : 0x00ff00});
for (let line of mesh.loops[l]) {
layrz.addLine(
BASE.newPoint(verts[line.v1], verts[line.v1+1], verts[line.v1+2] - 0.03),
BASE.newPoint(verts[line.v2], verts[line.v2+1], verts[line.v2+2] - 0.03)
);
}
}
layrz.setLayer("error", {line: 0x0000ff});
for (let line of error) {
layrz.addLine(
BASE.newPoint(verts[line.v1], verts[line.v1+1], verts[line.v1+2] - 0.06),
BASE.newPoint(verts[line.v2], verts[line.v2+1], verts[line.v2+2] - 0.06)
);
}
let stack = new KIRI.Stack(this.mesh);
stack.addLayers(layrz);
return { layrz, stack };
}
if (mesh.newFaces) { if (mesh.newFaces) {
this.loadVertices(mesh.unrolled().toFloat32()); this.loadVertices(mesh.unrolled().toFloat32());
return this.modified = true; return this.modified = true;