From 302fad13b02bfb565834175afa2e516effbd29e1 Mon Sep 17 00:00:00 2001 From: Alexander Gessler Date: Fri, 25 Jan 2013 05:16:02 +0100 Subject: [PATCH] - Ifc: [openings] don't accidentally mirror stuff when projecting onto 2D planes. --- code/IFCGeometry.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/code/IFCGeometry.cpp b/code/IFCGeometry.cpp index 0c044553f..99f99f831 100644 --- a/code/IFCGeometry.cpp +++ b/code/IFCGeometry.cpp @@ -535,9 +535,9 @@ IfcMatrix3 DerivePlaneCoordinateSpace(const TempMesh& curmesh, bool& ok, IfcFloa m.b2 = u.y; m.b3 = u.z; - m.c1 = nor.x; - m.c2 = nor.y; - m.c3 = nor.z; + m.c1 = -nor.x; + m.c2 = -nor.y; + m.c3 = -nor.z; return m; } @@ -1648,7 +1648,7 @@ void CloseWindows(ContourVector& contours, // wrong geometry may be generated. for (ContourVector::iterator it = contours.begin(), end = contours.end(); it != end; ++it) { if ((*it).IsInvalid()) { - continue; + //continue; } OpeningRefs& refs = contours_to_openings[std::distance(contours.begin(), it)]; @@ -1701,6 +1701,8 @@ void CloseWindows(ContourVector& contours, IfcVector2 last_proj; //const IfcVector2& first_proj; + IfcVector3 perp; + bool drop_this_edge = false; for (Contour::const_iterator cit = cbegin; cit != cend; ++cit, drop_this_edge = *skipit++) { const IfcVector2& proj_point = *cit; @@ -1719,6 +1721,7 @@ void CloseWindows(ContourVector& contours, } */ const IfcVector3& world_point = minv * IfcVector3(proj_point.x,proj_point.y,0.0f); + last_proj = proj_point; BOOST_FOREACH(const TempOpening* opening, refs) { @@ -1726,15 +1729,17 @@ void CloseWindows(ContourVector& contours, const IfcFloat sqdist = (world_point - other).SquareLength(); if (sqdist < best) { + // avoid self-connections + if(best < 1e-5) { + continue; + } + bestv = other; - best = sqdist; + best = sqdist; } } } - IfcVector3 diff = bestv - world_point; - diff.Normalize(); - if (drop_this_edge) { curmesh.verts.pop_back(); curmesh.verts.pop_back(); @@ -1836,7 +1841,10 @@ IfcMatrix4 ProjectOntoPlane(std::vector& out_contour, const TempMesh if(!ok) { return IfcMatrix4(); } - +#ifdef _DEBUG + const IfcFloat det = m.Determinant(); + ai_assert(fabs(det-1) < 1e-5); +#endif IfcFloat coord = 0; out_contour.reserve(in_verts.size()); @@ -2263,7 +2271,7 @@ void ProcessExtrudedAreaSolid(const IfcExtrudedAreaSolid& solid, TempMesh& resul out.push_back(in[next]); if(openings) { - if(GenerateOpenings(*conv.apply_openings,nors,temp,false, true)) { + if(GenerateOpenings(*conv.apply_openings,nors,temp,true, true)) { ++sides_with_openings; }