00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_MRM_BUILDER_H
00027 #define NL_MRM_BUILDER_H
00028
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/uv.h"
00031 #include "3d/mrm_mesh.h"
00032 #include "3d/mrm_internal.h"
00033 #include "3d/mrm_parameters.h"
00034 #include "3d/mesh.h"
00035 #include "3d/mesh_mrm.h"
00036 #include <map>
00037
00038
00039 namespace NL3D
00040 {
00041
00042
00043
00044
00051 class CMRMBuilder
00052 {
00053 public:
00054
00056 CMRMBuilder();
00057
00058
00059
00065 void compileMRM( const CMesh::CMeshBuild &mbuild, std::vector<CMesh::CMeshBuild*> &bsList,
00066 const CMRMParameters ¶ms, CMeshMRMGeom::CMeshBuildMRM &mrmMesh,
00067 uint numMaxMaterial);
00068
00069
00070
00071
00072 private:
00073
00074
00076
00077
00078 std::vector<CMRMVertex> TmpVertices;
00079
00080 std::vector<CMRMAttribute> TmpAttributes[NL3D_MRM_MAX_ATTRIB];
00081
00082 sint NumAttributes;
00083
00084 std::vector<CMRMFaceBuild> TmpFaces;
00085
00086 TEdgeMap EdgeCollapses;
00087
00088
00089 bool _Skinned;
00091 CMRMParameters::TSkinReduction _SkinReduction;
00092
00093
00094
00095
00097
00098 bool vertexHasOneWedge(sint numvertex);
00099 bool vertexHasOneMaterial(sint numvertex);
00100 bool vertexContinue(sint numvertex);
00101 bool vertexClosed(sint numvertex);
00102 float getDeltaFaceNormals(sint numvertex);
00103 bool edgeContinue(const CMRMEdge &edge);
00104 bool edgeNearUniqueMatFace(const CMRMEdge &edge);
00105 float computeEdgeCost(const CMRMEdge &edge);
00106
00107
00108
00110
00111 bool faceShareWedges(CMRMFaceBuild *face, sint attribId, sint numVertex1, sint numVertex2);
00112 void insertFaceIntoEdgeList(CMRMFaceBuild &tmpf);
00113 void removeFaceFromEdgeList(CMRMFaceBuild &f);
00114 sint collapseEdge(const CMRMEdge &edge);
00115 sint followVertex(sint i);
00116 sint followWedge(sint attribId, sint i);
00117 CMesh::CSkinWeight collapseSkinWeight(const CMesh::CSkinWeight &sw1, const CMesh::CSkinWeight &sw2, float InterValue) const;
00118
00119
00120
00122
00123 void init(const CMRMMesh &baseMesh);
00124 void collapseEdges(sint nWantedFaces);
00125 void makeLODMesh(CMRMMeshGeom &lodMesh);
00126 void saveCoarserMesh(CMRMMesh &coarserMesh);
00128 void makeFromMesh(const CMRMMesh &baseMesh, CMRMMeshGeom &lodMesh, CMRMMesh &coarserMesh, sint nWantedFaces);
00129
00130
00131
00132 void computeBsVerticesAttributes(std::vector<CMRMMesh> &srcBsMeshs, std::vector<CMRMMesh> &srcBsMeshsMod);
00133 void makeCoarserBS (std::vector<CMRMBlendShape> &csBsMeshs);
00134
00135
00136 private:
00137
00138
00140
00141
00142 struct CGeomPred
00143 {
00144 bool operator()(const CMRMWedgeGeom &a, const CMRMWedgeGeom &b) const
00145 {
00146 if(a.Start!=b.Start)
00147 return a.Start<b.Start;
00148 return a.End<b.End;
00149 }
00150 };
00151
00152
00153 typedef std::map<CMRMWedgeGeom, sint, CGeomPred> TGeomMap;
00154 TGeomMap _GeomMap;
00155
00156
00157
00159
00162 void buildBlendShapes (CMRMMesh &baseMesh, std::vector<CMesh::CMeshBuild*> &bsList, uint32 VertexFlags);
00163
00170 void buildAllLods( const CMRMMesh &baseMesh, std::vector<CMRMMeshGeom> &lodMeshs,
00171 uint nWantedLods= 10, uint divisor= 50 );
00172
00176 void buildFinalMRM(std::vector<CMRMMeshGeom> &lodMeshs, CMRMMeshFinal &finalMRM);
00177
00178
00179
00180
00181
00182 private:
00183
00184
00186
00187
00188
00190 struct CAttributeKey
00191 {
00192 sint VertexId;
00193 CVectorH Attribute;
00194
00195 bool operator<(const CAttributeKey &o) const
00196 {
00197 if(VertexId!=o.VertexId)
00198 return VertexId<o.VertexId;
00199 return Attribute<o.Attribute;
00200 }
00201 };
00202 typedef std::map<CAttributeKey, sint> TAttributeMap;
00203 TAttributeMap _AttributeMap[NL3D_MRM_MAX_ATTRIB];
00204 sint findInsertAttributeInBaseMesh(CMRMMesh &baseMesh, sint attId, sint vertexId, const CVectorH &att);
00205 sint findInsertNormalInBaseMesh(CMRMMesh &baseMesh, sint attId, sint vertexId, const CVector &normal);
00206 sint findInsertColorInBaseMesh(CMRMMesh &baseMesh, sint attId, sint vertexId, CRGBA col);
00207 sint findInsertUvwInBaseMesh(CMRMMesh &baseMesh, sint attId, sint vertexId, const NLMISC::CUVW &uvw);
00208 CRGBA attToColor(const CVectorH &att) const;
00209 NLMISC::CUVW attToUvw(const CVectorH &att) const;
00210
00211
00215 uint32 buildMrmBaseMesh(const CMesh::CMeshBuild &mbuild, CMRMMesh &baseMesh);
00216
00221 void buildMeshBuildMrm(const CMRMMeshFinal &finalMRM, CMeshMRMGeom::CMeshBuildMRM &mbuild, uint32 vbFlags, uint32 nbMats, const CMesh::CMeshBuild &mb);
00222
00223
00224 void normalizeBaseMeshSkin(CMRMMesh &baseMesh) const;
00225 CMesh::CSkinWeight normalizeSkinWeight(const CMesh::CSkinWeight &sw) const;
00226
00227
00228
00229 };
00230
00231
00232 }
00233
00234
00235 #endif // NL_MRM_BUILDER_H
00236
00237