Commit 749bd796 by Kai Westerkamp
parents 6ee50809 78246356
......@@ -93,7 +93,7 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
//compute edge table
//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){
//schaue alle dreiecke an
......@@ -107,6 +107,7 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
y = vb[y_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
......@@ -136,22 +137,22 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
//zx = ba, cb, ac
//TODO if oder else if?
if (x.samePos(a) && y.samePos(c)){
tables.edge_indices.push_back(x_i);
tables.edge_indices.push_back(y_i);
tables.edge_indices.push_back(z_i);
tables.edge_indices.push_back(b_i);
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(b_i);
}
if (x.samePos(b) && y.samePos(a)){
tables.edge_indices.push_back(x_i);
tables.edge_indices.push_back(y_i);
tables.edge_indices.push_back(z_i);
tables.edge_indices.push_back(c_i);
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(c_i);
}
if (x.samePos(c) && y.samePos(b)){
tables.edge_indices.push_back(x_i);
tables.edge_indices.push_back(y_i);
tables.edge_indices.push_back(z_i);
tables.edge_indices.push_back(a_i);
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(a_i);
}
}
}
......@@ -172,22 +173,22 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
//yz = ba, cb, ac
if (y.samePos(a) && z.samePos(c)){
tables.edge_indices.push_back(y_i);
tables.edge_indices.push_back(z_i);
tables.edge_indices.push_back(x_i);
tables.edge_indices.push_back(b_i);
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(b_i);
}
if (y.samePos(b) && z.samePos(a)){
tables.edge_indices.push_back(y_i);
tables.edge_indices.push_back(z_i);
tables.edge_indices.push_back(x_i);
tables.edge_indices.push_back(c_i);
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(c_i);
}
if (y.samePos(c) && z.samePos(b)){
tables.edge_indices.push_back(y_i);
tables.edge_indices.push_back(z_i);
tables.edge_indices.push_back(x_i);
tables.edge_indices.push_back(a_i);
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(a_i);
}
}
}
......@@ -208,42 +209,60 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
if (x.samePos(a) && z.samePos(b)){
tables.edge_indices.push_back(x_i);
tables.edge_indices.push_back(z_i);
tables.edge_indices.push_back(y_i);
tables.edge_indices.push_back(c_i);
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(c_i);
}
if (x.samePos(b) && z.samePos(c)){
tables.edge_indices.push_back(x_i);
tables.edge_indices.push_back(z_i);
tables.edge_indices.push_back(y_i);
tables.edge_indices.push_back(a_i);
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(a_i);
}
if (x.samePos(c) && z.samePos(a)){
tables.edge_indices.push_back(x_i);
tables.edge_indices.push_back(z_i);
tables.edge_indices.push_back(y_i);
tables.edge_indices.push_back(b_i);
edge_indices_buffer.push_back(x_i);
edge_indices_buffer.push_back(z_i);
edge_indices_buffer.push_back(y_i);
edge_indices_buffer.push_back(b_i);
}
}
}//quadratische Laufzeit ftw
if (edge_indices_buffer.length() == 12){
//copy edge indices buffer to actual edge indices
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 + i);
tables.index_buffer.push_back(nib_offset + i + 2);
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 + i + 1);
tables.index_buffer.push_back(nib_offset + i);
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(nib_offset + i + 2);
tables.index_buffer.push_back(nib_offset + i + 1);
tables.index_buffer.push_back(nib_offset + 2);
tables.index_buffer.push_back(nib_offset + 1);
tables.index_buffer.push_back(nib_offset + i);
tables.index_buffer.push_back(nib_offset + i + 1);
tables.index_buffer.push_back(nib_offset + i + 2);
tables.index_buffer.push_back(nib_offset);
tables.index_buffer.push_back(nib_offset + 1);
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.
}//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