scene.h

Go to the documentation of this file.
00001 
00005 /* Copyright, 2000 Nevrax Ltd.
00006  *
00007  * This file is part of NEVRAX NEL.
00008  * NEVRAX NEL is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2, or (at your option)
00011  * any later version.
00012 
00013  * NEVRAX NEL is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * General Public License for more details.
00017 
00018  * You should have received a copy of the GNU General Public License
00019  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00020  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00021  * MA 02111-1307, USA.
00022  */
00023 
00024 #ifndef NL_SCENE_H
00025 #define NL_SCENE_H
00026 
00027 
00028 #include "nel/3d/camera.h"
00029 #include "nel/3d/shape.h"
00030 #include "nel/3d/animated_lightmap.h"
00031 #include "nel/3d/play_list_manager.h"
00032 #include "nel/3d/quad_grid_clip_manager.h"
00033 #include "nel/3d/particle_system_manager.h"
00034 #include "nel/3d/animation_set.h"
00035 // The traversals
00036 #include "nel/3d/hrc_trav.h"
00037 #include "nel/3d/clip_trav.h"
00038 #include "nel/3d/anim_detail_trav.h"
00039 #include "nel/3d/load_balancing_trav.h"
00040 #include "nel/3d/light_trav.h"
00041 #include "nel/3d/render_trav.h"
00042 #include "nel/3d/flare_model.h"
00043 
00044 #include "nel/3d/viewport.h"
00045 #include "nel/3d/u_scene.h"
00046 
00047 #include "nel/misc/rgba.h"
00048 #include "nel/misc/smart_ptr.h"
00049 
00050 // Debug : Sept 01 2006
00051 #include "nel/3d/skeleton_spawn_script.h"
00052 
00053 #include <map>
00054 #include <list>
00055 
00057 namespace NL3D
00058 {
00059 
00060 using   NLMISC::CRefPtr;
00061 using   NLMISC::CSmartPtr;
00062 
00063 class   CTransform;
00064 class   CTransformShape;
00065 class   IDriver;
00066 class   CShapeBank;
00067 class   CCoarseMeshManager;
00068 class   CInstanceGroup;
00069 class   CLodCharacterManager;
00070 class   CAsyncTextureManager;
00071 class   CSkeletonModel;
00072 class   CRootModel;
00073 class   CVisualCollisionManager;
00074 class   CTextureCube;
00075 class   CWaterEnvMap;
00076 
00077 // ***************************************************************************
00114 class CScene
00115 {
00116 public:
00117 
00119 
00120 
00121     static void     registerBasics();
00122 
00129     static  void    registerModel(const NLMISC::CClassId &idModel, const NLMISC::CClassId &idModelBase, CTransform* (*creator)());
00130 
00132 
00133 
00135 
00136 
00137     CScene(bool bSmallScene);
00139     ~CScene();
00141     void            initDefaultRoots();
00143     void            initQuadGridClipManager ();
00145     void            setDriver(IDriver *drv);
00147     IDriver         *getDriver() const;
00148 
00149 
00153     void            release();
00155 
00156 
00158 
00159 
00167     void            render(bool doHrcPass=true);
00168 
00174     void            beginPartRender();
00181     void            renderPart(UScene::TRenderPart rp, bool doHrcPass=true);
00184     void            endPartRender();
00185 
00187 
00188 
00192     void            updateWaitingInstances(double systemTimeEllapsed);
00193 
00194 
00196 
00197 
00198     void            setCam(CCamera *cam) {CurrentCamera= cam;}
00199     CCamera         *getCam() {return CurrentCamera;}
00200     void            setViewport(const class CViewport& viewport)
00201     {
00202         _Viewport=viewport;
00203     }
00204     CViewport       getViewport()
00205     {
00206         return _Viewport;
00207     }
00208 
00215     CInstanceGroup *findCameraClusterSystemFromRay(CInstanceGroup *startClusterSystem,
00216         const NLMISC::CVector &startPos, NLMISC::CVector &endPos);
00218 
00219 
00221 
00222 
00234     CTransform      *createModel(const NLMISC::CClassId &idModel);
00235 
00241     void            deleteModel(CTransform *model);
00242 
00244 
00246 
00247 
00248     void            setShapeBank(CShapeBank*pShapeBank);
00249 
00251     CShapeBank   *getShapeBank(void) { return _ShapeBank ; }
00252 
00254     const CShapeBank   *getShapeBank(void) const { return _ShapeBank ; }
00255 
00259     CTransformShape *createInstance(const std::string &shapeName);
00260 
00264     void            createInstanceAsync(const std::string &shapeName, CTransformShape **pInstance, const NLMISC::CVector &position, uint selectedTexture);
00265 
00268     void            deleteInstance(CTransformShape*model);
00269 
00271 
00272     CInstanceGroup *getGlobalInstanceGroup() { return _GlobalInstanceGroup; }
00273 
00275 
00276     void    animate (TGlobalAnimationTime atTime);
00278     void    addInstanceGroupForLightAnimation(CInstanceGroup *ig);
00280     void    removeInstanceGroupForLightAnimation(CInstanceGroup *ig);
00281     // TODO:
00282     // TurnOff/TurnOn
00283     // Animate
00284     //CLight* addStaticLight(CLight*); // Generate Light Map
00285     //void addDynamicLight(CLight*); // ??? Vertex lighting
00287 
00288 
00289 
00291     TGlobalAnimationTime getCurrentTime(void) const { return _CurrentTime ; }
00292 
00294     TAnimationTime      getEllapsedTime(void) const { return _EllapsedTime ; }
00295 
00299     double              getCurrentSystemTime() const {return _GlobalSystemTime;}
00300 
00302     double              getEllapsedSystemTime() const { return _DeltaSystemTimeBetweenRender;}
00303 
00305     uint64              getNumRender() const { return _NumRender; }
00306 
00308     bool                isRendering() const {return _IsRendering;}
00309 
00311 
00312 
00316     float                   getNbFaceAsked () const;
00317 
00318 
00322     void                    setGroupLoadMaxPolygon(const std::string &group, uint nFaces);
00326     uint                    getGroupLoadMaxPolygon(const std::string &group);
00330     float                   getGroupNbFaceAsked (const std::string &group) const;
00331 
00332 
00339     enum            TPolygonBalancingMode {PolygonBalancingOff=0, PolygonBalancingOn, PolygonBalancingClamp, CountPolygonBalancing};
00340 
00342     void                    setPolygonBalancingMode(TPolygonBalancingMode polBalMode);
00344     TPolygonBalancingMode   getPolygonBalancingMode() const;
00345 
00346 
00350     void                    setMaxSkeletonsInNotCLodForm(uint m) {_MaxSkeletonsInNotCLodForm= m;}
00351     uint                    getMaxSkeletonsInNotCLodForm() const {return _MaxSkeletonsInNotCLodForm;}
00352 
00354 
00356 
00357     CCoarseMeshManager      *getCoarseMeshManager ()
00358     {
00359         return _CoarseMeshManager;
00360     }
00361 
00365     void                    setCoarseMeshLightingUpdate(uint8 period);
00366 
00368     uint8                   getCoarseMeshLightingUpdate() const {return _CoarseMeshLightingUpdate;}
00369 
00371     CLodCharacterManager    *getLodCharacterManager () const    {return _LodCharacterManager;}
00373     void                    setLodCharacterManager(CLodCharacterManager *m) {_LodCharacterManager= m;}
00374 
00376 
00377 
00379 
00380 
00386         void  setLayersRenderingOrder(bool directOrder = true);
00387         bool  getLayersRenderingOrder() const;
00389 
00390 
00392 
00393 
00397     void            enableLightingSystem(bool enable);
00398 
00400     bool            isLightingSystemEnabled() const {return _LightingSystemEnabled;}
00401 
00403     void            setAmbientGlobal(NLMISC::CRGBA ambient);
00405     void            setSunAmbient(NLMISC::CRGBA ambient);
00407     void            setSunDiffuse(NLMISC::CRGBA diffuse);
00409     void            setSunSpecular(NLMISC::CRGBA specular);
00411     void            setSunDirection(const NLMISC::CVector &direction);
00413     void            setLightGroupColor(uint lightmapGroup, NLMISC::CRGBA color);
00414 
00415 
00417     NLMISC::CRGBA   getAmbientGlobal() const;
00419     NLMISC::CRGBA   getSunAmbient() const;
00421     NLMISC::CRGBA   getSunDiffuse() const;
00423     NLMISC::CRGBA   getSunSpecular() const;
00425     NLMISC::CVector getSunDirection() const;
00427     uint            getNumLightGroup () const
00428     {
00429         return _LightGroupColor.size ();
00430     }
00432     NLMISC::CRGBA   getLightmapGroupColor(uint lightGroup) const
00433     {
00434         if (lightGroup<_LightGroupColor.size())
00435             return _LightGroupColor[lightGroup];
00436         else
00437             return CRGBA::White;
00438     }
00440     NLMISC::CRGBA   getAnimatedLightFactor (sint animatedLightmap, uint lightGroup) const
00441     {
00442         if (((uint)animatedLightmap)<_AnimatedLightPtr.size ())
00443         {
00444             return _AnimatedLightPtr[animatedLightmap]->getFactor (lightGroup);
00445         }
00446         else
00447         {
00448             return getLightmapGroupColor (lightGroup);
00449         }
00450     }
00452     sint            getAnimatedLightNameToIndex (const std::string &name) const;
00453 
00458     void        setMaxLightContribution(uint nlights);
00461     uint        getMaxLightContribution() const;
00462 
00471     void        setLightTransitionThreshold(float lightTransitionThreshold);
00474     float       getLightTransitionThreshold() const;
00475 
00476 
00478 
00479 
00481 
00482 
00484     void            setGlobalWindPower(float gwp);
00486     float           getGlobalWindPower() const {return _GlobalWindPower;}
00487 
00489     void            setGlobalWindDirection(const CVector &gwd);
00491     const CVector   &getGlobalWindDirection() const {return _GlobalWindDirection;}
00492 
00494 
00495 
00497 
00498     CHrcTrav            &getHrcTrav() {return HrcTrav;}
00499     CClipTrav           &getClipTrav() {return ClipTrav;}
00500     CLightTrav          &getLightTrav() {return LightTrav;}
00501     CAnimDetailTrav     &getAnimDetailTrav() {return AnimDetailTrav;}
00502     CLoadBalancingTrav  &getLoadBalancingTrav() {return LoadBalancingTrav;}
00503     CRenderTrav         &getRenderTrav() {return RenderTrav;}
00504 
00506     CTransform          *getRoot() const {return Root;}
00508     CCluster            *getRootCluster() const {return RootCluster;}
00509 
00511 
00512 
00514     CParticleSystemManager &getParticleSystemManager();
00515 
00516 
00518     void                setAutomaticAnimationSet(CAnimationSet *as);
00519 
00521     CAnimationSet       *getAutomaticAnimationSet() const { return _AutomaticAnimationSet; }
00522 
00523 
00525     CAsyncTextureManager        *getAsyncTextureManager() const {return _AsyncTextureManager;}
00527     void                        setAsyncTextureManager(CAsyncTextureManager *mgr) {_AsyncTextureManager= mgr;}
00528 
00530     // @{
00531     void                enableElementRender(UScene::TRenderFilter elt, bool state);
00532     uint32              getFilterRenderFlags() const {return _FilterRenderFlags;}
00533     // @}
00534 
00536     // @{
00538     typedef std::list<CSkeletonModel*>      TSkeletonModelList;
00539     typedef TSkeletonModelList::iterator    ItSkeletonModelList;
00540     ItSkeletonModelList         appendSkeletonModelToList(CSkeletonModel *skel);
00541     void                        eraseSkeletonModelToList(ItSkeletonModelList    it);
00542     ItSkeletonModelList         getSkeletonModelListBegin() {return _SkeletonModelList.begin();}
00543     ItSkeletonModelList         getSkeletonModelListEnd() {return _SkeletonModelList.end();}
00544 
00546     typedef std::list<CTransform*>              TShadowCasterList;
00547     typedef TShadowCasterList::iterator         ItShadowCasterList;
00548     void                        registerShadowCasterToList(CTransform *sc);
00549     void                        unregisterShadowCasterToList(CTransform *sc);
00550     ItShadowCasterList          getShadowCasterListBegin() {return _ShadowCasterList.begin();}
00551     ItShadowCasterList          getShadowCasterListEnd() {return _ShadowCasterList.end();}
00552 
00554     void                        addSSSModelRequest(const CSSSModelRequest &req);
00555 
00556     // @}
00557 
00558 
00560     // @{
00561 
00562     // Enable Profiling for the next render(). Reset All stats.
00563     void                        profileNextRender();
00564     bool                        isNextRenderProfile() const {return _NextRenderProfile;}
00565 
00566     // Result profiling
00567     UScene::CBenchResults       BenchRes;
00568     // increment with the current VBufferFormat
00569     void                            incrementProfileTriVBFormat(std::map<uint32, uint32> &formatToTri, uint32 vbFormat, uint32 numTris)
00570     {
00571         std::map<uint32, uint32>::iterator  it= formatToTri.find(vbFormat);
00572         if(it==formatToTri.end())
00573         {
00574             it= formatToTri.insert(std::make_pair(vbFormat,0)).first;
00575         }
00576         it->second+= numTris;
00577     }
00578 
00579     // @}
00580 
00586     // @{
00587         // The max number of contexts for flares
00588         enum { MaxNumFlareContexts = CFlareModel::MaxNumContext };
00589         // Set the current context for flares. context must be < to MaxNumFlareContexts
00590         void    setFlareContext(uint context) { nlassert(context < MaxNumFlareContexts); _FlareContext = context; }
00591         // Get the current context for flares
00592         uint    getFlareContext() const { return _FlareContext; }
00593     // @}
00594 
00595 
00597     // @{
00599     uint            getShadowMapTextureSize() const {return _ShadowMapTextureSize;}
00601     void            setShadowMapTextureSize(uint size);
00603     uint            getShadowMapBlurSize() const {return _ShadowMapBlurSize;}
00605     void            setShadowMapBlurSize(uint bs);
00607     void            enableShadowPolySmooth(bool enable);
00609     bool            getEnableShadowPolySmooth() const;
00610 
00612     void            setShadowMapDistFadeStart(float dist);
00613     float           getShadowMapDistFadeStart() const {return _ShadowMapDistFadeStart;}
00615     void            setShadowMapDistFadeEnd(float dist);
00616     float           getShadowMapDistFadeEnd() const {return _ShadowMapDistFadeEnd;}
00618     void            setShadowMapMaxCasterInScreen(uint num);
00619     uint            getShadowMapMaxCasterInScreen() const {return _ShadowMapMaxCasterInScreen;}
00621     void            setShadowMapMaxCasterAround(uint num);
00622     uint            getShadowMapMaxCasterAround() const {return _ShadowMapMaxCasterAround;}
00623 
00625     void                    setVisualCollisionManagerForShadow(CVisualCollisionManager *vcm) {_VisualCollisionManagerForShadow= vcm;}
00626     CVisualCollisionManager *getVisualCollisionManagerForShadow() const {return _VisualCollisionManagerForShadow;}
00627     // @}
00628 
00629     void            setWaterCallback(IWaterSurfaceAddedCallback *wcb) { _WaterCallback = wcb; }
00630     IWaterSurfaceAddedCallback *getWaterCallback() const { return _WaterCallback; }
00631 
00632     void            setLandscapePolyDrawingCallback(ILandscapePolyDrawingCallback *lpd)
00633     { _PolyDrawingCallback = lpd;}
00634     ILandscapePolyDrawingCallback *getLandscapePolyDrawingCallback() const { return _PolyDrawingCallback;}
00635 
00636     // Add a new occlusion query object that must be tested at the end of the rendering
00637     void            insertInOcclusionQueryList(CFlareModel *fm)
00638     {
00639         fm->Next = _FirstFlare;
00640         _FirstFlare = fm;
00641     }
00642 
00643     // debugging aid : draw all occlusion test mesh that are used by flares
00644     void            renderOcclusionTestMeshs();
00645 
00646     // Set a water envmap to be used with water surfaces in that scene. Water envmap may be shared accross several scenes.
00647     void          setWaterEnvMap(CWaterEnvMap *waterEnvMap) { _WaterEnvMap = waterEnvMap; }
00648     // Get currenlty used water envmap for that scene.
00649     CWaterEnvMap *getWaterEnvMap() const { return _WaterEnvMap; }
00653     void          updateWaterEnvMaps(TGlobalAnimationTime time);
00654     // Get vertex buffer used for water rendering
00655     CVertexBuffer &getWaterVB() { return _WaterVB; }
00656 private:
00657 
00659     CRefPtr<CCamera>    CurrentCamera;
00660     CViewport       _Viewport;
00661 
00662     // the current time
00663     TGlobalAnimationTime  _CurrentTime ;
00664 
00665     // the real time
00666     TGlobalAnimationTime  _RealTime;
00667     TGlobalAnimationTime  _InitTime;
00668 
00669     // true when its the first call of animate
00670     bool _FirstAnimateCall ;
00671 
00672     // the ellapsed time
00673     TAnimationTime  _EllapsedTime ;
00674 
00675     // System time is a time that always run (independent from the animation time that run only on animate())
00676     double  _DeltaSystemTimeBetweenRender;
00677     double  _GlobalSystemTime;
00678     uint64  _NumRender; // the number of time render has been called
00679 
00680 
00682 
00683     CHrcTrav            HrcTrav;
00684     CClipTrav           ClipTrav;
00685     CLightTrav          LightTrav;
00686     CAnimDetailTrav     AnimDetailTrav;
00687     CLoadBalancingTrav  LoadBalancingTrav;
00688     CRenderTrav         RenderTrav;
00690 
00691     // The root models (will be deleted by CScene).
00692     CTransform          *Root;
00693     // The Root Cluster
00694     CCluster            *RootCluster;
00695     // This model is used to clip any model which has a Skeleton ancestor
00696     CRootModel          *SonsOfAncestorSkeletonModelGroup;
00697 
00698 
00699     // The Ligths automatic movements
00700 
00701     std::map<std::string, uint>                 _AnimatedLightNameToIndex;
00702     std::list<CAnimatedLightmap>                _AnimatedLight;
00703     std::vector<CAnimatedLightmap*>             _AnimatedLightPtr;
00704     CPlayListManager _LMAnimsAuto;
00705 
00706     /* Lightmap factor for each lightmap group.
00707      * size() must be == to CAnimatedLightmap::_GroupColor.size () */
00708     std::vector<NLMISC::CRGBA>      _LightGroupColor;
00709 
00710     // List of InstanceGroup to animate PointLightFactor.
00711     typedef std::set<CInstanceGroup*>   TAnimatedIgSet;
00712     typedef TAnimatedIgSet::iterator    ItAnimatedIgSet;
00713     TAnimatedIgSet  _AnimatedIgSet;
00714 
00716 
00717     CShapeBank      *_ShapeBank;
00718 
00719     typedef std::multimap<std::string,CTransformShape**> TWaitingInstancesMMap;
00720     TWaitingInstancesMMap _WaitingInstances;
00721 
00722     CInstanceGroup* _GlobalInstanceGroup;
00724 
00726 
00727     // The Coarse Mesh Manager. Owned by the scene
00728     CCoarseMeshManager          *_CoarseMeshManager;
00729     // CLodCharacterManager is not a model. setuped by user
00730     CLodCharacterManager        *_LodCharacterManager;
00732 
00734 
00735     CQuadGridClipManager        *_QuadGridClipManager;
00737 
00738 
00739     // Lighting.
00740     bool                        _LightingSystemEnabled;
00741 
00743     uint8                       _CoarseMeshLightingUpdate;
00744 
00746 
00747         CParticleSystemManager  _ParticleSystemManager;
00749 
00750 
00752 
00753     float                       _GlobalWindPower;
00754     CVector                     _GlobalWindDirection;
00756 
00757 
00758     // A set of automatic animation
00759     NLMISC::CSmartPtr<CAnimationSet>            _AutomaticAnimationSet;
00760 
00761 
00762     // The async texture manager, setuped by the user.
00763     CAsyncTextureManager        *_AsyncTextureManager;
00764 
00765 
00766     // List of skeletons in the scene
00767     TSkeletonModelList          _SkeletonModelList;
00768     // Max Skeleton displayed as std.
00769     uint                        _MaxSkeletonsInNotCLodForm;
00770 
00771     // Render filtering
00772     uint32                      _FilterRenderFlags;
00773 
00774     // profile
00775     bool                        _NextRenderProfile;
00776 
00777     IWaterSurfaceAddedCallback  *_WaterCallback;
00778 
00779     ILandscapePolyDrawingCallback * _PolyDrawingCallback;
00780 
00781 
00782     CFlareModel *_FirstFlare; // first flare to test for occlusion query
00783 
00784     // List of shadow casters in the scene
00785     TShadowCasterList           _ShadowCasterList;
00786 
00787 // ******************
00788 private:
00789     struct  CModelEntry
00790     {
00791         NLMISC::CClassId    ModelId, BaseModelId;
00792         CTransform* (*Creator)();
00793         bool    operator<(const CModelEntry& o) const {return ModelId<o.ModelId;}
00794         bool    operator==(const CModelEntry& o) const {return ModelId==o.ModelId;}
00795         bool    operator!=(const CModelEntry& o) const {return !(*this==o);}
00796     };
00797 
00798 
00799 private:
00800     // must do this for _UpdateModelList access.
00801     friend  class CTransform;
00802     friend  class CClipTrav;
00803 
00804     std::set<CTransform*>               _Models;
00805     CTransform                          *_UpdateModelList;
00806 
00807     static std::set<CModelEntry>    _RegModels;
00808 
00810     void            updateModels();
00811 
00812     // current context for rendering of flares
00813     uint            _FlareContext;
00814 
00815     // ShadowMap Options
00816     uint            _ShadowMapTextureSize;
00817     uint            _ShadowMapBlurSize;
00818     float           _ShadowMapDistFadeStart;
00819     float           _ShadowMapDistFadeEnd;
00820     uint            _ShadowMapMaxCasterInScreen;
00821     uint            _ShadowMapMaxCasterAround;
00822     CVisualCollisionManager     *_VisualCollisionManagerForShadow;
00823 
00824     // Delayed model delete
00825     bool            _IsRendering;
00826     std::vector<CTransform*>    _ToDelete;
00827 
00828     UScene::TRenderPart _RenderedPart;
00829     void    renderOcclusionTestMeshsWithCurrMaterial();
00830     CWaterEnvMap    *_WaterEnvMap;
00832     std::vector<CSSSModelRequest>       _SSSModelRequests;
00833     void                                    flushSSSModelRequests();
00834     // common vb for water display
00835     CVertexBuffer    _WaterVB;
00836 
00837 
00838 };
00839 
00840 
00841 
00842 }
00843 
00844 
00845 #endif // NL_SCENE_H
00846 
00847 /* End of scene.h */

Generated on Thu Jan 7 08:26:20 2010 for NeL by  doxygen 1.6.1