Commit 9175b0a5 by Philipp Adolf

Only add one vertex per edge

parent 59b5b0e9
......@@ -113,6 +113,21 @@ void insert_edge(QMap<Triangle, QVector<Triangle::Edge>> &opposite_edges, const
opposite_edges.insert(triangle, edges);
}
struct Edge {
unsigned int a;
unsigned int b;
friend bool operator<(const Edge &l, const Edge &r) {
if (l.a < r.a) {
return true;
} else if (l.a > r.a) {
return false;
} else {
return l.b < r.b;
}
}
};
/**
* @brief Subdivision::precomputeTables
* @param mesh
......@@ -147,6 +162,9 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
// First the edge shared with the triangles uv edge, then vw and wu.
QMap<Triangle, QVector<Triangle::Edge>> opposite_edges;
// Maps edges to the index of the new vertex added on that edge. The keys are the indices of the two vertices defining the edge and must be in the order uv, vw or uw.
QMap<Edge, unsigned int> edge_indices;
unsigned int edge_index = vb.length();//offset in new index buffer for edge vertices
for (int i = 0; i < triangles.length(); i++){
//schaue alle dreiecke an
......@@ -175,24 +193,55 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
// indices of the three vertices added to the edges of this triangle
unsigned int uv, vw, wu;
uv = edge_index++;
vw = edge_index++;
wu = edge_index++;
Edge edge;
tables.edge_indices.push_back(triangle.u_idx());
tables.edge_indices.push_back(triangle.v_idx());
tables.edge_indices.push_back(triangle.w_idx());
tables.edge_indices.push_back(opposite[0].c);
edge = { triangle.u_idx(), triangle.v_idx() };
if (edge_indices.contains(edge)) {
uv = edge_indices.value(edge);
} else {
uv = edge_index++;
edge_indices.insert(edge, uv);
edge = { opposite[0].a, opposite[0].b };
edge_indices.insert(edge, uv);
tables.edge_indices.push_back(triangle.v_idx());
tables.edge_indices.push_back(triangle.w_idx());
tables.edge_indices.push_back(triangle.u_idx());
tables.edge_indices.push_back(opposite[1].c);
tables.edge_indices.push_back(triangle.u_idx());
tables.edge_indices.push_back(triangle.v_idx());
tables.edge_indices.push_back(triangle.w_idx());
tables.edge_indices.push_back(opposite[0].c);
}
tables.edge_indices.push_back(triangle.w_idx());
tables.edge_indices.push_back(triangle.u_idx());
tables.edge_indices.push_back(triangle.v_idx());
tables.edge_indices.push_back(opposite[2].c);
edge = { triangle.v_idx(), triangle.w_idx() };
if (edge_indices.contains(edge)) {
vw = edge_indices.value(edge);
} else {
vw = edge_index++;
edge_indices.insert(edge, vw);
edge = { opposite[1].a, opposite[1].b };
edge_indices.insert(edge, vw);
tables.edge_indices.push_back(triangle.v_idx());
tables.edge_indices.push_back(triangle.w_idx());
tables.edge_indices.push_back(triangle.u_idx());
tables.edge_indices.push_back(opposite[1].c);
}
edge = { triangle.w_idx(), triangle.u_idx() };
if (edge_indices.contains(edge)) {
wu = edge_indices.value(edge);
} else {
wu = edge_index++;
edge_indices.insert(edge, wu);
edge = { opposite[2].a, opposite[2].b };
edge_indices.insert(edge, wu);
tables.edge_indices.push_back(triangle.w_idx());
tables.edge_indices.push_back(triangle.u_idx());
tables.edge_indices.push_back(triangle.v_idx());
tables.edge_indices.push_back(opposite[2].c);
}
//add indices to new index buffer
tables.index_buffer.push_back(triangle.u_idx());
......
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