Skip to content
Snippets Groups Projects
Commit d58bab54 authored by Julius Nehring-Wirxel's avatar Julius Nehring-Wirxel
Browse files

Fix rendering bug due to zero normal faces

parent f46d9703
No related branches found
No related tags found
1 merge request!143Fix rendering bug due to zero normal faces
...@@ -819,15 +819,24 @@ public: ...@@ -819,15 +819,24 @@ public:
centroid /= 3.0f * area; centroid /= 3.0f * area;
} }
// try to find a non-zero normal
tg::vec3 normal; tg::vec3 normal;
{ {
auto e = face.any_halfedge(); auto const h_start = face.any_halfedge();
auto const v0 = tg::pos3(e.vertex_from()[pos]); auto h_curr = h_start;
auto const v1 = tg::pos3(e.vertex_to()[pos]); do
{
auto const v0 = tg::pos3(h_curr.vertex_from()[pos]);
auto const v1 = tg::pos3(h_curr.vertex_to()[pos]);
normal = cross(v0 - centroid, v1 - centroid); normal = cross(v0 - centroid, v1 - centroid);
auto l = length(normal); auto l = length(normal);
normal = l == 0 ? tg::vec3::zero : normal / l; normal = l == 0 ? tg::vec3::zero : normal / l;
h_curr = h_curr.next();
} while (h_curr != h_start && normal == tg::vec3::zero);
} }
// add triangle fan
auto h0 = face.any_halfedge(); auto h0 = face.any_halfedge();
auto he = h0.prev(); auto he = h0.prev();
auto h = h0.next(); auto h = h0.next();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment