00001 00005 /* Copyright, 2000 Nevrax Ltd. 00006 * 00007 * This file is part of NEVRAX NEL. 00008 * NEVRAX NEL is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2, or (at your option) 00011 * any later version. 00012 00013 * NEVRAX NEL is distributed in the hope that it will be useful, but 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * General Public License for more details. 00017 00018 * You should have received a copy of the GNU General Public License 00019 * along with NEVRAX NEL; see the file COPYING. If not, write to the 00020 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00021 * MA 02111-1307, USA. 00022 */ 00023 00024 #ifndef NL_MRM_MESH_H 00025 #define NL_MRM_MESH_H 00026 00027 #include "nel/misc/types_nl.h" 00028 #include "nel/misc/debug.h" 00029 #include "nel/misc/vector_h.h" 00030 #include "nel/misc/vector.h" 00031 #include "nel/3d/mesh.h" 00032 #include <vector> 00033 00034 00035 namespace NL3D 00036 { 00037 00038 00039 using NLMISC::CVector; 00040 using NLMISC::CVectorH; 00041 00042 00043 // *************************************************************************** 00044 #define NL3D_MRM_MAX_ATTRIB 12 00045 00046 00047 // *************************************************************************** 00054 struct CMRMCorner 00055 { 00056 // The id of the vertex. 00057 sint Vertex; 00058 // The ids of the wedges. Points on Attributes of the mesh. 00059 sint Attributes[NL3D_MRM_MAX_ATTRIB]; 00060 00061 // For CMRMMeshFinal computing, wedge ids. 00062 sint WedgeStartId; 00063 sint WedgeEndId; 00064 sint WedgeGeomId; 00065 }; 00066 00067 00068 // *************************************************************************** 00075 struct CMRMFace 00076 { 00077 public: 00078 // The 3 corner indices of the face. 00079 CMRMCorner Corner[3]; 00080 // The id of the material. Used for material boundaries. 00081 sint MaterialId; 00082 }; 00083 00084 00085 // *************************************************************************** 00093 class CMRMBlendShape 00094 { 00095 public: 00096 // The vertices of the MRMMesh. 00097 std::vector<CVector> Vertices; 00098 // The attributes of the MRMMesh. 00099 std::vector<CVectorH> Attributes[NL3D_MRM_MAX_ATTRIB]; 00100 // The number of used attributes of the MRMMesh. 00101 sint NumAttributes; 00102 }; 00103 00104 00105 // *************************************************************************** 00113 class CMRMMesh 00114 { 00115 public: 00116 // The vertices of the MRMMesh. 00117 std::vector<CVector> Vertices; 00118 // The skinWeights of the MRMMesh. same size than Vertices. 00119 std::vector<CMesh::CSkinWeight> SkinWeights; 00120 // The link to the original meshInterface vertex. same size than Vertices. 00121 std::vector<CMesh::CInterfaceLink> InterfaceLinks; 00122 // The attributes of the MRMMesh. 00123 std::vector<CVectorH> Attributes[NL3D_MRM_MAX_ATTRIB]; 00124 // The number of used attributes of the MRMMesh. 00125 sint NumAttributes; 00126 // The faces of the MRMMesh. 00127 std::vector<CMRMFace> Faces; 00128 00129 00131 std::vector<CMRMBlendShape> BlendShapes; 00132 00133 00134 public: 00136 CMRMMesh(); 00137 00138 }; 00139 00140 00141 // *************************************************************************** 00149 class CMRMMeshGeom : public CMRMMesh 00150 { 00151 public: 00153 std::vector<CMRMFace> CoarserFaces; 00154 00155 00156 CMRMMeshGeom &operator=(const CMRMMesh &o) 00157 { 00158 (CMRMMesh&)(*this)= o; 00159 // copy faces into CoarserFaces. 00160 CoarserFaces= Faces; 00161 return *this; 00162 } 00163 00164 public: 00166 CMRMMeshGeom() {} 00167 }; 00168 00169 00170 // *************************************************************************** 00178 struct CMRMWedgeGeom 00179 { 00181 uint32 Start; 00183 uint32 End; 00184 00185 00186 void serial(NLMISC::IStream &f) 00187 { 00188 f.serial(Start, End); 00189 } 00190 }; 00191 00192 00193 // *************************************************************************** 00201 class CMRMMeshFinal 00202 { 00203 public: 00204 00205 // An wedge value (vertex + all attribs). 00206 struct CWedge 00207 { 00208 CWedge(); 00209 CMesh::CSkinWeight VertexSkin; 00210 // Number of matrix this wedge use. 00211 uint NSkinMatUsed; 00212 CVector Vertex; 00213 CVectorH Attributes[NL3D_MRM_MAX_ATTRIB]; 00214 static uint NumAttributesToCompare; 00215 static bool CompareSkinning; 00216 00217 bool operator<(const CWedge &o) const 00218 { 00219 if(Vertex!=o.Vertex) 00220 return Vertex<o.Vertex; 00221 else 00222 { 00223 nlassert(NumAttributesToCompare<=NL3D_MRM_MAX_ATTRIB); 00224 for(uint i=0; i<NumAttributesToCompare; i++) 00225 { 00226 if(Attributes[i]!=o.Attributes[i]) 00227 return Attributes[i]<o.Attributes[i]; 00228 } 00229 } 00230 00231 // They may be different by their skin Weight. 00232 if(CompareSkinning) 00233 { 00234 for(uint i=0; i<NL3D_MESH_SKINNING_MAX_MATRIX; i++) 00235 { 00236 if( VertexSkin.MatrixId[i] != o.VertexSkin.MatrixId[i] ) 00237 return VertexSkin.MatrixId[i] < o.VertexSkin.MatrixId[i]; 00238 if( VertexSkin.Weights[i] != o.VertexSkin.Weights[i] ) 00239 return VertexSkin.Weights[i] < o.VertexSkin.Weights[i]; 00240 } 00241 } 00242 00243 // else they are equal. 00244 return false; 00245 } 00246 }; 00247 00248 // a face. 00249 struct CFace 00250 { 00252 sint WedgeId[3]; 00254 sint MaterialId; 00255 }; 00256 00257 00258 // A LOD information for the final MRM representation. 00259 struct CLod 00260 { 00262 sint NWedges; 00264 std::vector<CFace> Faces; 00266 std::vector<CMRMWedgeGeom> Geomorphs; 00267 }; 00268 00269 00270 struct CMRMBlendShapeFinal 00271 { 00272 std::vector<CWedge> Wedges; 00273 }; 00274 00275 public: 00279 std::vector<CWedge> Wedges; 00281 sint NGeomSpace; 00283 sint NumAttributes; 00285 bool Skinned; 00287 std::vector<CLod> Lods; 00288 00289 00290 std::vector<CMRMBlendShapeFinal> MRMBlendShapesFinals; 00291 00292 00293 CMRMMeshFinal() 00294 { 00295 NumAttributes= 0; 00296 } 00297 00298 00300 sint findInsertWedge(const CWedge &w); 00301 00302 00303 void reset() 00304 { 00305 Wedges.clear(); 00306 _WedgeMap.clear(); 00307 Lods.clear(); 00308 NumAttributes= 0; 00309 } 00310 00311 00312 private: 00313 // The map of wedges to wedges index. 00314 typedef std::map<CWedge, sint> TWedgeMap; 00315 TWedgeMap _WedgeMap; 00316 00317 }; 00318 00319 00320 } // NL3D 00321 00322 00323 #endif // NL_MRM_MESH_H 00324 00325 /* End of mrm_mesh.h */
1.6.1