00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_PS_MESH_H
00027 #define NL_PS_MESH_H
00028
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/class_registry.h"
00031 #include "3d/ps_particle_basic.h"
00032 #include "3d/ps_attrib.h"
00033 #include "3d/ps_plane_basis.h"
00034 #include "3d/vertex_buffer.h"
00035 #include "3d/material.h"
00036 #include "3d/primitive_block.h"
00037 #include "3d/shape.h"
00038
00039
00040
00041 #include <string>
00042 #include <vector>
00043 #include <queue>
00044
00045 namespace NLMISC
00046 {
00047 class IStream;
00048 struct EStream;
00049 }
00050
00051
00052 namespace NL3D {
00053
00054
00055 class CPSLocated;
00056 class CTransformShape;
00057 class CShapeBank;
00058 class CMesh;
00059
00060
00061
00062 const uint ConstraintMeshMaxNumVerts = 512;
00063 const uint ConstraintMeshBufSize = 64;
00064 const uint ConstraintMeshMaxNumPrerotatedModels = 32;
00065
00072 class CPSMesh : public CPSParticle,
00073 public CPSSizedParticle,
00074 public CPSRotated3DPlaneParticle,
00075 public CPSRotated2DParticle,
00076 public CPSShapeParticle
00077 {
00078 public:
00080 CPSMesh(const std::string &shape = "") : _Invalidated(false)
00081 {
00082 _Shape = shape;
00083 _Name = std::string("Mesh");
00084 }
00085
00087 void setShape(const std::string &shape) { _Shape = shape; }
00088
00090 std::string getShape(void) const { return _Shape; }
00091
00093 virtual void serial(NLMISC::IStream &f) throw(NLMISC::EStream);
00094
00095 virtual ~CPSMesh();
00096
00097 NLMISC_DECLARE_CLASS(CPSMesh);
00098
00099
00104 void invalidate()
00105 {
00106 _Invalidated = true;
00107 _Instances.clear();
00108 }
00109
00111 virtual bool hasTransparentFaces(void);
00112
00114 virtual bool hasOpaqueFaces(void);
00115
00117 virtual uint32 getMaxNumFaces(void) const;
00118
00119 protected:
00122 virtual void newElement(CPSLocated *emitterLocated, uint32 emitterIndex);
00123
00128 virtual void deleteElement(uint32 index);
00129
00130 virtual void step(TPSProcessPass pass, TAnimationTime ellapsedTime, TAnimationTime realEt);
00131
00133 virtual void updatePos();
00134
00138 virtual void resize(uint32 size);
00139
00140
00141
00142 std::string _Shape;
00143
00144
00145 typedef CPSAttrib<CTransformShape *> TInstanceCont;
00146
00147 TInstanceCont _Instances;
00148
00149
00150
00151 bool _Invalidated;
00152
00153 virtual CPSLocated *getSizeOwner(void) { return _Owner; }
00154 virtual CPSLocated *getAngle2DOwner(void) { return _Owner; }
00155 virtual CPSLocated *getPlaneBasisOwner(void) { return _Owner; }
00156 };
00157
00158
00163 class CPSConstraintMesh : public CPSParticle,
00164 public CPSSizedParticle,
00165 public CPSRotated3DPlaneParticle,
00166 public CPSHintParticleRotateTheSame,
00167 public CPSShapeParticle,
00168 public CPSColoredParticle
00169 {
00170 public:
00172 CPSConstraintMesh();
00173
00174 virtual ~CPSConstraintMesh();
00175
00179 void setShape(const std::string &meshFileName);
00180
00182 std::string getShape(void) const;
00183
00184
00185
00195 void setShapes(const std::string *shapesNames, uint numShapes);
00196
00197
00199 void setShape(uint index, const std::string &shapeName);
00200
00202 const std::string &getShape(uint index) const;
00203
00205 uint getNumShapes() const;
00206
00210 void getShapesNames(std::string *shapesNames) const;
00211
00213 void setMorphValue(float value);
00214
00216 float getMorphValue() const;
00217
00219 void setMorphScheme(CPSAttribMaker<float> *scheme);
00220
00222 CPSAttribMaker<float> *getMorphScheme();
00223
00225 const CPSAttribMaker<float> *getMorphScheme() const;
00226
00227
00228
00229
00230
00241 void hintRotateTheSame(uint32 nbConfiguration,
00242 float minAngularVelocity = NLMISC::Pi,
00243 float maxAngularVelocity = NLMISC::Pi
00244 );
00245
00250 void disableHintRotateTheSame(void)
00251 {
00252 hintRotateTheSame(0);
00253 }
00254
00260 uint32 checkHintRotateTheSame(float &min, float &max) const
00261 {
00262 min = _MinAngularVelocity;
00263 max = _MaxAngularVelocity;
00264 return _PrecompBasis.size();
00265 }
00266
00267
00269 virtual void serial(NLMISC::IStream &f) throw(NLMISC::EStream);
00270
00271
00272 NLMISC_DECLARE_CLASS(CPSConstraintMesh);
00273
00275 virtual bool hasTransparentFaces(void);
00276
00278 virtual bool hasOpaqueFaces(void);
00279
00281 virtual uint32 getMaxNumFaces(void) const;
00282
00283
00289 void forceStageModulationByColor(uint stage, bool force);
00290
00292 bool isStageModulationForced(uint stage) const;
00293
00295 void forceVertexColorLighting(bool force = true) { _VertexColorLightingForced = force; }
00296
00298 bool isVertexColorLightingForced() const { return _VertexColorLightingForced; }
00299
00301 static void initPrerotVB();
00302
00303
00305
00306
00307
00309 void setTexAnimType(TTexAnimType type);
00310
00312 TTexAnimType getTexAnimType() const;
00314
00315
00317
00318
00319 {
00320 NLMISC::CVector2f TransSpeed;
00321 NLMISC::CVector2f TransAccel;
00322 NLMISC::CVector2f ScaleStart;
00323 NLMISC::CVector2f ScaleSpeed;
00324 NLMISC::CVector2f ScaleAccel;
00325 float WRotSpeed;
00326 float WRotAccel;
00327 CGlobalTexAnim();
00328 void serial(NLMISC::IStream &f) throw(NLMISC::EStream);
00330 void buildMatrix(TAnimationTime &date, NLMISC::CMatrix &dest);
00331 };
00332
00334 void setGlobalTexAnim(uint stage, const CGlobalTexAnim &properties);
00335
00337 const CGlobalTexAnim &getGlobalTexAnim(uint stage) const;
00338
00340 void forceGlobalAnimTimeResetOnNewElement(bool force = true) { _ReinitGlobalAnimTimeOnNewElement = force; }
00341 bool isGlobalAnimTimeResetOnNewElementForced() const { return _ReinitGlobalAnimTimeOnNewElement != 0; }
00342
00344
00345
00346
00347 protected:
00348 friend class CPSConstraintMeshHelper;
00349
00350 virtual CPSLocated *getColorOwner(void) { return _Owner; }
00351
00352
00353 virtual void updateMatAndVbForColor(void);
00354
00357 virtual void newElement(CPSLocated *emitterLocated, uint32 emitterIndex);
00358
00361 virtual void deleteElement(uint32 index);
00362
00363 virtual void step(TPSProcessPass pass, TAnimationTime ellapsedTime, TAnimationTime realEt);
00367 void draw(bool opaque, TAnimationTime ellapsedTime);
00368
00370 void drawPreRotatedMeshs(bool opaque, TAnimationTime ellapsedTime);
00371
00372
00374 void releaseShapes();
00375
00376
00383 void computeColors(CVertexBuffer &outVB, const CVertexBuffer &inVB, uint startIndex, uint toProcess, uint32 srcStep);
00384
00388 virtual void resize(uint32 size);
00389
00393 bool update(void);
00394
00396 CVertexBuffer &makePrerotatedVb(const CVertexBuffer &inVB, TAnimationTime ellapsedTime);
00397
00401 struct CRdrPass
00402 {
00403 CMaterial Mat;
00404 CMaterial SourceMat;
00405 CPrimitiveBlock Pb;
00406 };
00407
00409 typedef std::vector<CRdrPass> TRdrPassSet;
00410
00412 struct CMeshDisplay
00413 {
00414 TRdrPassSet RdrPasses;
00415 CVertexBuffer VB;
00416 };
00417
00418 void restoreMaterials();
00419
00421 void CPSConstraintMesh::setupRenderPasses(float date, TRdrPassSet &rdrPasses, bool opaque);
00422
00424 void doRenderPasses(IDriver *driver, uint numObj, TRdrPassSet &rdrPasses, bool opaque);
00425
00426
00427 typedef NLMISC::CSmartPtr<IShape> PShape;
00428 typedef std::vector<std::string> TShapeNameVect;
00429 typedef std::vector<PShape> TShapeVect;
00430
00431
00432 TShapeNameVect _MeshShapeFileName;
00433 TShapeVect _Shapes;
00434
00435
00436 uint _NumFaces;
00437
00438
00439 CShapeBank *_ModelBank;
00440
00441
00445 class CMeshDisplayShare
00446 {
00447 public:
00449 CMeshDisplayShare(uint maxNumMD) : _MaxNumMD(maxNumMD) {}
00450
00452 ~CMeshDisplayShare();
00453
00457 CMeshDisplay &getMeshDisplay(IShape *shape, uint32 format);
00458
00459 protected:
00460 uint _MaxNumMD;
00461 typedef NLMISC::CSmartPtr<IShape> PShape;
00462 struct CKey
00463 {
00464 ~CKey();
00465 PShape Shape;
00466 uint32 Format;
00467 bool operator == (const CKey &key) const { return Shape == key.Shape && Format == key.Format; }
00468 bool operator != (const CKey &key) const { return ! (*this == key); }
00469 bool operator < (const CKey &key) const { return Shape < key.Shape || (Shape == key.Shape && Format < key.Format); }
00470 };
00471 typedef std::map<CKey, CMeshDisplay *> TMDMap;
00472 typedef std::queue<CKey> TMDQueue;
00473 TMDQueue MDQueue;
00474 TMDMap MDMap;
00476 static void buildRdrPassSet(TRdrPassSet &dest, const IShape *src);
00478 static void buildVB(uint32 destFormat, CVertexBuffer &dest, const IShape *src);
00479 };
00480
00481 friend class CMeshDisplayShare;
00482
00483
00485 static CMeshDisplayShare _MeshDisplayShare;
00486
00488 static CVertexBuffer _PreRotatedMeshVB;
00489 static CVertexBuffer _PreRotatedMeshVBWithNormal;
00490
00491
00492
00493 float _MinAngularVelocity;
00494 float _MaxAngularVelocity;
00495
00496
00497
00498 struct CPlaneBasisPair
00499 {
00500 CPlaneBasis Basis;
00501 CVector Axis;
00502 float AngularVelocity;
00503 };
00504
00506 std::vector< CPlaneBasisPair > _PrecompBasis;
00507
00509 std::vector<uint32> _IndexInPrecompBasis;
00510
00512 void fillIndexesInPrecompBasis(void);
00513
00514
00515 void clean(void);
00516
00517 virtual CPSLocated *getSizeOwner(void) { return _Owner; }
00518 virtual CPSLocated *getPlaneBasisOwner(void) { return _Owner; }
00519
00521 uint8 _ModulatedStages;
00522
00523
00524 uint8 _Touched : 1;
00525
00526 uint8 _HasTransparentFaces : 1;
00527
00528 uint8 _HasOpaqueFaces : 1;
00529 uint8 _VertexColorLightingForced : 1;
00530 uint8 _GlobalAnimationEnabled : 1;
00531 uint8 _ReinitGlobalAnimTimeOnNewElement : 1;
00532
00533
00535 struct CGlobalTexAnims
00536 {
00537 CGlobalTexAnim Anims[IDRV_MAT_MAXTEXTURES];
00538 void serial(NLMISC::IStream &f) throw(NLMISC::EStream);
00539 };
00540
00541 typedef std::auto_ptr<CGlobalTexAnims> PGlobalTexAnims;
00542 PGlobalTexAnims _GlobalTexAnims;
00543 float _GlobalAnimDate;
00544
00545
00547
00548 float _MorphValue;
00549 CPSAttribMaker<float> *_MorphScheme;
00551 private:
00552 CPSConstraintMesh(const CPSConstraintMesh &) { nlassert(0); }
00553 CPSConstraintMesh &operator = (const CPSConstraintMesh &other) { nlassert(0); return *this; }
00554 };
00555
00556
00557
00558 }
00559
00560
00561 #endif // NL_PS_MESH_H
00562
00563