===Tools===
authorKen Hughes <khughes@pacific.edu>
Sat, 10 Jun 2006 15:47:19 +0000 (15:47 +0000)
committerKen Hughes <khughes@pacific.edu>
Sat, 10 Jun 2006 15:47:19 +0000 (15:47 +0000)
Adding back some code to booleans that got lost in the Orange merge.

I've also added back the code which checked that meshes were solid
("manifolds") but have the actual check in
intern/boolop/intern/BOP_Interface.cpp, since from my testing it was
not causing crashes or hangs.  It *can* give odd results depending on
what you're trying to intersect, but seems useful.  Additionally, since
existing bugs in the current code can create non-solid/non-manifold
meshes, seems hypocritical to create a mesh that can't later be used in
another boolean operation.

intern/boolop/intern/BOP_Interface.cpp
intern/boolop/intern/BOP_Mesh.cpp
intern/boolop/intern/BOP_Mesh.h
intern/bsp/intern/CSG_BooleanOps.cpp

index 02945340d55e25dd34c0405a764e154955b1597f..518ea69982cae76d6f3dd7744d624ae645cdf33f 100644 (file)
@@ -121,6 +121,12 @@ BoolOpState BOP_performBooleanOperation(BoolOpType                    opType,
        // Add B-mesh into C-mesh
        BOP_addMesh(&meshC, &meshBFacesId, &materials, obBProps, obBFaces, obBVertices, invertMeshB);
 
+       // for now, allow operations on non-manifold (non-solid) meshes
+#if 0
+       if (!meshC.isClosedMesh())
+               return BOP_NO_SOLID;
+#endif
+
        // Perform the intersection boolean operation.
        BoolOpState result = BOP_intersectionBoolOp(&meshC, &meshAFacesId, &meshBFacesId, 
                                                                                                invertMeshA, invertMeshB);
index 595ccae6b934084ba099fb078a92c855d5372fa5..6afd1caabaf2fbb9f71d9f03f9b95d499b08c4cf 100644 (file)
@@ -555,6 +555,23 @@ BOP_Index BOP_Mesh::replaceVertexIndex(BOP_Index oldIndex, BOP_Index newIndex)
        return newIndex;
 }
 
+bool BOP_Mesh::isClosedMesh()
+{
+        for(unsigned int i=0; i<m_edges.size(); i++) {
+                        BOP_Edge *edge = m_edges[i];
+                        BOP_Indexs faces = edge->getFaces();
+                        unsigned int count = 0;
+                        const BOP_IT_Indexs facesEnd = faces.end();
+                        for(BOP_IT_Indexs it = faces.begin();it!=facesEnd;it++) {
+                                        if (m_faces[*it]->getTAG()!=BROKEN)
+                                                        count++;
+                        }
+
+                        if ((count%2)!=0) return false;
+        }
+
+        return true;
+}
 
 
 /** ***************************************************************************
index 644f9ab691c283afb2efd6e6346c3a0faa92a4c0..d4403facde7ffc1dc0a3e7e653fc18c2b0604d39 100644 (file)
@@ -83,7 +83,8 @@ public:
        unsigned int getNumVertexs(BOP_TAG tag);
        unsigned int getNumFaces(BOP_TAG tag);
        BOP_Index replaceVertexIndex(BOP_Index oldIndex, BOP_Index newIndex);
-       
+       bool BOP_Mesh::isClosedMesh();
+
        // Debug functions
        void print();
        void printFormat();
index a0b4dc0078d7f1a8bb68bfb436f31c784febdea9..1a3a149adebcdcb29599d0ffdd6e0d3a081d3e20 100755 (executable)
@@ -118,8 +118,6 @@ CSG_PerformBooleanOperation(
        BSP_MeshInfo * mesh_info = static_cast<BSP_MeshInfo *>(operation->CSG_info);
        if (mesh_info == NULL) return 0;
 
-       bool success = 1;
-
        obAFaces.Reset(obAFaces.it);
        obBFaces.Reset(obBFaces.it);
        obAVertices.Reset(obAVertices.it);
@@ -139,8 +137,9 @@ CSG_PerformBooleanOperation(
          break;
        }
 
+       BoolOpState boolOpResult;
        try {
-       BOP_performBooleanOperation( boolType,
+       boolOpResult = BOP_performBooleanOperation( boolType,
                                     mesh_info->output_descriptor,
                                     (BSP_CSGMesh**) &(mesh_info->output_mesh),
                                         mesh_info->obB_descriptor,
@@ -155,7 +154,12 @@ CSG_PerformBooleanOperation(
                return 0;
        }
 
-       return success;
+       switch (boolOpResult) {
+       case BOP_OK: return 1;
+       case BOP_NO_SOLID: return -2;
+       case BOP_ERROR: return 0;
+       default: return 1;
+       }
 }
 
        int