# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

scene.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_SCENE_H
00027 #define NL_SCENE_H
00028 
00029 
00030 #include "3d/mot.h"
00031 #include "3d/camera.h"
00032 #include "3d/shape.h"
00033 #include "3d/animated_lightmap.h"
00034 #include "3d/play_list_manager.h"
00035 #include "3d/quad_grid_clip_manager.h"
00036 #include "3d/particle_system_manager.h"
00037 #include "3d/animation_set.h"
00038 
00039 
00040 
00041 #include "nel/3d/viewport.h"
00042 
00043 #include "nel/misc/rgba.h"
00044 #include "nel/misc/smart_ptr.h"
00045 
00046 #include <map>
00047 #include <list>
00048 
00050 namespace NL3D
00051 {
00052 
00053 
00054 using   NLMISC::CRefPtr;
00055 using   NLMISC::CSmartPtr;
00056 
00057 class   CHrcTrav;
00058 class   CClipTrav;
00059 class   CLightTrav;
00060 class   CAnimDetailTrav;
00061 class   CLoadBalancingTrav;
00062 class   CRenderTrav;
00063 class   CDefaultHrcObs;
00064 class   CDefaultClipObs;
00065 class   CDefaultLightObs;
00066 class   CAnimDetailObs;
00067 class   CDefaultRenderObs;
00068 class   CTransform;
00069 class   CTransformShape;
00070 class   IDriver;
00071 class   CShapeBank;
00072 class   CCoarseMeshManager;
00073 class   CInstanceGroup;
00074 class   CSkipModel;
00075 class   CLodCharacterManager;
00076 class   CAsyncTextureManager;
00077 class   CSkeletonModel;
00078 
00079 
00080 // ***************************************************************************
00127 class CScene : public CMOT
00128 {
00129 public:
00130 
00131 
00133 
00134 
00135         static void             registerBasics();
00137 
00138 
00140 
00141 
00142         CScene();
00144         ~CScene();
00146         void                    initDefaultTravs();
00148         void                    initDefaultRoots();
00150         void                    initGlobalnstanceGroup();
00152         void                    initCoarseMeshManager ();
00154         void                    initQuadGridClipManager ();
00156         void                    setDriver(IDriver *drv);
00158         IDriver                 *getDriver() const;
00164         void                    addTrav(ITrav *v);
00165         
00166 
00170         virtual void                    release();
00172 
00173 
00175 
00176 
00183         void                    render(bool     doHrcPass=true);
00185 
00189         void                    updateWaitingInstances(double systemTimeEllapsed);
00190 
00191 
00193 
00194 
00195         void                    setCam(CCamera *cam) {CurrentCamera= cam;}
00196         CCamera                 *getCam() {return CurrentCamera;}
00197         void                    setViewport(const class CViewport& viewport)
00198         {
00199                 _Viewport=viewport;
00200         }
00201         CViewport               getViewport()
00202         {
00203                 return _Viewport;
00204         }
00206 
00207 
00209 
00210 
00211         void                    setShapeBank(CShapeBank*pShapeBank);
00212 
00214         CShapeBank   *getShapeBank(void) { return _ShapeBank ; }
00215 
00217         const CShapeBank   *getShapeBank(void) const { return _ShapeBank ; }
00218 
00222         virtual CTransformShape *createInstance(const std::string &shapeName);
00223 
00227         void                    createInstanceAsync(const std::string &shapeName, CTransformShape **pInstance);
00228 
00231         void                    deleteInstance(CTransformShape*model);
00233 
00234         CInstanceGroup *getGlobalInstanceGroup() { return _GlobalInstanceGroup; }
00235 
00237 
00238         void    loadLightmapAutoAnim (const std::string &);
00239         void    setAutoAnim (CAnimation *pAnim);
00240         void    animate (TGlobalAnimationTime atTime);
00242         void    addInstanceGroupForLightAnimation(CInstanceGroup *ig);
00244         void    removeInstanceGroupForLightAnimation(CInstanceGroup *ig);
00245         // TODO:
00246         // TurnOff/TurnOn
00247         // Animate
00248         //CLight* addStaticLight(CLight*); // Generate Light Map
00249         //void addDynamicLight(CLight*); // ??? Vertex lighting
00251 
00252 
00253 
00255         TGlobalAnimationTime getCurrentTime(void) const { return _CurrentTime ; }
00256 
00258         TAnimationTime          getEllapsedTime(void) const { return _EllapsedTime ; }
00259 
00263         double                          getCurrentSystemTime() const {return _GlobalSystemTime;}
00264 
00266         double                          getEllapsedSystemTime() const { return _DeltaSystemTimeBetweenRender;}
00267 
00269         uint64                          getNumRender() const { return _NumRender; }
00270 
00271 
00273 
00274 
00278         float                                   getNbFaceAsked () const;
00279 
00280 
00284         void                                    setGroupLoadMaxPolygon(const std::string &group, uint nFaces);
00288         uint                                    getGroupLoadMaxPolygon(const std::string &group);
00292         float                                   getGroupNbFaceAsked (const std::string &group) const;
00293 
00294 
00301         enum                    TPolygonBalancingMode {PolygonBalancingOff=0, PolygonBalancingOn, PolygonBalancingClamp, CountPolygonBalancing};
00302 
00304         void                                    setPolygonBalancingMode(TPolygonBalancingMode polBalMode);
00306         TPolygonBalancingMode   getPolygonBalancingMode() const;
00307 
00308 
00312         void                                    setMaxSkeletonsInNotCLodForm(uint m) {_MaxSkeletonsInNotCLodForm= m;}
00313         uint                                    getMaxSkeletonsInNotCLodForm() const {return _MaxSkeletonsInNotCLodForm;}
00314 
00316 
00318 
00319         CCoarseMeshManager              *getStaticCoarseMeshManager ()
00320         {
00321                 return _StaticCoarseMeshManager;
00322         }
00323         CCoarseMeshManager              *getDynamicCoarseMeshManager ()
00324         {
00325                 return _DynamicCoarseMeshManager;
00326         }
00327 
00331         void                                    setCoarseMeshLightingUpdate(uint8 period);
00332 
00334         uint8                                   getCoarseMeshLightingUpdate() const {return _CoarseMeshLightingUpdate;}
00335 
00337         CLodCharacterManager    *getLodCharacterManager () const        {return _LodCharacterManager;}
00339         void                                    setLodCharacterManager(CLodCharacterManager     *m) {_LodCharacterManager= m;}
00340 
00342 
00343 
00345 
00346 
00352                 void  setLayersRenderingOrder(bool directOrder = true);
00353                 bool  getLayersRenderingOrder() const;
00355 
00356 
00358 
00359 
00363         void                    enableLightingSystem(bool enable);
00364 
00366         bool                    isLightingSystemEnabled() const {return _LightingSystemEnabled;}
00367 
00369         void                    setAmbientGlobal(NLMISC::CRGBA ambient);
00371         void                    setSunAmbient(NLMISC::CRGBA ambient);
00373         void                    setSunDiffuse(NLMISC::CRGBA diffuse);
00375         void                    setSunSpecular(NLMISC::CRGBA specular);
00377         void                    setSunDirection(const NLMISC::CVector &direction);
00378 
00379 
00381         NLMISC::CRGBA   getAmbientGlobal() const;
00383         NLMISC::CRGBA   getSunAmbient() const;
00385         NLMISC::CRGBA   getSunDiffuse() const;
00387         NLMISC::CRGBA   getSunSpecular() const;
00389         NLMISC::CVector getSunDirection() const;
00390 
00391 
00396         void            setMaxLightContribution(uint nlights);
00398         uint            getMaxLightContribution() const;
00399 
00408         void            setLightTransitionThreshold(float lightTransitionThreshold);
00410         float           getLightTransitionThreshold() const;
00411 
00412 
00414 
00415 
00417 
00418 
00420         void                    setGlobalWindPower(float gwp);
00422         float                   getGlobalWindPower() const {return _GlobalWindPower;}
00423 
00425         void                    setGlobalWindDirection(const CVector &gwd);
00427         const CVector   &getGlobalWindDirection() const {return _GlobalWindDirection;}
00428 
00430 
00431 
00433 
00434         CHrcTrav                        *getHrcTrav() const {return HrcTrav;}
00435         CClipTrav                       *getClipTrav() const {return ClipTrav;}
00436         CLightTrav                      *getLightTrav() const {return LightTrav;}
00437         CAnimDetailTrav         *getAnimDetailTrav() const {return AnimDetailTrav;}
00438         CLoadBalancingTrav      *getLoadBalancingTrav() const {return LoadBalancingTrav;}
00439         CRenderTrav                     *getRenderTrav() const {return RenderTrav;}
00440 
00441         // Link models to this one to disable their use in the wanted traversal
00442         CSkipModel                      *getSkipModelRoot() const {return SkipModelRoot;}
00443 
00445 
00446 
00448         CParticleSystemManager &getParticleSystemManager();
00449 
00450 
00452         void                            setAutomaticAnimationSet(CAnimationSet *as) { _AutomaticAnimationSet = as; }
00453 
00455         CAnimationSet           *getAutomaticAnimationSet() const { return _AutomaticAnimationSet; }    
00456 
00457 
00459         CAsyncTextureManager            *getAsyncTextureManager() const {return _AsyncTextureManager;}
00461         void                                            setAsyncTextureManager(CAsyncTextureManager *mgr) {_AsyncTextureManager= mgr;}
00462 
00463 
00465         // @{
00466         typedef std::list<CSkeletonModel*>              TSkeletonModelList;
00467         typedef TSkeletonModelList::iterator    ItSkeletonModelList;
00469         ItSkeletonModelList                     appendSkeletonModelToList(CSkeletonModel *skel);
00470         void                                            eraseSkeletonModelToList(ItSkeletonModelList    it);
00471         ItSkeletonModelList                     getSkeletonModelListBegin() {return _SkeletonModelList.begin();}
00472         ItSkeletonModelList                     getSkeletonModelListEnd() {return _SkeletonModelList.end();}
00473         // @}
00474 
00475 private:
00476         typedef                 std::map<sint, ITravScene*>     TTravMap;
00477         TTravMap                RenderTraversals;       // Sorted via their getRenderOrder().
00478 
00480         CRefPtr<CCamera>        CurrentCamera;
00481         CViewport               _Viewport;
00482 
00483         // the current time
00484         TGlobalAnimationTime  _CurrentTime ;
00485         
00486         // the real time
00487         TGlobalAnimationTime  _RealTime ;
00488 
00489         // true when its the first call of animate
00490         bool _FirstAnimateCall ;
00491 
00492         // the ellapsed time
00493         TAnimationTime  _EllapsedTime ;
00494 
00495         // System time is a time that always run (independent from the animation time that run only on animate()) 
00496         double  _DeltaSystemTimeBetweenRender;
00497         double  _GlobalSystemTime;
00498         uint64  _NumRender; // the number of time render has been called
00499 
00500 
00502 
00503         CHrcTrav                *HrcTrav;
00504         CClipTrav               *ClipTrav;
00505         CLightTrav              *LightTrav;
00506         CAnimDetailTrav *AnimDetailTrav;
00507         CLoadBalancingTrav      *LoadBalancingTrav;
00508         CRenderTrav             *RenderTrav;
00510 
00511         // The root models (will be deleted by CScene).
00512         CTransform              *Root;
00513         CSkipModel              *SkipModelRoot;
00514         // This model is used to clip any model which has a Skeleton ancestor
00515         CRootModel              *SonsOfAncestorSkeletonModelGroup;
00516         // This model is used for LightTrav to know its dynamic pointLights
00517         CRootModel              *LightModelRoot;
00518 
00519 
00520         // The Ligths automatic movements
00521         CAnimationSet   _LightmapAnimations;
00522         std::set<CAnimatedLightmap*> _AnimatedLightmap;
00523         CPlayListManager _LMAnimsAuto;
00524         // List of InstanceGroup to animate PointLightFactor.
00525         typedef std::set<CInstanceGroup*>       TAnimatedIgSet;
00526         typedef TAnimatedIgSet::iterator        ItAnimatedIgSet;
00527         TAnimatedIgSet  _AnimatedIgSet;
00528 
00530 
00531         CShapeBank              *_ShapeBank;
00532 
00533         typedef std::multimap<std::string,CTransformShape**> TWaitingInstancesMMap;
00534         TWaitingInstancesMMap _WaitingInstances;
00535 
00536         CInstanceGroup* _GlobalInstanceGroup;
00538 
00540 
00541         CRefPtr<CCoarseMeshManager>     _StaticCoarseMeshManager;
00542         CRefPtr<CCoarseMeshManager>     _DynamicCoarseMeshManager;
00543         // CLodCharacterManager is not a model. setuped by user
00544         CLodCharacterManager            *_LodCharacterManager;
00546 
00548 
00549         CQuadGridClipManager            _QuadGridClipManager;
00551 
00552 
00553         // Lighting.
00554         bool                                            _LightingSystemEnabled;
00555 
00557         uint8                                           _CoarseMeshLightingUpdate;
00558 
00560 
00561                 CParticleSystemManager  _ParticleSystemManager;
00563 
00564 
00566 
00567         float                                           _GlobalWindPower;
00568         CVector                                         _GlobalWindDirection;
00570         
00571 
00572         // A set of automatic animation
00573         NLMISC::CSmartPtr<CAnimationSet>                        _AutomaticAnimationSet; 
00574 
00575 
00576         // The async texture manager, setuped by the user.
00577         CAsyncTextureManager            *_AsyncTextureManager;
00578 
00579 
00580         // List of skeletons in the scene
00581         TSkeletonModelList                      _SkeletonModelList;
00582         // Max Skeleton displayed as std.
00583         uint                                            _MaxSkeletonsInNotCLodForm;
00584 
00585 };
00586 
00587 
00588 }
00589 
00590 
00591 #endif // NL_SCENE_H
00592 
00593 /* End of scene.h */