Commit 78246356 by Alisa Jung

half-fix broken mesh from 4th(?) subdivision due to rounding errors at vertices

(when a triangle can't find all three adjacent vertices: don't create new edge points, keep indices for old triangle. Still creates holes though, since vertex points are moved anyway.)
parent 04f00bf9
...@@ -93,7 +93,7 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -93,7 +93,7 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
//compute edge table //compute edge table
//Format: first two entries: edge vertices. last two entries: distant vertices. //Format: first two entries: edge vertices. last two entries: distant vertices.
unsigned int nib_offset = vb.length(); unsigned int nib_offset = vb.length();//offset in new index buffer for edge vertices
for (int i = 0; i < ib.length(); i+=3){ for (int i = 0; i < ib.length(); i+=3){
//schaue alle dreiecke an //schaue alle dreiecke an
...@@ -107,6 +107,7 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -107,6 +107,7 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
y = vb[y_i]; y = vb[y_i];
z = vb[z_i]; z = vb[z_i];
QVector<unsigned int> edge_indices_buffer;//push all edge indices into this, then check if enough edge indices were found. if yes, copy to Tables and add to new index buffer.
/* /*
* Find edge xy in all other triangles, add to edge_indices * Find edge xy in all other triangles, add to edge_indices
...@@ -136,22 +137,22 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -136,22 +137,22 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
//zx = ba, cb, ac //zx = ba, cb, ac
//TODO if oder else if? //TODO if oder else if?
if (x.samePos(a) && y.samePos(c)){ if (x.samePos(a) && y.samePos(c)){
tables.edge_indices.push_back(x_i); edge_indices_buffer.push_back(x_i);
tables.edge_indices.push_back(y_i); edge_indices_buffer.push_back(y_i);
tables.edge_indices.push_back(z_i); edge_indices_buffer.push_back(z_i);
tables.edge_indices.push_back(b_i); edge_indices_buffer.push_back(b_i);
} }
if (x.samePos(b) && y.samePos(a)){ if (x.samePos(b) && y.samePos(a)){
tables.edge_indices.push_back(x_i); edge_indices_buffer.push_back(x_i);
tables.edge_indices.push_back(y_i); edge_indices_buffer.push_back(y_i);
tables.edge_indices.push_back(z_i); edge_indices_buffer.push_back(z_i);
tables.edge_indices.push_back(c_i); edge_indices_buffer.push_back(c_i);
} }
if (x.samePos(c) && y.samePos(b)){ if (x.samePos(c) && y.samePos(b)){
tables.edge_indices.push_back(x_i); edge_indices_buffer.push_back(x_i);
tables.edge_indices.push_back(y_i); edge_indices_buffer.push_back(y_i);
tables.edge_indices.push_back(z_i); edge_indices_buffer.push_back(z_i);
tables.edge_indices.push_back(a_i); edge_indices_buffer.push_back(a_i);
} }
} }
} }
...@@ -172,22 +173,22 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -172,22 +173,22 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
//yz = ba, cb, ac //yz = ba, cb, ac
if (y.samePos(a) && z.samePos(c)){ if (y.samePos(a) && z.samePos(c)){
tables.edge_indices.push_back(y_i); edge_indices_buffer.push_back(y_i);
tables.edge_indices.push_back(z_i); edge_indices_buffer.push_back(z_i);
tables.edge_indices.push_back(x_i); edge_indices_buffer.push_back(x_i);
tables.edge_indices.push_back(b_i); edge_indices_buffer.push_back(b_i);
} }
if (y.samePos(b) && z.samePos(a)){ if (y.samePos(b) && z.samePos(a)){
tables.edge_indices.push_back(y_i); edge_indices_buffer.push_back(y_i);
tables.edge_indices.push_back(z_i); edge_indices_buffer.push_back(z_i);
tables.edge_indices.push_back(x_i); edge_indices_buffer.push_back(x_i);
tables.edge_indices.push_back(c_i); edge_indices_buffer.push_back(c_i);
} }
if (y.samePos(c) && z.samePos(b)){ if (y.samePos(c) && z.samePos(b)){
tables.edge_indices.push_back(y_i); edge_indices_buffer.push_back(y_i);
tables.edge_indices.push_back(z_i); edge_indices_buffer.push_back(z_i);
tables.edge_indices.push_back(x_i); edge_indices_buffer.push_back(x_i);
tables.edge_indices.push_back(a_i); edge_indices_buffer.push_back(a_i);
} }
} }
} }
...@@ -208,42 +209,60 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -208,42 +209,60 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
if (x.samePos(a) && z.samePos(b)){ if (x.samePos(a) && z.samePos(b)){
tables.edge_indices.push_back(x_i); edge_indices_buffer.push_back(x_i);
tables.edge_indices.push_back(z_i); edge_indices_buffer.push_back(z_i);
tables.edge_indices.push_back(y_i); edge_indices_buffer.push_back(y_i);
tables.edge_indices.push_back(c_i); edge_indices_buffer.push_back(c_i);
} }
if (x.samePos(b) && z.samePos(c)){ if (x.samePos(b) && z.samePos(c)){
tables.edge_indices.push_back(x_i); edge_indices_buffer.push_back(x_i);
tables.edge_indices.push_back(z_i); edge_indices_buffer.push_back(z_i);
tables.edge_indices.push_back(y_i); edge_indices_buffer.push_back(y_i);
tables.edge_indices.push_back(a_i); edge_indices_buffer.push_back(a_i);
} }
if (x.samePos(c) && z.samePos(a)){ if (x.samePos(c) && z.samePos(a)){
tables.edge_indices.push_back(x_i); edge_indices_buffer.push_back(x_i);
tables.edge_indices.push_back(z_i); edge_indices_buffer.push_back(z_i);
tables.edge_indices.push_back(y_i); edge_indices_buffer.push_back(y_i);
tables.edge_indices.push_back(b_i); edge_indices_buffer.push_back(b_i);
} }
} }
}//quadratische Laufzeit ftw }//quadratische Laufzeit ftw
//add indices to new index buffer
tables.index_buffer.push_back(ib[i]);
tables.index_buffer.push_back(nib_offset + i);
tables.index_buffer.push_back(nib_offset + i + 2);
tables.index_buffer.push_back(ib[i+1]); if (edge_indices_buffer.length() == 12){
tables.index_buffer.push_back(nib_offset + i + 1); //copy edge indices buffer to actual edge indices
tables.index_buffer.push_back(nib_offset + i); for (int k = 0; k < edge_indices_buffer.length(); k++){
tables.edge_indices.push_back(edge_indices_buffer[k]);
}
//add indices to new index buffer
tables.index_buffer.push_back(ib[i]);
tables.index_buffer.push_back(nib_offset);
tables.index_buffer.push_back(nib_offset + 2);
tables.index_buffer.push_back(ib[i+1]);
tables.index_buffer.push_back(nib_offset + 1);
tables.index_buffer.push_back(nib_offset);
tables.index_buffer.push_back(ib[i+2]); tables.index_buffer.push_back(ib[i+2]);
tables.index_buffer.push_back(nib_offset + i + 2); tables.index_buffer.push_back(nib_offset + 2);
tables.index_buffer.push_back(nib_offset + i + 1); tables.index_buffer.push_back(nib_offset + 1);
tables.index_buffer.push_back(nib_offset + i); tables.index_buffer.push_back(nib_offset);
tables.index_buffer.push_back(nib_offset + i + 1); tables.index_buffer.push_back(nib_offset + 1);
tables.index_buffer.push_back(nib_offset + i + 2); tables.index_buffer.push_back(nib_offset + 2);
nib_offset += 3;
}else{
if (true || debugOutput){
qWarning()<<"Could not find all indices for edge points at ib " << i <<". Keep old triangle.";
}
//keep old, unsubdivided triangle.
tables.index_buffer.push_back(ib[i]);
tables.index_buffer.push_back(ib[i+1]);
tables.index_buffer.push_back(ib[i+2]);
}
//Wichtig: Wir gehen davon aus, dass wir geschlossene Oberflächen haben, dh für jede Kante von einem Dreieck wird eine passende Kante bei einem anderen Dreieck gefunden. //Wichtig: Wir gehen davon aus, dass wir geschlossene Oberflächen haben, dh für jede Kante von einem Dreieck wird eine passende Kante bei einem anderen Dreieck gefunden.
}//for each index in indexbuffer }//for each index in indexbuffer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment