Show bonus/malus timer text if available
[ryzomcore.git] / nel / src / 3d / scene_user.cpp
blob4eed212a464c579b1318c0b8788027806df0d129
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "std3d.h"
22 #include "nel/3d/u_point_light.h"
23 #include "nel/3d/u_instance.h"
24 #include "nel/3d/u_camera.h"
25 #include "nel/3d/u_skeleton.h"
26 #include "nel/3d/scene_user.h"
27 #include "nel/3d/skeleton_model.h"
28 #include "nel/3d/coarse_mesh_manager.h"
29 #include "nel/3d/point_light_model.h"
30 #include "nel/3d/lod_character_manager.h"
31 #include "nel/3d/lod_character_shape.h"
32 #include "nel/3d/lod_character_shape_bank.h"
33 #include "nel/misc/hierarchical_timer.h"
34 #include "nel/3d/async_texture_manager.h"
35 #include "nel/3d/water_env_map_user.h"
38 using namespace NLMISC;
40 #ifdef DEBUG_NEW
41 #define new DEBUG_NEW
42 #endif
44 namespace NL3D
47 H_AUTO_DECL( NL3D_UI_Scene )
48 H_AUTO_DECL( NL3D_Misc_Scene_CreateDel_Element )
49 H_AUTO_DECL( NL3D_CreateOrLoad_Instance )
50 H_AUTO_DECL( NL3D_CreateOrLoad_Skeleton )
51 H_AUTO_DECL( NL3D_Load_CLodOrCoarseMesh )
52 H_AUTO_DECL( NL3D_Load_AsyncIG )
54 #define NL3D_HAUTO_UI_SCENE H_AUTO_USE( NL3D_UI_Scene )
55 #define NL3D_HAUTO_ELT_SCENE H_AUTO_USE( NL3D_Misc_Scene_CreateDel_Element )
56 #define NL3D_HAUTO_CREATE_INSTANCE H_AUTO_USE( NL3D_CreateOrLoad_Instance )
57 #define NL3D_HAUTO_CREATE_SKELETON H_AUTO_USE( NL3D_CreateOrLoad_Skeleton )
58 #define NL3D_HAUTO_LOAD_LOD H_AUTO_USE( NL3D_Load_CLodOrCoarseMesh )
59 #define NL3D_HAUTO_ASYNC_IG H_AUTO_USE( NL3D_Load_AsyncIG )
61 // Render/Animate.
62 H_AUTO_DECL( NL3D_Render_Scene )
63 H_AUTO_DECL( NL3D_Render_Animate_Scene )
64 H_AUTO_DECL( NL3D_Render_Scene_Begin )
65 H_AUTO_DECL( NL3D_Render_Scene_Part )
66 H_AUTO_DECL( NL3D_Render_Scene_End )
68 #define NL3D_HAUTO_RENDER_SCENE H_AUTO_USE( NL3D_Render_Scene )
69 #define NL3D_HAUTO_RENDER_SCENE_ANIMATE H_AUTO_USE( NL3D_Render_Animate_Scene )
70 #define NL3D_HAUTO_RENDER_SCENE_BEGIN H_AUTO_USE( NL3D_Render_Scene_Begin )
71 #define NL3D_HAUTO_RENDER_SCENE_PART H_AUTO_USE( NL3D_Render_Scene_Part )
72 #define NL3D_HAUTO_RENDER_SCENE_END H_AUTO_USE( NL3D_Render_Scene_End )
77 // ***************************************************************************
78 void CSceneUser::setAutomaticAnimationSet(UAnimationSet *as)
80 NL3D_HAUTO_UI_SCENE;
82 nlassert(as);
83 as->build();
84 CAnimationSetUser *asu = NLMISC::safe_cast<CAnimationSetUser *>(as);
85 _Scene.setAutomaticAnimationSet(asu->_AnimationSet);
88 // ***************************************************************************
89 UPlayListManager *CSceneUser::createPlayListManager()
91 NL3D_HAUTO_ELT_SCENE;
93 return _PlayListManagers.insert(new CPlayListManagerUser());
95 // ***************************************************************************
96 void CSceneUser::deletePlayListManager(UPlayListManager *playListManager)
98 NL3D_HAUTO_ELT_SCENE;
100 _PlayListManagers.erase((CPlayListManagerUser*)playListManager, "deletePlayListManager(): Bad PlayListManager ptr");
103 // ***************************************************************************
105 void CSceneUser::setPolygonBalancingMode(CSceneUser::TPolygonBalancingMode polBalMode)
107 NL3D_HAUTO_UI_SCENE;
109 nlassert( (uint)CScene::CountPolygonBalancing == (uint)CSceneUser::CountPolygonBalancing );
110 _Scene.setPolygonBalancingMode((CScene::TPolygonBalancingMode)(uint)(polBalMode));
113 // ***************************************************************************
115 CSceneUser::TPolygonBalancingMode CSceneUser::getPolygonBalancingMode() const
117 NL3D_HAUTO_UI_SCENE;
119 nlassert( (uint)CScene::CountPolygonBalancing == (uint)CSceneUser::CountPolygonBalancing );
120 return (CSceneUser::TPolygonBalancingMode)(uint)_Scene.getPolygonBalancingMode();
124 // ***************************************************************************
125 float CSceneUser::getNbFaceAsked () const
127 NL3D_HAUTO_UI_SCENE;
129 return _Scene.getNbFaceAsked ();
132 // ***************************************************************************
133 void CSceneUser::setGroupLoadMaxPolygon(const std::string &group, uint nFaces)
135 NL3D_HAUTO_UI_SCENE;
137 _Scene.setGroupLoadMaxPolygon(group, nFaces);
139 // ***************************************************************************
140 uint CSceneUser::getGroupLoadMaxPolygon(const std::string &group)
142 NL3D_HAUTO_UI_SCENE;
144 return _Scene.getGroupLoadMaxPolygon(group);
146 // ***************************************************************************
147 float CSceneUser::getGroupNbFaceAsked (const std::string &group) const
149 NL3D_HAUTO_UI_SCENE;
151 return _Scene.getGroupNbFaceAsked (group);
155 // ***************************************************************************
157 void CSceneUser::setCoarseMeshManagerTexture (const char *sPath)
159 NL3D_HAUTO_LOAD_LOD;
161 // Get the manager
162 CCoarseMeshManager *manager=_Scene.getCoarseMeshManager ();
164 // Does it exist ?
165 if (manager)
167 // Set the texture
168 manager->setTextureFile (sPath);
172 // ***************************************************************************
173 void CSceneUser::setCoarseMeshLightingUpdate(uint8 period)
175 NL3D_HAUTO_UI_SCENE;
177 _Scene.setCoarseMeshLightingUpdate(period);
180 // ***************************************************************************
181 uint8 CSceneUser::getCoarseMeshLightingUpdate() const
183 NL3D_HAUTO_UI_SCENE;
185 return _Scene.getCoarseMeshLightingUpdate();
188 // ***************************************************************************
189 void CSceneUser::enableLightingSystem(bool enable)
191 NL3D_HAUTO_UI_SCENE;
193 _Scene.enableLightingSystem(enable);
196 // ***************************************************************************
197 void CSceneUser::setAmbientGlobal(NLMISC::CRGBA ambient)
199 NL3D_HAUTO_UI_SCENE;
201 _Scene.setAmbientGlobal(ambient);
203 void CSceneUser::setSunAmbient(NLMISC::CRGBA ambient)
205 NL3D_HAUTO_UI_SCENE;
207 _Scene.setSunAmbient(ambient);
209 void CSceneUser::setSunDiffuse(NLMISC::CRGBA diffuse)
211 NL3D_HAUTO_UI_SCENE;
213 _Scene.setSunDiffuse(diffuse);
215 void CSceneUser::setSunSpecular(NLMISC::CRGBA specular)
217 NL3D_HAUTO_UI_SCENE;
219 _Scene.setSunSpecular(specular);
221 void CSceneUser::setSunDirection(const NLMISC::CVector &direction)
223 NL3D_HAUTO_UI_SCENE;
225 _Scene.setSunDirection(direction);
227 void CSceneUser::setLightGroupColor(uint lightmapGroup, NLMISC::CRGBA color)
229 NL3D_HAUTO_UI_SCENE;
231 _Scene.setLightGroupColor(lightmapGroup, color);
235 // ***************************************************************************
236 NLMISC::CRGBA CSceneUser::getAmbientGlobal() const
238 NL3D_HAUTO_UI_SCENE;
240 return _Scene.getAmbientGlobal();
242 NLMISC::CRGBA CSceneUser::getSunAmbient() const
244 NL3D_HAUTO_UI_SCENE;
246 return _Scene.getSunAmbient();
248 NLMISC::CRGBA CSceneUser::getSunDiffuse() const
250 NL3D_HAUTO_UI_SCENE;
252 return _Scene.getSunDiffuse();
254 NLMISC::CRGBA CSceneUser::getSunSpecular() const
256 NL3D_HAUTO_UI_SCENE;
258 return _Scene.getSunSpecular();
260 NLMISC::CVector CSceneUser::getSunDirection() const
262 NL3D_HAUTO_UI_SCENE;
264 return _Scene.getSunDirection();
267 // ***************************************************************************
269 void CSceneUser::setMaxLightContribution(uint nlights)
271 NL3D_HAUTO_UI_SCENE;
273 _Scene.setMaxLightContribution(nlights);
276 // ***************************************************************************
278 uint CSceneUser::getMaxLightContribution() const
280 NL3D_HAUTO_UI_SCENE;
282 return _Scene.getMaxLightContribution();
285 // ***************************************************************************
287 void CSceneUser::setLightTransitionThreshold(float lightTransitionThreshold)
289 NL3D_HAUTO_UI_SCENE;
291 _Scene.setLightTransitionThreshold(lightTransitionThreshold);
294 // ***************************************************************************
296 float CSceneUser::getLightTransitionThreshold() const
298 NL3D_HAUTO_UI_SCENE;
300 return _Scene.getLightTransitionThreshold();
303 // ***************************************************************************
305 UPointLight CSceneUser::createPointLight()
307 NL3D_HAUTO_ELT_SCENE;
309 CTransform *model= _Scene.createModel(PointLightModelId);
310 if (model)
312 CPointLightModel *pointLightModel= safe_cast<CPointLightModel*> (model);
313 // If not found, return NULL.
314 if(pointLightModel==NULL)
315 return NULL;
317 // The component is auto added/deleted to _Scene in ctor/dtor.
318 return UPointLight (pointLightModel);
320 else
321 return UPointLight ();
324 // ***************************************************************************
325 void CSceneUser::deletePointLight(UPointLight &light)
327 NL3D_HAUTO_ELT_SCENE;
329 // The component is auto added/deleted to _Scene in ctor/dtor.
330 _Scene.deleteModel (light.getObjectPtr());
331 light.detach ();
335 // ***************************************************************************
336 void CSceneUser::setGlobalWindPower(float gwp)
338 NL3D_HAUTO_UI_SCENE;
340 _Scene.setGlobalWindPower(gwp);
342 // ***************************************************************************
343 float CSceneUser::getGlobalWindPower() const
345 NL3D_HAUTO_UI_SCENE;
347 return _Scene.getGlobalWindPower();
349 // ***************************************************************************
350 void CSceneUser::setGlobalWindDirection(const CVector &gwd)
352 _Scene.setGlobalWindDirection(gwd);
354 // ***************************************************************************
355 const CVector &CSceneUser::getGlobalWindDirection() const
357 NL3D_HAUTO_UI_SCENE;
359 return _Scene.getGlobalWindDirection();
362 // ***************************************************************************
363 void CSceneUser::updateWaitingIG()
365 for(TWaitingIGList::iterator it = _WaitingIGs.begin(); it != _WaitingIGs.end();)
367 bool erased= false;
368 if (it->IGToLoad != NULL) // ig loaded ?
370 if (it->IGToLoad != (UInstanceGroup *) -1)
372 switch (it->IGToLoad->getAddToSceneState())
374 case UInstanceGroup::StateNotAdded:
375 // start loading
376 if (it->Callback != NULL)
377 it->Callback->InstanceGroupCreated(it->IGToLoad);
378 it->IGToLoad->addToSceneAsync(*this, _DriverUser, it->SelectedTexture);
379 break;
380 case UInstanceGroup::StateAdded:
381 it->IGToLoad->setPos(it->Pos);
382 it->IGToLoad->setRotQuat(it->Rot);
383 this->setToGlobalInstanceGroup(it->IGToLoad);
384 *it->CallerPtr = it->IGToLoad;
385 // remove from list
386 it = _WaitingIGs.erase(it);
387 erased= true;
388 break;
389 case UInstanceGroup::StateError:
390 delete it->IGToLoad;
391 it->IGToLoad = (UInstanceGroup *) -1;
392 *it->CallerPtr = it->IGToLoad;
393 // remove from list
394 it = _WaitingIGs.erase(it);
395 erased= true;
396 break;
397 default:
398 break;
401 else
403 // loading failed
404 *it->CallerPtr = it->IGToLoad;
405 it = _WaitingIGs.erase(it);
406 erased= true;
409 // next IG.
410 if(!erased)
411 it++;
416 // ***************************************************************************
417 void CSceneUser::resetCLodManager()
419 NL3D_HAUTO_UI_SCENE;
421 // DriverUser always setup the lod manager
422 nlassert(_Scene.getLodCharacterManager());
424 _Scene.getLodCharacterManager()->reset();
427 // ***************************************************************************
428 uint32 CSceneUser::loadCLodShapeBank(const std::string &fileName)
430 NL3D_HAUTO_LOAD_LOD;
432 // DriverUser always setup the lod manager
433 nlassert(_Scene.getLodCharacterManager());
435 // Open the file
436 CIFile file(CPath::lookup(fileName));
438 // create the shape bank
439 uint32 bankId= _Scene.getLodCharacterManager()->createShapeBank();
441 // get the bank
442 CLodCharacterShapeBank *bank= _Scene.getLodCharacterManager()->getShapeBank(bankId);
443 nlassert(bank);
445 // read the bank.
446 file.serial(*bank);
448 // recompile the shape Map.
449 _Scene.getLodCharacterManager()->compile();
451 return bankId;
454 // ***************************************************************************
455 void CSceneUser::deleteCLodShapeBank(uint32 bankId)
457 NL3D_HAUTO_LOAD_LOD;
459 // DriverUser always setup the lod manager
460 nlassert(_Scene.getLodCharacterManager());
462 // delete the bank
463 _Scene.getLodCharacterManager()->deleteShapeBank(bankId);
465 // recompile the shape Map.
466 _Scene.getLodCharacterManager()->compile();
469 // ***************************************************************************
470 sint32 CSceneUser::getCLodShapeIdByName(const std::string &name) const
472 NL3D_HAUTO_UI_SCENE;
474 // DriverUser always setup the lod manager
475 nlassert(_Scene.getLodCharacterManager());
477 return _Scene.getLodCharacterManager()->getShapeIdByName(name);
480 // ***************************************************************************
481 sint32 CSceneUser::getCLodAnimIdByName(uint32 shapeId, const std::string &name) const
483 NL3D_HAUTO_UI_SCENE;
485 // DriverUser always setup the lod manager
486 nlassert(_Scene.getLodCharacterManager());
488 const CLodCharacterShape *shape= _Scene.getLodCharacterManager()->getShape(shapeId);
489 if(shape)
490 return shape->getAnimIdByName(name);
491 else
492 return -1;
496 // ***************************************************************************
497 void CSceneUser::render(bool updateWaitingInstancesFlag /*= true*/, bool restoreMatrixContextAfterRender /*= true*/)
500 // render the scene.
502 NL3D_HAUTO_RENDER_SCENE
504 if(_Scene.getCam() == NULL)
505 nlerror("render(): try to render with no camera linked (may have been deleted)");
506 _Scene.render(true);
509 if (updateWaitingInstancesFlag) updateWaitingInstances();
511 // Must restore the matrix context, so 2D/3D interface not disturbed.
512 if (restoreMatrixContextAfterRender) _DriverUser->restoreMatrixContext();
515 // ***************************************************************************
516 void CSceneUser::beginPartRender()
519 // render the scene.
521 NL3D_HAUTO_RENDER_SCENE_BEGIN
522 _Scene.beginPartRender();
526 // ***************************************************************************
527 void CSceneUser::renderPart(TRenderPart rp, bool doHrcPass, bool doTrav, bool keepTrav)
530 // render the scene.
532 NL3D_HAUTO_RENDER_SCENE_PART
534 if(_Scene.getCam() == NULL)
535 nlerror("render(): try to render with no camera linked (may have been deleted)");
536 _Scene.renderPart(rp, doHrcPass, doTrav, keepTrav);
540 // ***************************************************************************
541 void CSceneUser::endPartRender(bool updateWaitingInstancesFlag, bool restoreMatrixContextAfterRender, bool keepTrav)
544 // render the scene.
546 NL3D_HAUTO_RENDER_SCENE_END
547 _Scene.endPartRender(keepTrav);
550 if (updateWaitingInstancesFlag) updateWaitingInstances();
552 // Must restore the matrix context, so 2D/3D interface not disturbed.
553 if (restoreMatrixContextAfterRender) _DriverUser->restoreMatrixContext();
557 // ***************************************************************************
558 /*virtual*/ void CSceneUser::updateWaitingInstances(double ellapsedTime)
560 _Scene.updateWaitingInstances(ellapsedTime);
561 updateWaitingInstances();
565 // ***************************************************************************
566 void CSceneUser::updateWaitingInstances()
568 // Update waiting instances
570 NL3D_HAUTO_ASYNC_IG
572 // Done after the _Scene.render because in this method the instance are checked for creation
573 std::map<UInstance*,CTransformShape*>::iterator it = _WaitingInstances.begin();
574 while( it != _WaitingInstances.end() )
576 if( it->second != NULL )
578 it->first->attach (it->second);
579 std::map<UInstance*,CTransformShape*>::iterator delIt = it;
580 ++it;
581 _WaitingInstances.erase(delIt);
583 else
585 ++it;
590 // update waiting instances groups;
592 NL3D_HAUTO_ASYNC_IG
594 updateWaitingIG();
599 void CSceneUser::animate(TGlobalAnimationTime time)
601 NL3D_HAUTO_RENDER_SCENE_ANIMATE;
603 _Scene.animate(time);
606 // ***************************************************************************
608 void CSceneUser::setCam(UCamera cam)
610 NL3D_HAUTO_UI_SCENE;
612 if(cam.empty())
613 nlerror("setCam(): cannot set a NULL camera");
614 CCamera *camera = cam.getObjectPtr();
615 if( camera->getOwnerScene() != &_Scene)
616 nlerror("setCam(): try to set a current camera not created from this scene");
618 _Scene.setCam(camera);
621 // ***************************************************************************
623 UCamera CSceneUser::getCam()
625 NL3D_HAUTO_UI_SCENE;
627 return UCamera (_Scene.getCam());
630 // ***************************************************************************
632 void CSceneUser::setViewport(const class CViewport& viewport)
634 NL3D_HAUTO_UI_SCENE;
636 _Scene.setViewport(viewport);
638 CViewport CSceneUser::getViewport()
640 NL3D_HAUTO_UI_SCENE;
642 return _Scene.getViewport();
645 UInstanceGroup *CSceneUser::findCameraClusterSystemFromRay(UInstanceGroup *startClusterSystem,
646 const NLMISC::CVector &startPos, NLMISC::CVector &endPos)
648 NL3D_HAUTO_UI_SCENE;
650 CInstanceGroupUser *uig= dynamic_cast<CInstanceGroupUser*>(startClusterSystem);
651 CInstanceGroup *pIg= NULL;
652 if(uig)
653 pIg= &uig->_InstanceGroup;
655 CInstanceGroup *resultIg= _Scene.findCameraClusterSystemFromRay(pIg, startPos, endPos);
656 if(resultIg)
657 return resultIg->getUserInterface();
658 else
659 return NULL;
662 // ***************************************************************************
664 UCamera CSceneUser::createCamera()
666 NL3D_HAUTO_ELT_SCENE;
668 CTransform *model= _Scene.createModel(CameraId);
669 if (model)
671 CCamera *object = NLMISC::safe_cast<CCamera*>(model);
672 object->setFrustum(UCamera::DefLx, UCamera::DefLy, UCamera::DefLzNear, UCamera::DefLzFar);
673 return UCamera (object);
675 else
676 return UCamera ();
679 // ***************************************************************************
681 void CSceneUser::deleteCamera(UCamera &cam)
683 NL3D_HAUTO_ELT_SCENE;
685 CCamera *object = cam.getObjectPtr();
687 // The component is auto added/deleted to _Scene in ctor/dtor.
688 _Scene.deleteModel (object);
689 cam.detach ();
692 // ***************************************************************************
694 UInstance CSceneUser::createInstance(const std::string &shapeName)
696 NL3D_HAUTO_CREATE_INSTANCE;
698 CTransformShape *model= _Scene.createInstance(shapeName);
699 return UInstance (model);
702 // ***************************************************************************
704 void CSceneUser::createInstanceAsync(const std::string &shapeName, UInstance *ppInstance, const NLMISC::CVector &position, uint selectedTexture)
706 NL3D_HAUTO_CREATE_INSTANCE;
708 _WaitingInstances[ppInstance] = NULL;
709 _Scene.createInstanceAsync(shapeName,&_WaitingInstances[ppInstance], position, selectedTexture);
710 // CTransform *model= _Scene.createInstance(shapeName);
711 // If not found, return NULL.
712 // if(model==NULL)
713 // return NULL;
715 // if( dynamic_cast<CMeshInstance*>(model)==NULL )
716 // nlerror("UScene::createInstance(): shape is not a mesh");
718 // The component is auto added/deleted to _Scene in ctor/dtor.
719 // return dynamic_cast<UInstance*>( _Transforms.insert(new CInstanceUser(&_Scene, model)) );
722 // ***************************************************************************
724 void CSceneUser::deleteInstance(UInstance &inst)
726 NL3D_HAUTO_ELT_SCENE;
728 _Scene.deleteInstance (inst.getObjectPtr());
729 inst.detach ();
732 // ***************************************************************************
734 void CSceneUser::createInstanceGroupAndAddToSceneAsync (const std::string &instanceGroup, UInstanceGroup **pIG, const NLMISC::CVector &pos, const NLMISC::CQuat &rot,
735 uint selectedTexture, IAsyncLoadCallback *pCB)
737 NL3D_HAUTO_ASYNC_IG;
739 _WaitingIGs.push_front(CWaitingIG(pIG, pos, rot, selectedTexture, pCB));
740 UInstanceGroup::createInstanceGroupAsync(instanceGroup, &(_WaitingIGs.begin()->IGToLoad));
741 // this list updat will be performed at each render, see updateWaitingIG
744 void CSceneUser::stopCreatingAndAddingIG(UInstanceGroup **pIG)
746 NL3D_HAUTO_ASYNC_IG;
748 for(TWaitingIGList::iterator it = _WaitingIGs.begin(); it != _WaitingIGs.end(); ++it)
750 CWaitingIG &rWIG = *it;
751 if (rWIG.CallerPtr == pIG)
753 if (rWIG.IGToLoad == NULL)
755 UInstanceGroup::stopCreateInstanceGroupAsync(pIG);
757 // Ig must be initialized
758 else if (rWIG.IGToLoad != (UInstanceGroup*)-1)
760 switch(rWIG.IGToLoad->getAddToSceneState())
762 case UInstanceGroup::StateAdding:
763 rWIG.IGToLoad->stopAddToSceneAsync();
764 break;
765 case UInstanceGroup::StateAdded:
766 rWIG.IGToLoad->removeFromScene(*this);
767 delete rWIG.IGToLoad;
768 break;
769 case UInstanceGroup::StateNotAdded:
770 delete rWIG.IGToLoad;
771 break;
772 default:
773 break;
776 _WaitingIGs.erase(it);
777 return;
782 void CSceneUser::deleteInstanceGroup(UInstanceGroup *pIG)
784 delete pIG;
787 // ***************************************************************************
789 UTransform CSceneUser::createTransform()
791 NL3D_HAUTO_ELT_SCENE;
793 CTransform *model= _Scene.createModel(TransformId);
794 return UTransform (model);
797 // ***************************************************************************
799 void CSceneUser::deleteTransform(UTransform &tr)
801 NL3D_HAUTO_ELT_SCENE;
803 _Scene.deleteModel (tr.getObjectPtr());
804 tr.detach ();
807 // ***************************************************************************
809 USkeleton CSceneUser::createSkeleton(const std::string &shapeName)
811 NL3D_HAUTO_CREATE_SKELETON;
813 CTransformShape *ts = _Scene.createInstance(shapeName);
814 if (ts)
816 CSkeletonModel *model= safe_cast<CSkeletonModel*> (ts);
817 return USkeleton (model);
819 else
821 return USkeleton ();
825 // ***************************************************************************
827 void CSceneUser::deleteSkeleton(USkeleton &skel)
829 NL3D_HAUTO_ELT_SCENE;
831 // The component is auto added/deleted to _Scene in ctor/dtor.
832 _Scene.deleteInstance (skel.getObjectPtr());
833 skel.detach ();
836 // ***************************************************************************
838 ULandscape *CSceneUser::createLandscape()
840 NL3D_HAUTO_ELT_SCENE;
842 // The component is auto added/deleted to _Scene in ctor/dtor.
843 return _Landscapes.insert(new CLandscapeUser(&_Scene));
845 void CSceneUser::deleteLandscape(ULandscape *land)
847 NL3D_HAUTO_ELT_SCENE;
849 // The component is auto added/deleted to _Scene in ctor/dtor.
850 _Landscapes.erase((CLandscapeUser*) land);
853 UCloudScape *CSceneUser::createCloudScape()
855 NL3D_HAUTO_ELT_SCENE;
857 // The component is auto added/deleted to _Scene in ctor/dtor.
858 return _CloudScapes.insert(new CCloudScapeUser(&_Scene));
860 void CSceneUser::deleteCloudScape(UCloudScape *cs)
863 // The component is auto added/deleted to _Scene in ctor/dtor.
864 _CloudScapes.erase((CCloudScapeUser*) cs);
868 UInstanceGroup *CSceneUser::createInstanceGroup (const std::string &instanceGroup)
870 // Create the instance group
871 CInstanceGroupUser *user=new CInstanceGroupUser;
873 // Init the class
874 if (!user->load (instanceGroup))
876 // Prb, erase it
877 delete user;
879 // Return error code
880 return NULL;
883 // Insert the pointer in the pointer list
884 _InstanceGroups.insert (user);
886 // return the good value
887 return user;
890 void CSceneUser::deleteInstanceGroup (UInstanceGroup *group)
892 // The component is auto added/deleted to _Scene in ctor/dtor.
893 _InstanceGroups.erase (dynamic_cast<CInstanceGroupUser*>(group));
897 void CSceneUser::setToGlobalInstanceGroup(UInstanceGroup *pIG)
899 NL3D_HAUTO_UI_SCENE;
901 CInstanceGroupUser *pIGU = (CInstanceGroupUser*)pIG;
902 pIGU->_InstanceGroup.setClusterSystemForInstances(_Scene.getGlobalInstanceGroup());
905 // ***************************************************************************
906 UVisualCollisionManager *CSceneUser::createVisualCollisionManager()
908 NL3D_HAUTO_ELT_SCENE;
910 return _VisualCollisionManagers.insert(new CVisualCollisionManagerUser);
912 void CSceneUser::deleteVisualCollisionManager(UVisualCollisionManager *mgr)
914 NL3D_HAUTO_ELT_SCENE;
916 CVisualCollisionManagerUser *vcmUser= dynamic_cast<CVisualCollisionManagerUser*>(mgr);
918 // if it was the one used for shadow receiving in this scene, then set NULL
919 if(_Scene.getVisualCollisionManagerForShadow()==&vcmUser->getVCM())
920 _Scene.setVisualCollisionManagerForShadow(NULL);
922 // and delete it
923 _VisualCollisionManagers.erase(vcmUser);
927 // ***************************************************************************
928 CSceneUser::CSceneUser(CDriverUser *drv, bool bSmallScene) : _Scene(bSmallScene)
930 nlassert(drv);
931 _DriverUser= drv;
933 // init default Roots.
934 _Scene.initDefaultRoots();
936 // Set driver.
937 _Scene.setDriver(_DriverUser->getDriver());
939 // Set viewport
940 _Scene.setViewport (CViewport());
942 // init QuadGridClipManager
943 _Scene.initQuadGridClipManager ();
945 // Create default camera, and active!!
946 setCam(createCamera());
948 _WaterEnvMap = NULL;
951 CSceneUser::~CSceneUser()
953 _VisualCollisionManagers.clear();
954 _Landscapes.clear();
955 _CloudScapes.clear();
956 _Scene.release();
957 _Scene.setDriver(NULL);
958 _Scene.setCam(NULL);
959 _DriverUser= NULL;
962 // ***************************************************************************
963 void CSceneUser::setMaxSkeletonsInNotCLodForm(uint m)
965 _Scene.setMaxSkeletonsInNotCLodForm(m);
968 // ***************************************************************************
969 uint CSceneUser::getMaxSkeletonsInNotCLodForm() const
971 return _Scene.getMaxSkeletonsInNotCLodForm();
975 // ***************************************************************************
976 void CSceneUser::enableElementRender(TRenderFilter elt, bool state)
978 _Scene.enableElementRender(elt, state);
982 // ***************************************************************************
983 void CSceneUser::profileNextRender()
985 _Scene.profileNextRender();
987 // ***************************************************************************
988 void CSceneUser::getProfileResults(CBenchResults &results)
990 // Fill profile results
991 results= _Scene.BenchRes;
994 // ***************************************************************************
995 void CSceneUser::profileQuadGridClipManager()
997 _Scene.getClipTrav().getQuadGridClipManager()->profile();
1000 // ***************************************************************************
1001 uint CSceneUser::getNumFlareContexts() const
1003 return CScene::MaxNumFlareContexts;
1006 // ***************************************************************************
1007 void CSceneUser::setFlareContext(uint context)
1009 if (context >= CScene::MaxNumFlareContexts)
1011 nlwarning("Invalid flare context");
1012 return;
1014 _Scene.setFlareContext(context);
1017 // ***************************************************************************
1018 uint CSceneUser::getFlareContext() const
1020 return _Scene.getFlareContext();
1024 // ***************************************************************************
1025 uint CSceneUser::getShadowMapTextureSize() const
1027 return _Scene.getShadowMapTextureSize();
1030 // ***************************************************************************
1031 void CSceneUser::setShadowMapTextureSize(uint size)
1033 _Scene.setShadowMapTextureSize(size);
1036 // ***************************************************************************
1037 uint CSceneUser::getShadowMapBlurSize() const
1039 return _Scene.getShadowMapBlurSize();
1042 // ***************************************************************************
1043 void CSceneUser::setShadowMapBlurSize(uint bs)
1045 _Scene.setShadowMapBlurSize(bs);
1048 // ***************************************************************************
1049 void CSceneUser::enableShadowPolySmooth(bool enable)
1051 _Scene.enableShadowPolySmooth(enable);
1054 // ***************************************************************************
1055 bool CSceneUser::getEnableShadowPolySmooth() const
1057 return _Scene.getEnableShadowPolySmooth();
1060 // ***************************************************************************
1061 void CSceneUser::setShadowMapDistFadeStart(float dist)
1063 _Scene.setShadowMapDistFadeStart(dist);
1065 // ***************************************************************************
1066 float CSceneUser::getShadowMapDistFadeStart() const
1068 return _Scene.getShadowMapDistFadeStart();
1070 // ***************************************************************************
1071 void CSceneUser::setShadowMapDistFadeEnd(float dist)
1073 _Scene.setShadowMapDistFadeEnd(dist);
1075 // ***************************************************************************
1076 float CSceneUser::getShadowMapDistFadeEnd() const
1078 return _Scene.getShadowMapDistFadeEnd();
1080 // ***************************************************************************
1081 void CSceneUser::setShadowMapMaxCasterInScreen(uint num)
1083 _Scene.setShadowMapMaxCasterInScreen(num);
1085 // ***************************************************************************
1086 uint CSceneUser::getShadowMapMaxCasterInScreen() const
1088 return _Scene.getShadowMapMaxCasterInScreen();
1090 // ***************************************************************************
1091 void CSceneUser::setShadowMapMaxCasterAround(uint num)
1093 _Scene.setShadowMapMaxCasterAround(num);
1095 // ***************************************************************************
1096 uint CSceneUser::getShadowMapMaxCasterAround() const
1098 return _Scene.getShadowMapMaxCasterAround();
1100 // ***************************************************************************
1101 void CSceneUser::setVisualCollisionManagerForShadow(UVisualCollisionManager *vcm)
1103 if(vcm==NULL)
1104 _Scene.setVisualCollisionManagerForShadow(NULL);
1105 else
1107 CVisualCollisionManagerUser *vcmUser= static_cast<CVisualCollisionManagerUser*>(vcm);
1108 _Scene.setVisualCollisionManagerForShadow(&vcmUser->getVCM());
1111 // ***************************************************************************
1112 void CSceneUser::setWaterCallback(IWaterSurfaceAddedCallback *wcb)
1114 _Scene.setWaterCallback(wcb);
1116 // ***************************************************************************
1117 IWaterSurfaceAddedCallback *CSceneUser::getWaterCallback() const
1119 return _Scene.getWaterCallback();
1121 // ***************************************************************************
1122 void CSceneUser::setLandscapePolyDrawingCallback(ILandscapePolyDrawingCallback *lpd)
1124 _Scene.setLandscapePolyDrawingCallback(lpd);
1126 // ***************************************************************************
1127 ILandscapePolyDrawingCallback *CSceneUser::getLandscapePolyDrawingCallback() const
1129 return _Scene.getLandscapePolyDrawingCallback();
1131 // ***************************************************************************
1132 void CSceneUser::setupTransparencySorting(uint8 maxPriority /*=0*/,uint NbDistanceEntries /*=1024*/)
1134 _Scene.getRenderTrav().setupTransparencySorting(maxPriority, NbDistanceEntries);
1137 // ***************************************************************************
1138 void CSceneUser::setWaterEnvMap(UWaterEnvMap *waterEnvMap)
1140 if (waterEnvMap)
1142 if (((CWaterEnvMapUser *) waterEnvMap)->EnvMap.Driver != _DriverUser)
1144 nlwarning("Water envmap can only be set in a scene that was created from the same driver");
1145 return;
1148 _Scene.setWaterEnvMap(&((CWaterEnvMapUser *) waterEnvMap)->EnvMap);
1149 _WaterEnvMap = waterEnvMap;
1153 // ***************************************************************************
1154 void CSceneUser::updateWaterEnvMaps(TGlobalAnimationTime time)
1156 _Scene.updateWaterEnvMaps(time);
1162 } // NL3D