00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_MRM_INTERNAL_H
00027 #define NL_MRM_INTERNAL_H
00028
00029 #include "nel/misc/types_nl.h"
00030 #include "3d/mrm_mesh.h"
00031
00032
00033 namespace NL3D
00034 {
00035
00036
00037 struct CLinearEquation
00038 {
00039 struct Element
00040 {
00041 uint32 index;
00042 float factor;
00043
00044 Element(uint32 i, float f)
00045 {
00046 index = i;
00047 factor = f;
00048 }
00049 };
00050
00051 std::vector<Element> Elts;
00052
00053 void init(uint32 ii)
00054 {
00055 clear();
00056 Elts.push_back (Element(ii, 1.0f));
00057 }
00058
00059
00060 void add(CLinearEquation& eq, float factor)
00061 {
00062 Element tmp(0, 0.0f);
00063
00064 for (uint32 i = 0; i < eq.Elts.size(); ++i)
00065 {
00066 tmp.index = eq.Elts[i].index;
00067 tmp.factor = factor * eq.Elts[i].factor;
00068 Elts.push_back (tmp);
00069 }
00070 }
00071
00072
00073 void mul (float factor)
00074 {
00075 for (uint32 i = 0; i < Elts.size(); ++i)
00076 Elts[i].factor *= factor;
00077 }
00078
00079 void clear()
00080 {
00081 NLMISC::contReset (Elts);
00082 }
00083 };
00084
00085
00092 struct CMRMVertex
00093 {
00094 public:
00095
00096 CVector Current,Original;
00097 std::vector<CVector> BSCurrent;
00098
00099 CMesh::CSkinWeight CurrentSW, OriginalSW;
00100 std::vector<sint> SharedFaces;
00101 sint CollapsedTo;
00102
00103 sint CoarserIndex;
00104
00105
00106 CMesh::CInterfaceLink InterfaceLink;
00107
00108 public:
00109 CMRMVertex() {CollapsedTo=-1;}
00110 };
00111
00112
00113
00120 struct CMRMAttribute
00121 {
00122 public:
00123 CVectorH Current,Original;
00124 std::vector<CVectorH> BSCurrent;
00125 sint CollapsedTo;
00126
00127 sint CoarserIndex;
00128
00129 public:
00130
00131 sint InterpolatedFace;
00132 sint NbSharedFaces;
00133 bool Shared;
00134
00135
00136
00137 public:
00138 CMRMAttribute() {CollapsedTo=-1;}
00139 };
00140
00141
00142
00149 struct CMRMEdge
00150 {
00151 sint v0,v1;
00152 CMRMEdge() {}
00153 CMRMEdge(sint a, sint b) {v0= a; v1=b;}
00154 bool operator==(const CMRMEdge &o) const
00155 {
00156
00157 return (v0==o.v0 && v1==o.v1) || (v0==o.v1 && v1==o.v0);
00158 }
00159 bool operator<(const CMRMEdge &o) const
00160 {
00161
00162 sint max0= std::max(v0,v1);
00163 sint min0= std::min(v0,v1);
00164 sint max1= std::max(o.v0,o.v1);
00165 sint min1= std::min(o.v0,o.v1);
00166 if(max0!=max1)
00167 return max0<max1;
00168 else
00169 return min0<min1;
00170 }
00171 };
00172
00173
00174
00175 struct CMRMFaceBuild;
00182 struct CMRMEdgeFace : public CMRMEdge
00183 {
00184 CMRMFaceBuild *Face;
00185 CMRMEdgeFace();
00186 CMRMEdgeFace(sint a, sint b, CMRMFaceBuild *f)
00187 {
00188 v0=a; v1=b;
00189 Face= f;
00190 }
00191 CMRMEdgeFace(const CMRMEdge &e, CMRMFaceBuild *f) : CMRMEdge(e)
00192 {
00193 Face= f;
00194 }
00195
00196 };
00197
00198
00199
00206 typedef std::multimap<float, CMRMEdgeFace> TEdgeMap;
00207 typedef TEdgeMap::iterator ItEdgeMap;
00208
00209
00210
00217 struct CMRMFaceBuild : public CMRMFace
00218 {
00219 public:
00220
00221
00222 CVectorH InterpolatedAttribute;
00223 std::vector<CVectorH> BSInterpolated;
00224
00225
00226 bool Deleted;
00227
00228 ItEdgeMap It0, It1, It2;
00229
00230 bool ValidIt0, ValidIt1, ValidIt2;
00231
00232
00233 public:
00234 CMRMFaceBuild()
00235 {
00236 Deleted=false;
00237 ValidIt0= ValidIt1= ValidIt2= false;
00238 }
00239 CMRMFaceBuild &operator=(const CMRMFace &f)
00240 {
00241 (CMRMFace &)(*this)=f;
00242 return *this;
00243 }
00244
00245
00246
00247 sint getAssociatedEdge(const CMRMEdge &edge) const
00248 {
00249 sint v0= edge.v0;
00250 sint v1= edge.v1;
00251 if(Corner[0].Vertex==v0 && Corner[1].Vertex==v1) return 0;
00252 if(Corner[0].Vertex==v1 && Corner[1].Vertex==v0) return 0;
00253 if(Corner[1].Vertex==v0 && Corner[2].Vertex==v1) return 1;
00254 if(Corner[1].Vertex==v1 && Corner[2].Vertex==v0) return 1;
00255 if(Corner[0].Vertex==v0 && Corner[2].Vertex==v1) return 2;
00256 if(Corner[0].Vertex==v1 && Corner[2].Vertex==v0) return 2;
00257 return -1;
00258 }
00259 bool hasEdge(const CMRMEdge &edge) const
00260 {
00261 return getAssociatedEdge(edge)!=-1;
00262 }
00263 CMRMEdge getEdge(sint eId) const
00264 {
00265 if(eId==0) return CMRMEdge(Corner[0].Vertex, Corner[1].Vertex);
00266 if(eId==1) return CMRMEdge(Corner[1].Vertex, Corner[2].Vertex);
00267 if(eId==2) return CMRMEdge(Corner[2].Vertex, Corner[0].Vertex);
00268 nlstop;
00269 return CMRMEdge(-1,-1);
00270 }
00271 void invalidAllIts(TEdgeMap &edgeMap)
00272 {
00273 ValidIt0= ValidIt1= ValidIt2= false;
00274 It0= edgeMap.end();
00275 It1= edgeMap.end();
00276 It2= edgeMap.end();
00277 }
00278 void invalidEdgeIt(const CMRMEdge &e, TEdgeMap &edgeMap)
00279 {
00280 if(e== getEdge(0))
00281 It0= edgeMap.end(), ValidIt0= false;
00282 else if(e== getEdge(1))
00283 It1= edgeMap.end(), ValidIt1= false;
00284 else if(e== getEdge(2))
00285 It2= edgeMap.end(), ValidIt2= false;
00286 else nlstop;
00287 }
00288 bool validEdgeIt(const CMRMEdge &e)
00289 {
00290 if(e== getEdge(0)) return ValidIt0;
00291 if(e== getEdge(1)) return ValidIt1;
00292 if(e== getEdge(2)) return ValidIt2;
00293 nlstop;
00294 return false;
00295 }
00296
00297
00298
00299 bool hasVertex(sint numvertex)
00300 {
00301 return Corner[0].Vertex==numvertex || Corner[1].Vertex==numvertex || Corner[2].Vertex==numvertex;
00302 }
00303
00304
00305
00306
00307 bool hasWedge(sint attribId, sint numwedge)
00308 {
00309 return Corner[0].Attributes[attribId]==numwedge ||
00310 Corner[1].Attributes[attribId]==numwedge ||
00311 Corner[2].Attributes[attribId]==numwedge;
00312 }
00313 sint getAssociatedWedge(sint attribId, sint numvertex)
00314 {
00315 if(Corner[0].Vertex==numvertex) return Corner[0].Attributes[attribId];
00316 if(Corner[1].Vertex==numvertex) return Corner[1].Attributes[attribId];
00317 if(Corner[2].Vertex==numvertex) return Corner[2].Attributes[attribId];
00318 return -1;
00319 }
00320 };
00321
00322
00323
00327 class CMRMSewingMesh
00328 {
00329 struct CLod
00330 {
00331
00332 std::vector<CMRMEdge> EdgeToCollapse;
00333 };
00334
00335
00336 std::vector<CLod> _Lods;
00337
00338 public:
00339
00342 void build(const CMesh::CInterface &meshInt, uint nWantedLods, uint divisor);
00343
00347 sint mustCollapseEdge(uint lod, const CMRMEdge &edge, uint &vertToCollapse) const;
00348
00350 sint getNumCollapseEdge(uint lod) const;
00351
00352 };
00353
00354
00355
00356
00357 }
00358
00359
00360 #endif // NL_MRM_INTERNAL_H
00361
00362