00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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 ¶ms, CMeshMRMGeom::CMeshBuildMRM &mrmMesh,
00066 uint numMaxMaterial);
00067
00068
00069
00075 void compileMRM( const CMesh::CMeshBuild &mbuild, std::vector<CMesh::CMeshBuild*> &bsList,
00076 const CMRMParameters ¶ms, CMeshMRMSkinnedGeom::CMeshBuildMRM &mrmMesh,
00077 uint numMaxMaterial);
00078
00079
00080
00081
00082 private:
00083
00084
00086
00087
00088 std::vector<CMRMVertex> TmpVertices;
00089
00090 std::vector<CMRMAttribute> TmpAttributes[NL3D_MRM_MAX_ATTRIB];
00091
00092 sint NumAttributes;
00093
00094 std::vector<CMRMFaceBuild> TmpFaces;
00095
00096 TEdgeMap EdgeCollapses;
00097
00098
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);
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);
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
00150 std::vector<CMRMSewingMesh> _SewingMeshes;
00151
00152 uint _CurrentLodComputed;
00153
00154
00155 bool buildMRMSewingMeshes(const CMesh::CMeshBuild &mbuild, uint nWantedLods, uint divisor);
00156
00157
00158
00159
00160 private:
00161
00162
00164
00165
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
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
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 }
00263
00264
00265 #endif // NL_MRM_BUILDER_H
00266
00267