add mesh heal debug path
This commit is contained in:
parent
39e0356ba5
commit
8eaf721648
2 changed files with 44 additions and 14 deletions
|
|
@ -93,14 +93,14 @@
|
|||
constructor(v1, v2) {
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
this.peers = [];
|
||||
this.faces = [];
|
||||
}
|
||||
|
||||
addPeers(lines, face) {
|
||||
this.peers.appendAll(lines);
|
||||
addFace(face) {
|
||||
if (this.faces.indexOf(face) < 0) {
|
||||
this.faces.push(face);
|
||||
// } else {
|
||||
// console.log('adding face to line twice', this, face);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
|
@ -139,6 +139,7 @@
|
|||
// point order will be swapped for reconstructed faces
|
||||
// to preserve chirality (assuming face normals are correct)
|
||||
line = hash[key] = new Line(v1, v2);
|
||||
line.key = key;
|
||||
lines.push(line);
|
||||
let lm1 = vmap[v1] = vmap[v1] || [];
|
||||
let lm2 = vmap[v2] = vmap[v2] || [];
|
||||
|
|
@ -152,18 +153,14 @@
|
|||
let v1 = faces[i];
|
||||
let v2 = faces[i+1];
|
||||
let v3 = faces[i+2];
|
||||
let l1 = getLine(v1, v2);
|
||||
let l2 = getLine(v2, v3);
|
||||
let l3 = getLine(v3, v1);
|
||||
l1.addPeers([l2, l3], i);
|
||||
l2.addPeers([l3, l1], i);
|
||||
l3.addPeers([l1, l2], i);
|
||||
let l1 = getLine(v1, v2).addFace(i);
|
||||
let l2 = getLine(v2, v3).addFace(i);
|
||||
let l3 = getLine(v3, v1).addFace(i);
|
||||
}
|
||||
|
||||
this.lines = lines;
|
||||
|
||||
// lines belonging to only one face or with only 2 peers
|
||||
// are on the edge of a hole
|
||||
// lines belonging to only one face are on the edge of a hole
|
||||
let edges = this.edges = lines.filter(l => l.faces.length === 1);
|
||||
let loops = this.loops = [];
|
||||
// console.log({edges});
|
||||
|
|
@ -174,7 +171,7 @@
|
|||
if (line.used) {
|
||||
continue;
|
||||
}
|
||||
line.used = true;
|
||||
// line.used = true;
|
||||
let loop = [ line ];
|
||||
// build line through adjacent lines
|
||||
while (true) {
|
||||
|
|
@ -185,7 +182,8 @@
|
|||
break;
|
||||
}
|
||||
if (adjacent.length > 2) {
|
||||
console.log('error adjacent', adjacent);
|
||||
console.log('error adjacent', line, adjacent, loops.length, loop.length);
|
||||
line.error = adjacent;
|
||||
// break;
|
||||
}
|
||||
if (adjacent.length === 1) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
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) {
|
||||
this.loadVertices(mesh.unrolled().toFloat32());
|
||||
return this.modified = true;
|
||||
|
|
|
|||
Loading…
Reference in a new issue