diff options
author | kintel <kintel@b57f626f-c46c-0410-a088-ec61d464b74c> | 2010-05-10 18:14:12 (GMT) |
---|---|---|
committer | kintel <kintel@b57f626f-c46c-0410-a088-ec61d464b74c> | 2010-05-10 18:14:12 (GMT) |
commit | 8a592d34e7fd50f0e00a96db72eb0c870f731a04 (patch) | |
tree | a99b7dc09778dd2f3f5329b4a4e31221cce91bc9 | |
parent | 135b51b8c0915278beeacd7394ddd69e547efb18 (diff) |
bugfix: Don't normalize zero-length normals
git-svn-id: http://svn.clifford.at/openscad/trunk@545 b57f626f-c46c-0410-a088-ec61d464b74c
-rw-r--r-- | src/export.cc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/export.cc b/src/export.cc index d63188a..40573c5 100644 --- a/src/export.cc +++ b/src/export.cc @@ -120,9 +120,12 @@ void export_stl(CGAL_Nef_polyhedron *root_N, QString filename, QProgressDialog * double nx = (y1-y2)*(z1-z3) - (z1-z2)*(y1-y3); double ny = (z1-z2)*(x1-x3) - (x1-x2)*(z1-z3); double nz = (x1-x2)*(y1-y3) - (y1-y2)*(x1-x3); - double n_scale = 1 / sqrt(nx*nx + ny*ny + nz*nz); + double nlength = sqrt(nx*nx + ny*ny + nz*nz); + // Avoid generating normals for polygons with zero area + double eps = 0.000001; + if (nlength < eps) nlength = 1.0; fprintf(f, " facet normal %f %f %f\n", - nx * n_scale, ny * n_scale, nz * n_scale); + nx / nlength, ny / nlength, nz / nlength); fprintf(f, " outer loop\n"); fprintf(f, " vertex %s\n", vs1.toAscii().data()); fprintf(f, " vertex %s\n", vs2.toAscii().data()); |