mirror of https://github.com/vitalif/openscad
bugfix: Don't normalize zero-length normals
git-svn-id: http://svn.clifford.at/openscad/trunk@545 b57f626f-c46c-0410-a088-ec61d464b74cstl_dim
parent
135b51b8c0
commit
8a592d34e7
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue