diff --git a/libsrc/csg/identify.cpp b/libsrc/csg/identify.cpp index e3086a3b..9ebb985a 100644 --- a/libsrc/csg/identify.cpp +++ b/libsrc/csg/identify.cpp @@ -1245,13 +1245,20 @@ BuildSurfaceElements (Array & segs, (mesh.GetIdentifications().Get (s2[0], s1[1], nr) && mesh.GetIdentifications().Get (s2[1], s1[0], nr))) { + Vec<3> ns = surf->GetNormalVector (mesh[s1[0]]); + + Vec<3> t1 = mesh[s1[1]] - mesh[s1[0]]; + Vec<3> t2 = mesh[s2[1]] - mesh[s2[0]]; + Vec<3> nst1 = Cross(t1, ns); + Vec<3> nst2 = Cross(t2, ns); + Vec<3> dvec = Center(mesh[s1[0]], mesh[s1[1]])-Center(mesh[s2[0]], mesh[s2[1]]); + if (nst1 * dvec < 0) continue; + Element2d el(s1[0], s1[1], s2[0], s2[1]); Vec<3> n = Cross (mesh[el[1]] - mesh[el[0]], mesh[el[3]] - mesh[el[0]]); - Vec<3> ns = surf->GetNormalVector (mesh[el[0]]); - if (n * ns < 0) { Swap (el.PNum(1), el.PNum(2));