mrm_builder.h

Go to the documentation of this file.
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_BUILDER_H
00025 #define NL_MRM_BUILDER_H
00026 
00027 #include "nel/misc/types_nl.h"
00028 #include "nel/misc/uv.h"
00029 #include "nel/3d/mrm_mesh.h"
00030 #include "nel/3d/mrm_internal.h"
00031 #include "nel/3d/mrm_parameters.h"
00032 #include "nel/3d/mesh.h"
00033 #include "nel/3d/mesh_mrm.h"
00034 #include "nel/3d/mesh_mrm_skinned.h"
00035 #include <map>
00036 
00037 
00038 namespace NL3D
00039 {
00040 
00041 
00042 
00043 // ***************************************************************************
00050 class CMRMBuilder
00051 {
00052 public:
00053 
00055     CMRMBuilder();
00056 
00057 
00058 
00064     void    compileMRM( const CMesh::CMeshBuild &mbuild, std::vector<CMesh::CMeshBuild*> &bsList,
00065                         const CMRMParameters &params, CMeshMRMGeom::CMeshBuildMRM &mrmMesh,
00066                         uint numMaxMaterial);
00067 
00068 
00069 
00075     void    compileMRM( const CMesh::CMeshBuild &mbuild, std::vector<CMesh::CMeshBuild*> &bsList,
00076                         const CMRMParameters &params, CMeshMRMSkinnedGeom::CMeshBuildMRM &mrmMesh,
00077                         uint numMaxMaterial);
00078 
00079 
00080 
00081 // ****************************
00082 private:
00083 // Mesh Level Part.
00084 
00086     // @{
00087     // The vertices of the MRMMesh.
00088     std::vector<CMRMVertex>     TmpVertices;
00089     // The attributes of the MRMMesh.
00090     std::vector<CMRMAttribute>  TmpAttributes[NL3D_MRM_MAX_ATTRIB];
00091     // The number of used attributes of the MRMMesh.
00092     sint                        NumAttributes;
00093     // The faces of the MRMMesh.
00094     std::vector<CMRMFaceBuild>  TmpFaces;
00095     // Ordered list of Edge collapse.
00096     TEdgeMap                    EdgeCollapses;
00097 
00098     // Say if the current build must compute skinning information.
00099     bool                        _Skinned;
00101     CMRMParameters::TSkinReduction  _SkinReduction;
00102 
00103     // @}
00104 
00105 
00107     // @{
00108     bool    vertexHasOneWedge(sint numvertex);
00109     bool    vertexHasOneMaterial(sint numvertex);
00110     bool    vertexContinue(sint numvertex);
00111     bool    vertexClosed(sint numvertex);
00112     float   getDeltaFaceNormals(sint numvertex);    // return a positive value of Sum(|DeltaNormals|) / NNormals.
00113     bool    edgeContinue(const CMRMEdge &edge);
00114     bool    edgeNearUniqueMatFace(const CMRMEdge &edge);
00115     float   computeEdgeCost(const CMRMEdge &edge);
00116     // @}
00117 
00118 
00120     // @{
00121     bool    faceShareWedges(CMRMFaceBuild *face, sint attribId, sint numVertex1, sint numVertex2);
00122     void    insertFaceIntoEdgeList(CMRMFaceBuild &tmpf);
00123     void    removeFaceFromEdgeList(CMRMFaceBuild &f);
00124     sint    collapseEdge(const CMRMEdge &edge); // return num of deleted faces.
00125     sint    followVertex(sint i);
00126     sint    followWedge(sint attribId, sint i);
00127     CMesh::CSkinWeight  collapseSkinWeight(const CMesh::CSkinWeight &sw1, const CMesh::CSkinWeight &sw2, float InterValue) const;
00128     // @}
00129 
00130 
00132     // @{
00133     void    init(const CMRMMesh &baseMesh);
00134     void    collapseEdges(sint nWantedFaces);
00135     void    makeLODMesh(CMRMMeshGeom &lodMesh);
00136     void    saveCoarserMesh(CMRMMesh &coarserMesh);
00138     void    makeFromMesh(const CMRMMesh &baseMesh, CMRMMeshGeom &lodMesh, CMRMMesh &coarserMesh, sint nWantedFaces);
00139     // @}
00140 
00141 
00142     void    computeBsVerticesAttributes(std::vector<CMRMMesh> &srcBsMeshs, std::vector<CMRMMesh> &srcBsMeshsMod);
00143     void    makeCoarserBS (std::vector<CMRMBlendShape> &csBsMeshs);
00144 
00145 
00147     // @{
00148     bool                        _HasMeshInterfaces;
00149     // the sewing meshes
00150     std::vector<CMRMSewingMesh> _SewingMeshes;
00151     // The current Lod
00152     uint                        _CurrentLodComputed;
00153 
00154     // true if the build has some Mesh sewing interface setup.
00155     bool    buildMRMSewingMeshes(const CMesh::CMeshBuild &mbuild, uint nWantedLods, uint divisor);
00156 
00157     // @}
00158 
00159 
00160 private:
00161 // MRM Level Part.
00162 
00164     // @{
00165     // Our comparator of CMRMWedgeGeom.
00166     struct  CGeomPred
00167     {
00168         bool    operator()(const CMRMWedgeGeom &a, const CMRMWedgeGeom &b) const
00169         {
00170             if(a.Start!=b.Start)
00171                 return a.Start<b.Start;
00172             return a.End<b.End;
00173         }
00174     };
00175 
00176     // The map of geomorph. for one LOD only;
00177     typedef std::map<CMRMWedgeGeom, sint, CGeomPred>        TGeomMap;
00178     TGeomMap            _GeomMap;
00179     // @}
00180 
00181 
00183     // @{
00186     void buildBlendShapes (CMRMMesh &baseMesh, std::vector<CMesh::CMeshBuild*> &bsList, uint32 VertexFlags);
00187 
00194     void    buildAllLods(   const CMRMMesh &baseMesh, std::vector<CMRMMeshGeom> &lodMeshs,
00195                             uint nWantedLods= 10, uint divisor= 50 );
00196 
00200     void    buildFinalMRM(std::vector<CMRMMeshGeom> &lodMeshs, CMRMMeshFinal &finalMRM);
00201 
00202     // @}
00203 
00204 
00205 
00206 private:
00207 // Interface to MeshBuild Part.
00208 
00210     // @{
00211 
00212 
00214     struct  CAttributeKey
00215     {
00216         sint        VertexId;
00217         CVectorH    Attribute;
00218 
00219         bool    operator<(const CAttributeKey &o) const
00220         {
00221             if(VertexId!=o.VertexId)
00222                 return VertexId<o.VertexId;
00223             return Attribute<o.Attribute;
00224         }
00225     };
00226     typedef std::map<CAttributeKey, sint>       TAttributeMap;
00227     TAttributeMap       _AttributeMap[NL3D_MRM_MAX_ATTRIB];
00228     sint            findInsertAttributeInBaseMesh(CMRMMesh &baseMesh, sint attId, sint vertexId, const CVectorH &att);
00229     sint            findInsertNormalInBaseMesh(CMRMMesh &baseMesh, sint attId, sint vertexId, const CVector &normal);
00230     sint            findInsertColorInBaseMesh(CMRMMesh &baseMesh, sint attId, sint vertexId, CRGBA col);
00231     sint            findInsertUvwInBaseMesh(CMRMMesh &baseMesh, sint attId, sint vertexId, const NLMISC::CUVW &uvw);
00232     CRGBA           attToColor(const CVectorH &att) const;
00233     NLMISC::CUVW    attToUvw(const CVectorH &att) const;
00234 
00235 
00239     uint32          buildMrmBaseMesh(const CMesh::CMeshBuild &mbuild, CMRMMesh &baseMesh);
00240 
00245     void            buildMeshBuildMrm(const CMRMMeshFinal &finalMRM, CMeshMRMGeom::CMeshBuildMRM &mbuild, uint32 vbFlags, uint32 nbMats, const CMesh::CMeshBuild &mb);
00246 
00251     void            buildMeshBuildMrm(const CMRMMeshFinal &finalMRM, CMeshMRMSkinnedGeom::CMeshBuildMRM &mbuild, uint32 vbFlags, uint32 nbMats, const CMesh::CMeshBuild &mb);
00252 
00253 
00254     void            normalizeBaseMeshSkin(CMRMMesh &baseMesh) const;
00255     CMesh::CSkinWeight  normalizeSkinWeight(const CMesh::CSkinWeight &sw) const;
00256 
00257     // @}
00258 
00259 };
00260 
00261 
00262 } // NL3D
00263 
00264 
00265 #endif // NL_MRM_BUILDER_H
00266 
00267 /* End of mrm_builder.h */

Generated on Thu Jan 7 08:26:19 2010 for NeL by  doxygen 1.6.1