mirror of https://github.com/vitalif/openscad
#1105 Workaround for CGAL problem: Don't trust normal vectors from Nef polyhedrons, normalize calculated normal vectors
parent
5537e82274
commit
1941a7fc0d
|
@ -107,6 +107,8 @@ namespace CGALUtils {
|
||||||
else {
|
else {
|
||||||
// Calculate best guess at face normal using Newell's method
|
// Calculate best guess at face normal using Newell's method
|
||||||
CGAL::normal_vector_newell_3(polygons.front().begin(), polygons.front().end(), normalvec);
|
CGAL::normal_vector_newell_3(polygons.front().begin(), polygons.front().end(), normalvec);
|
||||||
|
double sqrl = normalvec.squared_length();
|
||||||
|
if (sqrl > 0.0) normalvec = normalvec / sqrt(sqrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass the normal vector to the (undocumented)
|
// Pass the normal vector to the (undocumented)
|
||||||
|
|
|
@ -917,10 +917,13 @@ namespace CGALUtils {
|
||||||
and let the tessellater deal with the holes, and then
|
and let the tessellater deal with the holes, and then
|
||||||
just output the resulting 3d triangles*/
|
just output the resulting 3d triangles*/
|
||||||
|
|
||||||
CGAL::Vector_3<CGAL_Kernel3> nvec = plane.orthogonal_vector();
|
// We cannot trust the plane from Nef polyhedron to be correct.
|
||||||
K::Vector_3 normal(CGAL::to_double(nvec.x()), CGAL::to_double(nvec.y()), CGAL::to_double(nvec.z()));
|
// Passing an incorrect normal vector can cause a crash in the constrained delaunay triangulator
|
||||||
|
// See http://cgal-discuss.949826.n4.nabble.com/Nef3-Wrong-normal-vector-reported-causes-triangulator-crash-tt4660282.html
|
||||||
|
// CGAL::Vector_3<CGAL_Kernel3> nvec = plane.orthogonal_vector();
|
||||||
|
// K::Vector_3 normal(CGAL::to_double(nvec.x()), CGAL::to_double(nvec.y()), CGAL::to_double(nvec.z()));
|
||||||
std::vector<Polygon> triangles;
|
std::vector<Polygon> triangles;
|
||||||
bool err = CGALUtils::tessellatePolygonWithHoles(polyholes, triangles, &normal);
|
bool err = CGALUtils::tessellatePolygonWithHoles(polyholes, triangles, NULL);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
BOOST_FOREACH(const Polygon &p, triangles) {
|
BOOST_FOREACH(const Polygon &p, triangles) {
|
||||||
if (p.size() != 3) {
|
if (p.size() != 3) {
|
||||||
|
|
Loading…
Reference in New Issue