From 0ea5fc66924303d1bf73ba283a383e2aadee02f2 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 11 Aug 2018 20:21:34 +0200 Subject: Initial commit --- docs/doxygen/nel/scene__user_8cpp-source.html | 1046 +++++++++++++++++++++++++ 1 file changed, 1046 insertions(+) create mode 100644 docs/doxygen/nel/scene__user_8cpp-source.html (limited to 'docs/doxygen/nel/scene__user_8cpp-source.html') diff --git a/docs/doxygen/nel/scene__user_8cpp-source.html b/docs/doxygen/nel/scene__user_8cpp-source.html new file mode 100644 index 00000000..e9b8bdea --- /dev/null +++ b/docs/doxygen/nel/scene__user_8cpp-source.html @@ -0,0 +1,1046 @@ + + + + nevrax.org : docs + + + + + + + + + + + + + + +
# 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_user.cpp

Go to the documentation of this file.
00001 
+00007 /* Copyright, 2001 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 #include "std3d.h"
+00027 
+00028 #include "3d/scene_user.h"
+00029 #include "3d/coarse_mesh_manager.h"
+00030 #include "3d/point_light_user.h"
+00031 #include "3d/point_light_model.h"
+00032 #include "3d/lod_character_manager.h"
+00033 #include "3d/lod_character_shape.h"
+00034 #include "3d/lod_character_shape_bank.h"
+00035 #include "nel/misc/hierarchical_timer.h"
+00036 #include "3d/async_texture_manager.h"
+00037 
+00038 using namespace NLMISC;
+00039 
+00040 namespace NL3D 
+00041 {
+00042 
+00043 H_AUTO_DECL( NL3D_UI_Scene )
+00044 H_AUTO_DECL( NL3D_Misc_Scene_CreateDel_Element )
+00045 H_AUTO_DECL( NL3D_Load_AnimationSet )
+00046 H_AUTO_DECL( NL3D_CreateOrLoad_Instance )
+00047 H_AUTO_DECL( NL3D_CreateOrLoad_Skeleton )
+00048 H_AUTO_DECL( NL3D_Load_CLodOrCoarseMesh )
+00049 H_AUTO_DECL( NL3D_Load_AsyncIG )
+00050 
+00051 #define NL3D_HAUTO_UI_SCENE                                             H_AUTO_USE( NL3D_UI_Scene )
+00052 #define NL3D_HAUTO_ELT_SCENE                                    H_AUTO_USE( NL3D_Misc_Scene_CreateDel_Element )
+00053 #define NL3D_HAUTO_LOAD_ANIMSET                                 H_AUTO_USE( NL3D_Load_AnimationSet )
+00054 #define NL3D_HAUTO_CREATE_INSTANCE                              H_AUTO_USE( NL3D_CreateOrLoad_Instance )
+00055 #define NL3D_HAUTO_CREATE_SKELETON                              H_AUTO_USE( NL3D_CreateOrLoad_Skeleton )
+00056 #define NL3D_HAUTO_LOAD_LOD                                             H_AUTO_USE( NL3D_Load_CLodOrCoarseMesh )
+00057 #define NL3D_HAUTO_ASYNC_IG                                             H_AUTO_USE( NL3D_Load_AsyncIG )
+00058 
+00059 // Render/Animate.
+00060 H_AUTO_DECL( NL3D_Render_Scene )
+00061 H_AUTO_DECL( NL3D_Render_Animate_Scene )
+00062 
+00063 #define NL3D_HAUTO_RENDER_SCENE                                 H_AUTO_USE( NL3D_Render_Scene )
+00064 #define NL3D_HAUTO_RENDER_SCENE_ANIMATE                 H_AUTO_USE( NL3D_Render_Animate_Scene )
+00065 
+00066 #define NL3D_MEM_LIGHT                                          NL_ALLOC_CONTEXT( 3dLight )
+00067 #define NL3D_MEM_IG                                                     NL_ALLOC_CONTEXT( 3dIg )
+00068 #define NL3D_MEM_LOD                                            NL_ALLOC_CONTEXT( 3dLod )
+00069 #define NL3D_MEM_SCENE_RENDER                           NL_ALLOC_CONTEXT( 3dScRdr )
+00070 #define NL3D_MEM_INSTANCE                                       NL_ALLOC_CONTEXT( 3dInst )
+00071 #define NL3D_MEM_LANDSCAPE                                      NL_ALLOC_CONTEXT( 3dLand )
+00072 #define NL3D_MEM_CLOUDS                                         NL_ALLOC_CONTEXT( 3dCloud )
+00073 #define NL3D_MEM_VISUAL_COLLISION                       NL_ALLOC_CONTEXT( 3dVsCol )
+00074 
+00075 // ***************************************************************************
+00076 UAnimationSet                   *CSceneUser::createAnimationSet() 
+00077 {
+00078         NL_ALLOC_CONTEXT( 3dAnmSt )
+00079         NL3D_HAUTO_ELT_SCENE;
+00080 
+00081         return new CAnimationSetUser();
+00082 }
+00083 // ***************************************************************************
+00084 UAnimationSet                   *CSceneUser::createAnimationSet(const std::string &animationSetFile) 
+00085 {
+00086         NL_ALLOC_CONTEXT( 3dAnmSt )
+00087         NL3D_HAUTO_LOAD_ANIMSET;
+00088 
+00089         NLMISC::CIFile  f;
+00090         // throw exception if not found.
+00091         std::string     path= CPath::lookup(animationSetFile);
+00092         f.open(path);
+00093         return _AnimationSets.insert(new CAnimationSetUser(f));
+00094 }
+00095 // ***************************************************************************
+00096 void                    CSceneUser::deleteAnimationSet(UAnimationSet    *animationSet) 
+00097 {
+00098         NL_ALLOC_CONTEXT( 3dAnmSt )
+00099         NL3D_HAUTO_ELT_SCENE;
+00100 
+00101         _AnimationSets.erase((CAnimationSetUser*)animationSet, "deleteAnimationSet(): Bad AnimationSet ptr");
+00102 }
+00103 
+00104 // ***************************************************************************
+00105 void                    CSceneUser::setAutomaticAnimationSet(UAnimationSet *as)
+00106 {
+00107         NL_ALLOC_CONTEXT( 3dAnmSt )
+00108         NL3D_HAUTO_UI_SCENE;
+00109 
+00110         nlassert(as);
+00111         as->build();
+00112         CAnimationSetUser *asu = NLMISC::safe_cast<CAnimationSetUser *>(as);
+00113         _Scene.setAutomaticAnimationSet(asu->_AnimationSet);
+00114 }
+00115 
+00116 // ***************************************************************************
+00117 UPlayListManager                        *CSceneUser::createPlayListManager() 
+00118 {
+00119         NL_ALLOC_CONTEXT( 3dAnim )
+00120         NL3D_HAUTO_ELT_SCENE;
+00121 
+00122         return _PlayListManagers.insert(new CPlayListManagerUser());
+00123 }
+00124 // ***************************************************************************
+00125 void                    CSceneUser::deletePlayListManager(UPlayListManager      *playListManager) 
+00126 {
+00127         NL_ALLOC_CONTEXT( 3dAnim )
+00128         NL3D_HAUTO_ELT_SCENE;
+00129 
+00130         _PlayListManagers.erase((CPlayListManagerUser*)playListManager, "deletePlayListManager(): Bad PlayListManager ptr");
+00131 }
+00132 
+00133 // ***************************************************************************
+00134 
+00135 void                    CSceneUser::setPolygonBalancingMode(CSceneUser::TPolygonBalancingMode polBalMode)
+00136 {
+00137         NL3D_MEM_SCENE
+00138         NL3D_HAUTO_UI_SCENE;
+00139 
+00140         nlassert( (uint)CScene::CountPolygonBalancing == (uint)CSceneUser::CountPolygonBalancing );
+00141         _Scene.setPolygonBalancingMode((CScene::TPolygonBalancingMode)(uint)(polBalMode));
+00142 }
+00143 
+00144 // ***************************************************************************
+00145 
+00146 CSceneUser::TPolygonBalancingMode       CSceneUser::getPolygonBalancingMode() const
+00147 {
+00148         NL3D_MEM_SCENE
+00149         NL3D_HAUTO_UI_SCENE;
+00150 
+00151         nlassert( (uint)CScene::CountPolygonBalancing == (uint)CSceneUser::CountPolygonBalancing );
+00152         return (CSceneUser::TPolygonBalancingMode)(uint)_Scene.getPolygonBalancingMode();
+00153 }
+00154 
+00155 
+00156 // ***************************************************************************
+00157 float                   CSceneUser::getNbFaceAsked () const
+00158 {
+00159         NL3D_MEM_SCENE
+00160         NL3D_HAUTO_UI_SCENE;
+00161 
+00162         return _Scene.getNbFaceAsked ();
+00163 }
+00164 
+00165 // ***************************************************************************
+00166 void                    CSceneUser::setGroupLoadMaxPolygon(const std::string &group, uint nFaces)
+00167 {
+00168         NL3D_MEM_SCENE
+00169         NL3D_HAUTO_UI_SCENE;
+00170 
+00171         _Scene.setGroupLoadMaxPolygon(group, nFaces);
+00172 }
+00173 // ***************************************************************************
+00174 uint                    CSceneUser::getGroupLoadMaxPolygon(const std::string &group)
+00175 {
+00176         NL3D_MEM_SCENE
+00177         NL3D_HAUTO_UI_SCENE;
+00178 
+00179         return _Scene.getGroupLoadMaxPolygon(group);
+00180 }
+00181 // ***************************************************************************
+00182 float                   CSceneUser::getGroupNbFaceAsked (const std::string &group) const
+00183 {
+00184         NL3D_MEM_SCENE
+00185         NL3D_HAUTO_UI_SCENE;
+00186 
+00187         return _Scene.getGroupNbFaceAsked (group);
+00188 }
+00189 
+00190 
+00191 // ***************************************************************************
+00192 
+00193 void CSceneUser::setStaticCoarseMeshManagerTexture (const char *sPath)
+00194 {
+00195         NL3D_MEM_LOD
+00196         NL3D_HAUTO_LOAD_LOD;
+00197 
+00198         // Get the manager
+00199         CCoarseMeshManager *manager=_Scene.getStaticCoarseMeshManager ();
+00200 
+00201         // Does it exist ?
+00202         if (manager)
+00203         {
+00204                 // Set the texture
+00205                 manager->setTextureFile (sPath);
+00206         }
+00207 }
+00208 
+00209 // ***************************************************************************
+00210 
+00211 void CSceneUser::setDynamicCoarseMeshManagerTexture (const char *sPath)
+00212 {
+00213         NL3D_MEM_LOD
+00214         NL3D_HAUTO_LOAD_LOD;
+00215 
+00216         // Get the manager
+00217         CCoarseMeshManager *manager=_Scene.getDynamicCoarseMeshManager ();
+00218 
+00219         // Does it exist ?
+00220         if (manager)
+00221         {
+00222                 // Set the texture
+00223                 manager->setTextureFile (sPath);
+00224         }
+00225 }
+00226 
+00227 // ***************************************************************************
+00228 void                            CSceneUser::setCoarseMeshLightingUpdate(uint8 period)
+00229 {
+00230         NL3D_MEM_LIGHT
+00231         NL3D_HAUTO_UI_SCENE;
+00232 
+00233         _Scene.setCoarseMeshLightingUpdate(period);
+00234 }
+00235 
+00236 // ***************************************************************************
+00237 uint8                           CSceneUser::getCoarseMeshLightingUpdate() const
+00238 {
+00239         NL3D_MEM_LIGHT
+00240         NL3D_HAUTO_UI_SCENE;
+00241 
+00242         return _Scene.getCoarseMeshLightingUpdate();
+00243 }
+00244 
+00245 // ***************************************************************************
+00246 void                            CSceneUser::enableLightingSystem(bool enable)
+00247 {
+00248         NL3D_MEM_LIGHT
+00249         NL3D_HAUTO_UI_SCENE;
+00250 
+00251         _Scene.enableLightingSystem(enable);
+00252 }
+00253 
+00254 // ***************************************************************************
+00255 void                            CSceneUser::setAmbientGlobal(NLMISC::CRGBA ambient)
+00256 {
+00257         NL3D_MEM_LIGHT
+00258         NL3D_HAUTO_UI_SCENE;
+00259 
+00260         _Scene.setAmbientGlobal(ambient);
+00261 }
+00262 void                            CSceneUser::setSunAmbient(NLMISC::CRGBA ambient)
+00263 {
+00264         NL3D_MEM_LIGHT
+00265         NL3D_HAUTO_UI_SCENE;
+00266 
+00267         _Scene.setSunAmbient(ambient);
+00268 }
+00269 void                            CSceneUser::setSunDiffuse(NLMISC::CRGBA diffuse)
+00270 {
+00271         NL3D_MEM_LIGHT
+00272         NL3D_HAUTO_UI_SCENE;
+00273 
+00274         _Scene.setSunDiffuse(diffuse);
+00275 }
+00276 void                            CSceneUser::setSunSpecular(NLMISC::CRGBA specular)
+00277 {
+00278         NL3D_MEM_LIGHT
+00279         NL3D_HAUTO_UI_SCENE;
+00280 
+00281         _Scene.setSunSpecular(specular);
+00282 }
+00283 void                            CSceneUser::setSunDirection(const NLMISC::CVector &direction)
+00284 {
+00285         NL3D_MEM_LIGHT
+00286         NL3D_HAUTO_UI_SCENE;
+00287 
+00288         _Scene.setSunDirection(direction);
+00289 }
+00290 
+00291 
+00292 // ***************************************************************************
+00293 NLMISC::CRGBA           CSceneUser::getAmbientGlobal() const
+00294 {
+00295         NL3D_MEM_LIGHT
+00296         NL3D_HAUTO_UI_SCENE;
+00297 
+00298         return _Scene.getAmbientGlobal();
+00299 }
+00300 NLMISC::CRGBA           CSceneUser::getSunAmbient() const
+00301 {
+00302         NL3D_MEM_LIGHT
+00303         NL3D_HAUTO_UI_SCENE;
+00304 
+00305         return _Scene.getSunAmbient();
+00306 }
+00307 NLMISC::CRGBA           CSceneUser::getSunDiffuse() const
+00308 {
+00309         NL3D_MEM_LIGHT
+00310         NL3D_HAUTO_UI_SCENE;
+00311 
+00312         return _Scene.getSunDiffuse();
+00313 }
+00314 NLMISC::CRGBA           CSceneUser::getSunSpecular() const
+00315 {
+00316         NL3D_MEM_LIGHT
+00317         NL3D_HAUTO_UI_SCENE;
+00318 
+00319         return _Scene.getSunSpecular();
+00320 }
+00321 NLMISC::CVector         CSceneUser::getSunDirection() const
+00322 {
+00323         NL3D_MEM_LIGHT
+00324         NL3D_HAUTO_UI_SCENE;
+00325 
+00326         return _Scene.getSunDirection();
+00327 }
+00328 
+00329 
+00330 // ***************************************************************************
+00331 void                            CSceneUser::setMaxLightContribution(uint nlights)
+00332 {
+00333         NL3D_MEM_LIGHT
+00334         NL3D_HAUTO_UI_SCENE;
+00335 
+00336         _Scene.setMaxLightContribution(nlights);
+00337 }
+00338 uint                            CSceneUser::getMaxLightContribution() const
+00339 {
+00340         NL3D_MEM_LIGHT
+00341         NL3D_HAUTO_UI_SCENE;
+00342 
+00343         return _Scene.getMaxLightContribution();
+00344 }
+00345 
+00346 void                            CSceneUser::setLightTransitionThreshold(float lightTransitionThreshold)
+00347 {
+00348         NL3D_MEM_LIGHT
+00349         NL3D_HAUTO_UI_SCENE;
+00350 
+00351         _Scene.setLightTransitionThreshold(lightTransitionThreshold);
+00352 }
+00353 float                           CSceneUser::getLightTransitionThreshold() const
+00354 {
+00355         NL3D_MEM_LIGHT
+00356         NL3D_HAUTO_UI_SCENE;
+00357 
+00358         return _Scene.getLightTransitionThreshold();
+00359 }
+00360 
+00361 
+00362 // ***************************************************************************
+00363 UPointLight             *CSceneUser::createPointLight()
+00364 {
+00365         NL3D_MEM_LIGHT
+00366         NL3D_HAUTO_ELT_SCENE;
+00367 
+00368         IModel  *model= _Scene.createModel(PointLightModelId);
+00369         // If not found, return NULL.
+00370         if(model==NULL)
+00371                 return NULL;
+00372 
+00373         // The component is auto added/deleted to _Scene in ctor/dtor.
+00374         return dynamic_cast<UPointLight*>( _Transforms.insert(new CPointLightUser(&_Scene, model)) );
+00375 }
+00376 // ***************************************************************************
+00377 void                    CSceneUser::deletePointLight(UPointLight *light)
+00378 {
+00379         NL3D_MEM_LIGHT
+00380         NL3D_HAUTO_ELT_SCENE;
+00381 
+00382         // The component is auto added/deleted to _Scene in ctor/dtor.
+00383         _Transforms.erase(dynamic_cast<CTransformUser*>(light));
+00384 }
+00385 
+00386 
+00387 // ***************************************************************************
+00388 void                    CSceneUser::setGlobalWindPower(float gwp)
+00389 {
+00390         NL3D_MEM_SCENE
+00391         NL3D_HAUTO_UI_SCENE;
+00392 
+00393         _Scene.setGlobalWindPower(gwp);
+00394 }
+00395 // ***************************************************************************
+00396 float                   CSceneUser::getGlobalWindPower() const
+00397 {
+00398         NL3D_MEM_SCENE
+00399         NL3D_HAUTO_UI_SCENE;
+00400 
+00401         return _Scene.getGlobalWindPower();
+00402 }
+00403 // ***************************************************************************
+00404 void                    CSceneUser::setGlobalWindDirection(const CVector &gwd)
+00405 {
+00406         _Scene.setGlobalWindDirection(gwd);
+00407 }
+00408 // ***************************************************************************
+00409 const CVector   &CSceneUser::getGlobalWindDirection() const
+00410 {
+00411         NL3D_MEM_SCENE
+00412         NL3D_HAUTO_UI_SCENE;
+00413 
+00414         return _Scene.getGlobalWindDirection();
+00415 }
+00416 
+00417 // ***************************************************************************
+00418 void CSceneUser::updateWaitingIG()
+00419 {
+00420         NL3D_MEM_IG
+00421         for(TWaitingIGList::iterator it = _WaitingIGs.begin(); it != _WaitingIGs.end();)
+00422         {
+00423                 bool    erased= false;
+00424                 if (it->IGToLoad != NULL) // ig loaded ?
+00425                 {                       
+00426                         if (it->IGToLoad != (UInstanceGroup *) -1)
+00427                         {                               
+00428                                 switch (it->IGToLoad->getAddToSceneState())
+00429                                 {
+00430                                         case UInstanceGroup::StateNotAdded:
+00431                                                 // start loading                                                                                
+00432                                                 it->IGToLoad->addToSceneAsync(*this, _DriverUser);
+00433                                         break;
+00434                                         case UInstanceGroup::StateAdded:
+00435                                                 it->IGToLoad->setPos(it->Offset);
+00436                                                 this->setToGlobalInstanceGroup(it->IGToLoad);
+00437                                                 *it->CallerPtr = it->IGToLoad;
+00438                                                 // remove from list
+00439                                                 it = _WaitingIGs.erase(it);
+00440                                                 erased= true;
+00441                                         break;
+00442                                         default:
+00443                                         break;
+00444                                 }
+00445                         }
+00446                         else
+00447                         {
+00448                                 // loading failed
+00449                                 *it->CallerPtr = it->IGToLoad;
+00450                                 it = _WaitingIGs.erase(it);
+00451                                 erased= true;
+00452                         }
+00453                 }
+00454                 // next IG.
+00455                 if(!erased)
+00456                         it++;
+00457         }
+00458 }
+00459 
+00460 
+00461 // ***************************************************************************
+00462 void                            CSceneUser::resetCLodManager()
+00463 {
+00464         NL3D_MEM_LOD
+00465         NL3D_HAUTO_UI_SCENE;
+00466 
+00467         // DriverUser always setup the lod manager
+00468         nlassert(_Scene.getLodCharacterManager());
+00469 
+00470         _Scene.getLodCharacterManager()->reset();
+00471 }
+00472 
+00473 // ***************************************************************************
+00474 uint32                          CSceneUser::loadCLodShapeBank(const std::string &fileName)
+00475 {
+00476         NL3D_MEM_LOD
+00477         NL3D_HAUTO_LOAD_LOD;
+00478 
+00479         // DriverUser always setup the lod manager
+00480         nlassert(_Scene.getLodCharacterManager());
+00481 
+00482         // Open the file
+00483         CIFile  file(CPath::lookup(fileName));
+00484 
+00485         // create the shape bank
+00486         uint32  bankId= _Scene.getLodCharacterManager()->createShapeBank();
+00487 
+00488         // get the bank
+00489         CLodCharacterShapeBank  *bank= _Scene.getLodCharacterManager()->getShapeBank(bankId);
+00490         nlassert(bank);
+00491 
+00492         // read the bank.
+00493         file.serial(*bank);
+00494 
+00495         // recompile the shape Map.
+00496         _Scene.getLodCharacterManager()->compile();
+00497 
+00498         return bankId;
+00499 }
+00500 
+00501 // ***************************************************************************
+00502 void                            CSceneUser::deleteCLodShapeBank(uint32 bankId)
+00503 {
+00504         NL3D_MEM_LOD
+00505         NL3D_HAUTO_LOAD_LOD;
+00506 
+00507         // DriverUser always setup the lod manager
+00508         nlassert(_Scene.getLodCharacterManager());
+00509 
+00510         // delete the bank
+00511         _Scene.getLodCharacterManager()->deleteShapeBank(bankId);
+00512 
+00513         // recompile the shape Map.
+00514         _Scene.getLodCharacterManager()->compile();
+00515 }
+00516 
+00517 // ***************************************************************************
+00518 sint32                          CSceneUser::getCLodShapeIdByName(const std::string &name) const
+00519 {
+00520         NL3D_MEM_LOD
+00521         NL3D_HAUTO_UI_SCENE;
+00522 
+00523         // DriverUser always setup the lod manager
+00524         nlassert(_Scene.getLodCharacterManager());
+00525 
+00526         return _Scene.getLodCharacterManager()->getShapeIdByName(name);
+00527 }
+00528 
+00529 // ***************************************************************************
+00530 sint32                          CSceneUser::getCLodAnimIdByName(uint32 shapeId, const std::string &name) const
+00531 {
+00532         NL3D_MEM_LOD
+00533         NL3D_HAUTO_UI_SCENE;
+00534 
+00535         // DriverUser always setup the lod manager
+00536         nlassert(_Scene.getLodCharacterManager());
+00537 
+00538         const CLodCharacterShape        *shape= _Scene.getLodCharacterManager()->getShape(shapeId);
+00539         if(shape)
+00540                 return shape->getAnimIdByName(name);
+00541         else
+00542                 return -1;
+00543 }
+00544 
+00545 
+00546 // ***************************************************************************
+00547 void                    CSceneUser::render()
+00548 {       
+00549         NL3D_MEM_SCENE_RENDER
+00550 
+00551         // render the scene.
+00552         {
+00553                 NL3D_HAUTO_RENDER_SCENE
+00554 
+00555                 if(_CurrentCamera==NULL)
+00556                         nlerror("render(): try to render with no camera linked (may have been deleted)");
+00557                 _Scene.render();
+00558         }
+00559 
+00560         updateWaitingInstances();
+00561 
+00562         // Must restore the matrix context, so 2D/3D interface not disturbed.
+00563         _DriverUser->restoreMatrixContext();
+00564 }
+00565 
+00566 
+00567 // ***************************************************************************
+00568 /*virtual*/ void CSceneUser::updateWaitingInstances(double ellapsedTime)
+00569 {
+00570         NL3D_MEM_INSTANCE
+00571         _Scene.updateWaitingInstances(ellapsedTime);
+00572         updateWaitingInstances();
+00573 }
+00574 
+00575 
+00576 // ***************************************************************************
+00577 void CSceneUser::updateWaitingInstances()
+00578 {
+00579         NL3D_MEM_INSTANCE
+00580         // Update waiting instances
+00581         {
+00582                 NL3D_HAUTO_ASYNC_IG
+00583 
+00584                 // Done after the _Scene.render because in this method the instance are checked for creation
+00585                 std::map<UInstance**,CTransformShape*>::iterator it = _WaitingInstances.begin();
+00586                 while( it != _WaitingInstances.end() )
+00587                 {
+00588                         if( it->second != NULL )
+00589                         {
+00590                                 *(it->first) = dynamic_cast<UInstance*>( _Transforms.insert(new CInstanceUser(&_Scene, it->second)) );
+00591                                 std::map<UInstance**,CTransformShape*>::iterator delIt = it;
+00592                                 ++it;
+00593                                 _WaitingInstances.erase(delIt);
+00594                         }
+00595                         else
+00596                         {
+00597                                 ++it;
+00598                         }
+00599                 }
+00600         }
+00601 
+00602         // update waiting instances groups;
+00603         {
+00604                 NL3D_HAUTO_ASYNC_IG
+00605 
+00606                 updateWaitingIG();
+00607         }       
+00608 }
+00609 
+00610 
+00611 void                    CSceneUser::animate(TGlobalAnimationTime time)
+00612 {
+00613         NL_ALLOC_CONTEXT( 3dAnim )
+00614         NL3D_HAUTO_RENDER_SCENE_ANIMATE;
+00615 
+00616         _Scene.animate(time);
+00617 }
+00618 
+00619 
+00620 // ***************************************************************************
+00621 void                    CSceneUser::setCam(UCamera *cam)
+00622 {
+00623         NL3D_MEM_SCENE
+00624         NL3D_HAUTO_UI_SCENE;
+00625 
+00626         if(!cam)
+00627                 nlerror("setCam(): cannot set a NULL camera");
+00628         CCameraUser             *newCam= dynamic_cast<CCameraUser*>(cam);
+00629         if( newCam->getScene() != &_Scene)
+00630                 nlerror("setCam(): try to set a current camera not created from this scene");
+00631 
+00632         _CurrentCamera= newCam;
+00633         _Scene.setCam(newCam->getCamera());
+00634 }
+00635 UCamera                 *CSceneUser::getCam()
+00636 {
+00637         NL3D_MEM_SCENE
+00638         NL3D_HAUTO_UI_SCENE;
+00639 
+00640         return dynamic_cast<UCamera*>(_CurrentCamera);
+00641 }
+00642 void                    CSceneUser::setViewport(const class CViewport& viewport)
+00643 {
+00644         NL3D_MEM_SCENE
+00645         NL3D_HAUTO_UI_SCENE;
+00646 
+00647         _Scene.setViewport(viewport);
+00648 }
+00649 CViewport               CSceneUser::getViewport()
+00650 {
+00651         NL3D_MEM_SCENE
+00652         NL3D_HAUTO_UI_SCENE;
+00653 
+00654         return _Scene.getViewport();
+00655 }
+00656 
+00657 // ***************************************************************************
+00658 UCamera                 *CSceneUser::createCamera()
+00659 {
+00660         NL3D_MEM_SCENE
+00661         NL3D_HAUTO_ELT_SCENE;
+00662 
+00663         // The component is auto added/deleted to _Scene in ctor/dtor.
+00664         return dynamic_cast<UCamera*>( _Transforms.insert(new CCameraUser(&_Scene)) );
+00665 }
+00666 void                    CSceneUser::deleteCamera(UCamera *cam)
+00667 {
+00668         NL3D_MEM_SCENE
+00669         NL3D_HAUTO_ELT_SCENE;
+00670 
+00671         CCameraUser             *oldCam= dynamic_cast<CCameraUser*>(cam);
+00672         // Is this the current camera??
+00673         if(oldCam==_CurrentCamera)
+00674                 _CurrentCamera=NULL;
+00675 
+00676         // The component is auto added/deleted to _Scene in ctor/dtor.
+00677         _Transforms.erase(oldCam);
+00678 }
+00679 
+00680 UInstance               *CSceneUser::createInstance(const std::string &shapeName)
+00681 {
+00682         NL3D_MEM_INSTANCE
+00683         NL3D_HAUTO_CREATE_INSTANCE;
+00684 
+00685         IModel  *model= _Scene.createInstance(shapeName);
+00686         // If not found, return NULL.
+00687         if(model==NULL)
+00688                 return NULL;
+00689 
+00690         // The component is auto added/deleted to _Scene in ctor/dtor.
+00691         if (dynamic_cast<CParticleSystemModel *>(model))
+00692         {
+00694                 return dynamic_cast<UInstance*>( _Transforms.insert(new CParticleSystemInstanceUser(&_Scene, model)) );
+00695         }
+00696         else
+00697         {
+00699                 return dynamic_cast<UInstance*>( _Transforms.insert(new CInstanceUser(&_Scene, model)) );
+00700         }
+00701 }
+00702 
+00703 
+00704 void CSceneUser::createInstanceAsync(const std::string &shapeName, UInstance**ppInstance)
+00705 {
+00706         NL3D_MEM_INSTANCE
+00707         NL3D_HAUTO_CREATE_INSTANCE;
+00708 
+00709         _WaitingInstances[ppInstance] = NULL;
+00710         _Scene.createInstanceAsync(shapeName,&_WaitingInstances[ppInstance]);
+00711 //              IModel  *model= _Scene.createInstance(shapeName);
+00712         // If not found, return NULL.
+00713 //              if(model==NULL)
+00714 //                      return NULL;
+00715 
+00716 //              if( dynamic_cast<CMeshInstance*>(model)==NULL )
+00717 //                      nlerror("UScene::createInstance(): shape is not a mesh");
+00718 
+00719         // The component is auto added/deleted to _Scene in ctor/dtor.
+00720 //              return dynamic_cast<UInstance*>( _Transforms.insert(new CInstanceUser(&_Scene, model)) );
+00721 }
+00722 
+00723 void                    CSceneUser::deleteInstance(UInstance *inst)
+00724 {
+00725         NL3D_MEM_INSTANCE
+00726         NL3D_HAUTO_ELT_SCENE;
+00727 
+00728         // The component is auto added/deleted to _Scene in ctor/dtor.
+00729         _Transforms.erase(dynamic_cast<CTransformUser*>(inst));
+00730 }
+00731 
+00732 
+00733 void CSceneUser::createInstanceGroupAndAddToSceneAsync (const std::string &instanceGroup, UInstanceGroup **pIG, const NLMISC::CVector &offset)
+00734 {
+00735         NL3D_MEM_IG
+00736         NL3D_HAUTO_ASYNC_IG;
+00737 
+00738         _WaitingIGs.push_front(CWaitingIG(pIG, offset));
+00739         UInstanceGroup::createInstanceGroupAsync(instanceGroup, &(_WaitingIGs.begin()->IGToLoad));
+00740         // this list updat will be performed at each render, see updateWaitingIG
+00741 }
+00742 
+00743 void CSceneUser::stopCreatingAndAddingIG(UInstanceGroup **pIG)
+00744 {
+00745         NL3D_MEM_IG
+00746         NL3D_HAUTO_ASYNC_IG;
+00747 
+00748         for(TWaitingIGList::iterator it = _WaitingIGs.begin(); it != _WaitingIGs.end(); ++it)
+00749         {
+00750                 if (it->CallerPtr == pIG)
+00751                 {
+00752                         if (!it->IGToLoad)
+00753                         {
+00754                                 UInstanceGroup::stopCreateInstanceGroupAsync(pIG);                                                                              
+00755                         }
+00756                         else
+00757                         {
+00758                                 switch(it->IGToLoad->getAddToSceneState())
+00759                                 {
+00760                                         case UInstanceGroup::StateAdding:
+00761                                                 it->IGToLoad->stopAddToSceneAsync();
+00762                                         break;
+00763                                         case UInstanceGroup::StateAdded:
+00764                                                 it->IGToLoad->removeFromScene(*this);
+00765                                                 delete it->IGToLoad;
+00766                                         break;
+00767                                         case UInstanceGroup::StateNotAdded:
+00768                                                 delete it->IGToLoad;
+00769                                         break;
+00770                                 }
+00771                         }
+00772                         _WaitingIGs.erase(it);
+00773                         return;
+00774                 }
+00775         }               
+00776 }
+00777 
+00778 
+00779 UTransform *CSceneUser::createTransform()
+00780 {
+00781         NL3D_MEM_SCENE
+00782         NL3D_HAUTO_ELT_SCENE;
+00783 
+00784         IModel  *model= _Scene.createModel(TransformId);
+00785         // If not found, return NULL.
+00786         if(model==NULL)
+00787                 return NULL;
+00788 
+00789         // The component is auto added/deleted to _Scene in ctor/dtor.
+00790         return dynamic_cast<UTransform*>( _Transforms.insert(new CTransformUser(&_Scene, model)) );
+00791 }
+00792 
+00793 void                    CSceneUser::deleteTransform(UTransform *tr)
+00794 {
+00795         NL3D_MEM_SCENE
+00796         NL3D_HAUTO_ELT_SCENE;
+00797 
+00798         // The component is auto added/deleted to _Scene in ctor/dtor.
+00799         _Transforms.erase(dynamic_cast<CTransformUser*>(tr));
+00800 }
+00801 
+00802 
+00803 USkeleton               *CSceneUser::createSkeleton(const std::string &shapeName)
+00804 {
+00805         NL3D_MEM_SKELETON
+00806         NL3D_HAUTO_CREATE_SKELETON;
+00807 
+00808         IModel  *model= _Scene.createInstance(shapeName);
+00809         // If not found, return NULL.
+00810         if(model==NULL)
+00811                 return NULL;
+00812 
+00813         if( dynamic_cast<CSkeletonModel*>(model)==NULL )
+00814                 nlerror("UScene::createSkeleton(): shape is not a skeletonShape");
+00815 
+00816         // The component is auto added/deleted to _Scene in ctor/dtor.
+00817         return dynamic_cast<USkeleton*>( _Transforms.insert(new CSkeletonUser(&_Scene, model)) );
+00818 }
+00819 void                    CSceneUser::deleteSkeleton(USkeleton *skel)
+00820 {
+00821         NL3D_MEM_SKELETON
+00822         NL3D_HAUTO_ELT_SCENE;
+00823 
+00824         // The component is auto added/deleted to _Scene in ctor/dtor.
+00825         _Transforms.erase(dynamic_cast<CTransformUser*>(skel));
+00826 }
+00827 
+00828 
+00829 ULandscape              *CSceneUser::createLandscape()
+00830 {
+00831         NL3D_MEM_LANDSCAPE
+00832         NL3D_HAUTO_ELT_SCENE;
+00833 
+00834         // The component is auto added/deleted to _Scene in ctor/dtor.
+00835         return _Landscapes.insert(new CLandscapeUser(&_Scene));
+00836 }
+00837 void                    CSceneUser::deleteLandscape(ULandscape *land)
+00838 {
+00839         NL3D_MEM_LANDSCAPE
+00840         NL3D_HAUTO_ELT_SCENE;
+00841 
+00842         // The component is auto added/deleted to _Scene in ctor/dtor.
+00843         _Landscapes.erase((CLandscapeUser*) land);
+00844 }
+00845 
+00846 UCloudScape *CSceneUser::createCloudScape()
+00847 {
+00848         NL3D_MEM_CLOUDS
+00849         NL3D_HAUTO_ELT_SCENE;
+00850 
+00851         // The component is auto added/deleted to _Scene in ctor/dtor.
+00852         return _CloudScapes.insert(new CCloudScapeUser(&_Scene));
+00853 }
+00854 void CSceneUser::deleteCloudScape(UCloudScape *cs)
+00855 {
+00856         NL3D_MEM_CLOUDS
+00857 
+00858         // The component is auto added/deleted to _Scene in ctor/dtor.
+00859         _CloudScapes.erase((CCloudScapeUser*) cs);
+00860 }
+00861 /*
+00862 
+00863 UInstanceGroup  *CSceneUser::createInstanceGroup (const std::string &instanceGroup)
+00864 {
+00865         // Create the instance group
+00866         CInstanceGroupUser *user=new CInstanceGroupUser;
+00867 
+00868         // Init the class
+00869         if (!user->load (instanceGroup))
+00870         {
+00871                 // Prb, erase it
+00872                 delete user;
+00873 
+00874                 // Return error code
+00875                 return NULL;
+00876         }
+00877 
+00878         // Insert the pointer in the pointer list
+00879         _InstanceGroups.insert (user);
+00880 
+00881         // return the good value
+00882         return user;
+00883 }
+00884 
+00885 void                    CSceneUser::deleteInstanceGroup (UInstanceGroup *group)
+00886 {
+00887         // The component is auto added/deleted to _Scene in ctor/dtor.
+00888         _InstanceGroups.erase (dynamic_cast<CInstanceGroupUser*>(group));
+00889 }
+00890 */
+00891 
+00892 void CSceneUser::setToGlobalInstanceGroup(UInstanceGroup *pIG)
+00893 {
+00894         NL3D_MEM_IG
+00895         NL3D_HAUTO_UI_SCENE;
+00896 
+00897         CInstanceGroupUser *pIGU = (CInstanceGroupUser*)pIG;
+00898         pIGU->_InstanceGroup.setClusterSystem (_Scene.getGlobalInstanceGroup());
+00899 }
+00900 
+00901 // ***************************************************************************
+00902 UVisualCollisionManager         *CSceneUser::createVisualCollisionManager()
+00903 {
+00904         NL3D_MEM_VISUAL_COLLISION
+00905         NL3D_HAUTO_ELT_SCENE;
+00906 
+00907         return _VisualCollisionManagers.insert(new CVisualCollisionManagerUser);
+00908 }
+00909 void                                            CSceneUser::deleteVisualCollisionManager(UVisualCollisionManager *mgr)
+00910 {
+00911         NL3D_MEM_VISUAL_COLLISION
+00912         NL3D_HAUTO_ELT_SCENE;
+00913 
+00914         _VisualCollisionManagers.erase(dynamic_cast<CVisualCollisionManagerUser*>(mgr));
+00915 }
+00916 
+00917 
+00918 // ***************************************************************************
+00919 CSceneUser::CSceneUser(CDriverUser *drv)
+00920 {
+00921         NL3D_MEM_SCENE_INIT
+00922         nlassert(drv);
+00923         _DriverUser= drv;
+00924         _CurrentCamera = NULL;
+00925 
+00926         // Init Scene.
+00927         _Scene.initDefaultTravs();
+00928 
+00929         // Don't add any user trav.
+00930         // init default Roots.
+00931         _Scene.initDefaultRoots();
+00932 
+00933         // Set driver.
+00934         _Scene.setDriver(_DriverUser->getDriver());
+00935 
+00936         // Set viewport
+00937         _Scene.setViewport (CViewport());
+00938 
+00939         // Init the world instance group
+00940         _Scene.initGlobalnstanceGroup();
+00941 
+00942         // Init coarse mesh manager
+00943         _Scene.initCoarseMeshManager ();
+00944 
+00945         // init QuadGridClipManager
+00946         _Scene.initQuadGridClipManager ();
+00947 
+00948         // Create default camera, and active!!
+00949         setCam(createCamera());
+00950 }
+00951 
+00952 CSceneUser::~CSceneUser()
+00953 {
+00954         NL3D_MEM_SCENE
+00955         _VisualCollisionManagers.clear();
+00956         _Transforms.clear();
+00957         _Landscapes.clear();
+00958         _CloudScapes.clear();
+00959         _Scene.release();
+00960         _Scene.setDriver(NULL);
+00961         _Scene.setCam(NULL);
+00962         _CurrentCamera= NULL;
+00963         _DriverUser= NULL;
+00964 }
+00965 
+00966 // ***************************************************************************
+00967 void            CSceneUser::setMaxSkeletonsInNotCLodForm(uint m)
+00968 {
+00969         _Scene.setMaxSkeletonsInNotCLodForm(m);
+00970 }
+00971 
+00972 // ***************************************************************************
+00973 uint            CSceneUser::getMaxSkeletonsInNotCLodForm() const
+00974 {
+00975         return _Scene.getMaxSkeletonsInNotCLodForm();
+00976 }
+00977 
+00978 
+00979 } // NL3D
+
+ + +
                                                                                                                                                                    +
+ + -- cgit v1.2.1