|
Blender
V2.59
|
00001 /* 00002 * $Id: BSP_CSGMesh.h 35145 2011-02-25 10:44:20Z jesterking $ 00003 * ***** BEGIN GPL LICENSE BLOCK ***** 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software Foundation, 00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 * 00019 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00020 * All rights reserved. 00021 * 00022 * The Original Code is: all of this file. 00023 * 00024 * Contributor(s): none yet. 00025 * 00026 * ***** END GPL LICENSE BLOCK ***** 00027 */ 00028 00034 #ifndef NAN_INCLUDED_BSP_CSGMesh_h 00035 #define NAN_INCLUDED_BSP_CSGMesh_h 00036 00037 #include "BSP_MeshPrimitives.h" 00038 #include "MEM_SmartPtr.h" 00039 #include "MEM_RefCountPtr.h" 00040 #include "MEM_NonCopyable.h" 00041 #include "../extern/CSG_BooleanOps.h" 00042 00043 00044 class MT_Plane3; 00045 00046 class BSP_CSGMesh : 00047 public MEM_NonCopyable, 00048 public MEM_RefCountable 00049 { 00050 00051 public : 00052 00053 static 00054 BSP_CSGMesh * 00055 New( 00056 ); 00057 00058 bool 00059 SetVertices( 00060 std::vector<BSP_MVertex> *verts 00061 ); 00062 00063 void 00064 AddPolygon( 00065 const int * verts, 00066 int num_verts 00067 ); 00068 00069 // assumes that the face already has a plane equation 00070 void 00071 AddPolygon( 00072 const BSP_MFace &face 00073 ); 00074 00075 00076 // Allocate and build the mesh edges. 00078 00079 bool 00080 BuildEdges( 00081 ); 00082 00083 // Clean the mesh of edges. and edge pointers 00084 // This removes the circular connectivity information 00086 00087 void 00088 DestroyEdges( 00089 ); 00090 00091 // return a new separate copy of the 00092 // mesh allocated on the heap. 00093 00094 BSP_CSGMesh * 00095 NewCopy( 00096 ) const; 00097 00098 00099 // Reverse the winding order of every polygon 00100 // in the mesh and swap the planes around. 00101 00102 void 00103 Invert( 00104 ); 00105 00106 00107 // geometry access 00109 00110 std::vector<BSP_MVertex> & 00111 VertexSet( 00112 ) const ; 00113 00114 std::vector<BSP_MFace> & 00115 FaceSet( 00116 ) const ; 00117 00118 std::vector<BSP_MEdge> & 00119 EdgeSet( 00120 ) const; 00121 00122 ~BSP_CSGMesh( 00123 ); 00124 00125 // local geometry queries. 00127 00128 // face queries 00130 00131 void 00132 FaceVertices( 00133 const BSP_FaceInd & f, 00134 std::vector<BSP_VertexInd> &output 00135 ); 00136 00137 void 00138 FaceEdges( 00139 const BSP_FaceInd & f, 00140 std::vector<BSP_EdgeInd> &output 00141 ); 00142 00143 // edge queries 00145 00146 void 00147 EdgeVertices( 00148 const BSP_EdgeInd & e, 00149 std::vector<BSP_VertexInd> &output 00150 ); 00151 00152 void 00153 EdgeFaces( 00154 const BSP_EdgeInd & e, 00155 std::vector<BSP_FaceInd> &output 00156 ); 00157 00158 // vertex queries 00160 00161 void 00162 VertexEdges( 00163 const BSP_VertexInd & v, 00164 std::vector<BSP_EdgeInd> &output 00165 ); 00166 00167 void 00168 VertexFaces( 00169 const BSP_VertexInd & v, 00170 std::vector<BSP_FaceInd> &output 00171 ); 00172 00173 // Returns the edge index of the edge from v1 to v2. 00174 // Does this by searching the edge sets of v1 - but not v2. 00175 // If you are paranoid you should check both and make sure the 00176 // indices are the same. If the edge doe not exist edgeInd is empty. 00177 00178 BSP_EdgeInd 00179 FindEdge( 00180 const BSP_VertexInd &v1, 00181 const BSP_VertexInd &v2 00182 ) const; 00183 00184 00189 // make sure the edge faces have a pointer to f 00190 00191 bool 00192 SC_Face( 00193 BSP_FaceInd f 00194 ); 00195 00200 MT_Plane3 00201 FacePlane( 00202 const BSP_FaceInd &fi 00203 )const; 00204 00205 00211 void 00212 ComputeFacePlanes( 00213 ); 00214 00220 int 00221 CountTriangles( 00222 ) const; 00223 00224 private : 00225 00226 void 00227 InsertEdge( 00228 const BSP_VertexInd &v1, 00229 const BSP_VertexInd &v2, 00230 const BSP_FaceInd &f, 00231 std::vector<BSP_EdgeInd> &new_edges 00232 ); 00233 00234 00235 // Private to insure heap instantiation. 00236 00237 BSP_CSGMesh( 00238 ); 00239 00240 std::vector<BSP_MVertex> *m_verts; 00241 std::vector<BSP_MFace> *m_faces; 00242 std::vector<BSP_MEdge> *m_edges; 00243 00244 MT_Vector3 m_bbox_min; 00245 MT_Vector3 m_bbox_max; 00246 00247 }; 00248 00249 00250 #endif 00251