Commit 8c68e838 by Philipp Adolf

temp

parent d08d0b1b
......@@ -25,12 +25,16 @@ layout(std430, binding=3) buffer Output {
int neighbors[][3];
};
bool areEqual(vec3 a, vec3 b) {
return all(lessThan(abs(a - b), vec3(0.01)));
}
int shared_edge(vec3 u, vec3 v, vec3 w, vec3 a, vec3 b, vec3 c) {
if (u == a && v == c) {
if (areEqual(u, a) && areEqual(v, c)) {
return 0;
} else if (u == a && w == b) {
} else if (areEqual(u, a) && areEqual(w, b)) {
return 2;
} else if (v == a && w == c) {
} else if (areEqual(v, a) && areEqual(w, c)) {
return 1;
}
return -1;
......@@ -50,7 +54,7 @@ void main() {
vec3 v = vb[ib[3 * (gl_GlobalInvocationID.x + offset_in) + 1]].pos;
vec3 w = vb[ib[3 * (gl_GlobalInvocationID.x + offset_in) + 2]].pos;
for (int i = 0; found < 3 && i < 128 && (3 * gl_GlobalInvocationID.y + offset_search + gl_NumWorkGroups.y * i) + 2 < ib.length(); i++) {
for (int i = 0; i < 128 && (3 * gl_GlobalInvocationID.y + offset_search + gl_NumWorkGroups.y * i) + 2 < ib.length(); i++) {
vec3 a = vb[ib[3 * (gl_GlobalInvocationID.y + offset_search + gl_NumWorkGroups.y * i) + 0]].pos;
vec3 b = vb[ib[3 * (gl_GlobalInvocationID.y + offset_search + gl_NumWorkGroups.y * i) + 1]].pos;
vec3 c = vb[ib[3 * (gl_GlobalInvocationID.y + offset_search + gl_NumWorkGroups.y * i) + 2]].pos;
......
......@@ -89,15 +89,18 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
Tables tables = precomputeTables(input);
Result result = runShader(input, tables);
QVector<Triangle> triangles;
ibToTriangles(&result.vertex_buffer, tables.index_buffer, triangles);
QVector<Triangle> all_triangles;
ibToTriangles(&result.vertex_buffer, tables.index_buffer, all_triangles);
ibToTriangles(&result.vertex_buffer, tables.extra_triangles, all_triangles);
all_triangles += triangles;
QMap<Triangle, Triangle::Neighbors> neighbors;
buildNeighborsMap(result.vertex_buffer, all_triangles, neighbors);
QVector<Triangle> regular;
QVector<Triangle> irregular;
findRegular(all_triangles, neighbors, regular, irregular);
findRegular(triangles, neighbors, regular, irregular);
qCDebug(log_subdiv) << "Indices" << tables.index_buffer.length();
qCDebug(log_subdiv) << "subdivide: regular" << regular.length();
......@@ -177,6 +180,7 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
subTimer.restart();
updateIndexBuffer(tables.index_buffer, modified_vertices);
updateIndexBuffer(tables.extra_triangles, modified_vertices);
qCDebug(log_timing) << "updateIndexBuffer:" << formatTimeMeasurement(subTimer.elapsed());
qCDebug(log_subdiv) << "Precompute Tables Done";
......@@ -370,11 +374,12 @@ void Subdivision::buildNeighborsMap(QVector<Vertex> &vb, QVector<Triangle> &tria
QVector<Triangle> Subdivision::vertexNeighbors(Triangle &triangle, Triangle::Neighbor current_neighbor, QMap<Triangle, Triangle::Neighbors> neighbors) {
QVector<Triangle> ns;
do {
assert(current_neighbor.triangle != NULL);
// qDebug() << current_neighbor.triangle;
// assert(current_neighbor.triangle != NULL);
ns.push_back(*current_neighbor.triangle);
current_neighbor = neighbors.value(*current_neighbor.triangle).get_neighbor(rotate_edge_name(current_neighbor.edge.name));
} while (*current_neighbor.triangle != triangle);
assert(current_neighbor.triangle != NULL);
} while (current_neighbor.triangle != NULL && *current_neighbor.triangle != triangle);
// assert(current_neighbor.triangle != NULL);
return ns;
}
......@@ -410,14 +415,16 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
*/
Triangle::Neighbors ns = neighbors.value(*triangle);
if (!irregular_triangles.contains(*ns.uv.triangle)) {
extra_triangles.insert(*ns.uv.triangle, true);
QVector<Triangle> neighboring_triangles;
neighboring_triangles += vertexNeighbors(*triangle, ns.uv, neighbors);
neighboring_triangles += vertexNeighbors(*triangle, ns.vw, neighbors);
neighboring_triangles += vertexNeighbors(*triangle, ns.wu, neighbors);
QVectorIterator<Triangle> extra(neighboring_triangles);
while (extra.hasNext()) {
Triangle extra_triangle = extra.next();
if (!irregular_triangles.contains(extra_triangle)) {
extra_triangles.insert(extra_triangle, true);
}
if (!irregular_triangles.contains(*ns.vw.triangle)) {
extra_triangles.insert(*ns.vw.triangle, true);
}
if (!irregular_triangles.contains(*ns.wu.triangle)) {
extra_triangles.insert(*ns.wu.triangle, true);
}
// indices of the three vertices added to the edges of this triangle
......@@ -491,10 +498,13 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
tables.index_buffer.push_back(wu);
}
qDebug() << "extra triangles" << extra_triangles.size();
QMapIterator<Triangle, bool> extra_it(extra_triangles);
while (extra_it.hasNext()) {
extra_it.next();
Triangle triangle = extra_it.key();
qDebug() << triangle;
unsigned int uv, vw, wu;
Edge edge;
......
......@@ -165,6 +165,18 @@ bool Triangle::operator<(const Triangle &other) const {
return false;
}
bool Triangle::operator<=(const Triangle &other) const {
return (*this < other) || (*this == other);
}
bool Triangle::operator>(const Triangle &other) const {
return !((*this < other) || (*this == other));
}
bool Triangle::operator>=(const Triangle &other) const {
return !(*this < other);
}
void Triangle::rotate_indices() {
unsigned int a = u_;
u_ = v_;
......
......@@ -57,6 +57,9 @@ class Triangle {
bool operator==(const Triangle &other) const;
bool operator!=(const Triangle &other) const;
bool operator<(const Triangle &other) const;
bool operator<=(const Triangle &other) const;
bool operator>(const Triangle &other) const;
bool operator>=(const Triangle &other) const;
bool next_ctrclockwise(Edge first, Edge next) const;
bool next_clockwise(Edge first, Edge next) const;
......
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