Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00038 #include "../extern/CSG_BooleanOps.h" 00039 #include "BSP_CSGMesh_CFIterator.h" 00040 #include "MEM_RefCountPtr.h" 00041 00042 #include "../../boolop/extern/BOP_Interface.h" 00043 #include <iostream> 00044 using namespace std; 00045 00046 #include "BSP_MeshPrimitives.h" 00047 00048 struct BSP_MeshInfo { 00049 BSP_CSGMesh *output_mesh; 00050 }; 00051 00052 using namespace std; 00053 00054 CSG_BooleanOperation * 00055 CSG_NewBooleanFunction( 00056 void 00057 ){ 00058 BSP_MeshInfo * mesh_info = new BSP_MeshInfo; 00059 CSG_BooleanOperation * output = new CSG_BooleanOperation; 00060 00061 if (mesh_info==NULL || output==NULL) return NULL; 00062 00063 mesh_info->output_mesh = NULL; 00064 output->CSG_info = mesh_info; 00065 00066 return output; 00067 } 00068 00072 int 00073 CSG_PerformBooleanOperation( 00074 CSG_BooleanOperation *operation, 00075 CSG_OperationType op_type, 00076 CSG_FaceIteratorDescriptor obAFaces, 00077 CSG_VertexIteratorDescriptor obAVertices, 00078 CSG_FaceIteratorDescriptor obBFaces, 00079 CSG_VertexIteratorDescriptor obBVertices 00080 ){ 00081 if (operation == NULL) return 0; 00082 BSP_MeshInfo * mesh_info = static_cast<BSP_MeshInfo *>(operation->CSG_info); 00083 if (mesh_info == NULL) return 0; 00084 00085 obAFaces.Reset(obAFaces.it); 00086 obBFaces.Reset(obBFaces.it); 00087 obAVertices.Reset(obAVertices.it); 00088 obBVertices.Reset(obBVertices.it); 00089 00090 BoolOpType boolType; 00091 00092 switch( op_type ) { 00093 case e_csg_union: 00094 boolType = BOP_UNION; 00095 break; 00096 case e_csg_difference: 00097 boolType = BOP_DIFFERENCE; 00098 break; 00099 default: 00100 boolType = BOP_INTERSECTION; 00101 break; 00102 } 00103 00104 BoolOpState boolOpResult; 00105 try { 00106 boolOpResult = BOP_performBooleanOperation( boolType, 00107 (BSP_CSGMesh**) &(mesh_info->output_mesh), 00108 obAFaces, obAVertices, obBFaces, obBVertices); 00109 } 00110 catch(...) { 00111 return 0; 00112 } 00113 00114 switch (boolOpResult) { 00115 case BOP_OK: return 1; 00116 case BOP_NO_SOLID: return -2; 00117 case BOP_ERROR: return 0; 00118 default: return 1; 00119 } 00120 } 00121 00122 int 00123 CSG_OutputFaceDescriptor( 00124 CSG_BooleanOperation * operation, 00125 CSG_FaceIteratorDescriptor * output 00126 ){ 00127 if (operation == NULL) return 0; 00128 BSP_MeshInfo * mesh_info = static_cast<BSP_MeshInfo *>(operation->CSG_info); 00129 00130 if (mesh_info == NULL) return 0; 00131 if (mesh_info->output_mesh == NULL) return 0; 00132 00133 BSP_CSGMesh_FaceIt_Construct(mesh_info->output_mesh,output); 00134 return 1; 00135 } 00136 00137 00138 int 00139 CSG_OutputVertexDescriptor( 00140 CSG_BooleanOperation * operation, 00141 CSG_VertexIteratorDescriptor *output 00142 ){ 00143 if (operation == NULL) return 0; 00144 BSP_MeshInfo * mesh_info = static_cast<BSP_MeshInfo *>(operation->CSG_info); 00145 00146 if (mesh_info == NULL) return 0; 00147 if (mesh_info->output_mesh == NULL) return 0; 00148 00149 BSP_CSGMeshVertexIt_Construct(mesh_info->output_mesh,output); 00150 return 1; 00151 } 00152 00153 void 00154 CSG_FreeVertexDescriptor( 00155 CSG_VertexIteratorDescriptor * v_descriptor 00156 ){ 00157 BSP_CSGMesh_VertexIt_Destruct(v_descriptor); 00158 } 00159 00160 00161 void 00162 CSG_FreeFaceDescriptor( 00163 CSG_FaceIteratorDescriptor * f_descriptor 00164 ){ 00165 BSP_CSGMesh_FaceIt_Destruct(f_descriptor); 00166 } 00167 00168 00169 void 00170 CSG_FreeBooleanOperation( 00171 CSG_BooleanOperation *operation 00172 ){ 00173 if (operation != NULL) { 00174 BSP_MeshInfo * mesh_info = static_cast<BSP_MeshInfo *>(operation->CSG_info); 00175 00176 delete (mesh_info->output_mesh); 00177 delete(mesh_info); 00178 delete(operation); 00179 } 00180 } 00181