SO3Engine
SO3Scene.cpp
Go to the documentation of this file.
1
8#include "SCOLPack/SO3SCOL.h"
24#include "SO3Renderer/SO3Root.h"
40#include "OgreFontManager.h"
41#include "OgreFont.h"
42#include <OgreOctreePlugin.h>
43
44#include <boost/numeric/conversion/cast.hpp>
45
46extern int SCENE_PRE_RENDER_EVENT;
50extern int ANIMATION_END_EVENT;
51
52extern int getScenePreRenderEvent(struct Mmachine*, SCOL_PTR_TYPE, SCOL_PTR_TYPE);
53extern int getScenePreRenderEvent2(struct Mmachine*, SCOL_PTR_TYPE, SCOL_PTR_TYPE);
54extern int getScenePreRenderPhysicEvent(struct Mmachine*, SCOL_PTR_TYPE, SCOL_PTR_TYPE);
55extern int getScenePostRenderEvent(struct Mmachine*, SCOL_PTR_TYPE, SCOL_PTR_TYPE);
56
58extern SMaterialPair* getMaterialPairByWorld(SPhysicWorld* world, int ID1, int ID2);
59
60namespace SO3
61{
62
63SScene::SScene(SRoot* parent, const std::string& sceneName) : SData(sceneName)
64{
65 scolRoot = parent;
66 O3SceneManager = Ogre::Root::getSingleton().createSceneManager("OctreeSceneManager", sceneName);
67
68 //TODO resize scene octree for raycast if the raycast fail on far distances
69 //maybe this will not be needed if the we use rendered depth value in view to get the raycast position
70 //what if we resize the octree when we add a mesh using it's position and boundingbox ?
71 //bool showOctreeDebug = true;
72 //O3SceneManager->setOption("ShowOctree", &showOctreeDebug);
73
74 //Ogre::AxisAlignedBox octreeBox(-1000, -1000, -1000, 1000, 1000, 1000);
75 //O3SceneManager->setOption("Size", &octreeBox);
76
77 //int octreeDepth = 16;
78 //O3SceneManager->setOption("Depth", &octreeDepth);
79
80 //O3SceneManager->setLateMaterialResolving(false);
81 //O3SceneManager->_suppressShadows(true);
82
83 Ogre::RenderQueue* rq = O3SceneManager->getRenderQueue();
84 //rq->getQueueGroup(Ogre::RENDER_QUEUE_WORLD_GEOMETRY_1)->setShadowsEnabled(false);
85 //rq->getQueueGroup(Ogre::RENDER_QUEUE_WORLD_GEOMETRY_2)->setShadowsEnabled(false);
86 //rq->getQueueGroup(Ogre::RENDER_QUEUE_MAIN)->setShadowsEnabled(false);
87 //rq->getQueueGroup(49)->setShadowsEnabled(false);
88
89 cAmbientLight = O3SceneManager->getAmbientLight();
90 animationCounter = 0;
91
92 skyBoxMat.reset();
93 skyDomeMat.reset();
94 skyPlaneMat.reset();
95 hasSkyBox = false;
96 skyBoxDrawFirst = false;
97 hasSkyDome = false;
98 skyDomeDrawFirst = false;
99 hasSkyPlane = false;
100 skyPlaneDrawFirst = false;
101 materialCaster.reset();
102 materialReceiver.reset();
103 mPreTimer.reset();
104 mPostTimer.reset();
105 mLastShadowType = SShadowManager::SO3_SHADOWS_NONE;
106
107 O3MeshManager = Ogre::MeshManager::getSingletonPtr();
108 O3MaterialManager = Ogre::MaterialManager::getSingletonPtr();
109 O3TextureManager = Ogre::TextureManager::getSingletonPtr();
110 O3SkeletonManager = Ogre::SkeletonManager::getSingletonPtr();
111
112 //used for simple ray cast
113 mRayQuery = O3SceneManager->createRayQuery(Ogre::Ray(), Ogre::SceneManager::ENTITY_TYPE_MASK);
114 mRayQuery->setSortByDistance(true);
115
116 SO3DebugOverlay = 0;
117 SO3DebugPanel = 0;
118 SO3DebugTextArea = 0;
119
120 // add default resource group
121 std::string groupResource = name + Ogre::RGN_DEFAULT;
122 try
123 {
124 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(groupResource, false);
125 }
126 catch (Ogre::Exception &e)
127 {
128 MMechostr(MSKDEBUG, "SScene: An exception has occurred: %s\n", e.what());
129 }
130
131 //only on first scene (overlay are common for all scenes and viewports... beurk)
132#if !defined(ANDROID) && !defined(RPI) && !defined(__APPLE__)
133 try
134 {
135 if (parent->GetSceneList().size() == 0)
136 {
137 // init debug overlay
138 SO3DebugFont.reset();
139 SO3DebugFont = Ogre::FontManager::getSingleton().create(sceneName + "_SO3DebugFont", SO3_INTERNAL_RESOURCE_GROUP );
140 SO3DebugFont->setParameter("type", "truetype");
141 SO3DebugFont->setParameter("source", "bluehigh.ttf");
142 SO3DebugFont->setParameter("size", "16");
143 SO3DebugFont->setParameter("resolution", "96");
144 //SO3DebugFont->setParameter("code_points", "33-126");
145 SO3DebugFont->load();
146
147 SO3DebugOverlay = Ogre::OverlayManager::getSingleton().create(sceneName + "_SO3DebugOverlayName");
148 SO3DebugPanel = static_cast<Ogre::OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", sceneName + "_SO3DebugPanelName"));
149 SO3DebugTextArea = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", sceneName + "_SO3DebugTextAreaName"));
150 SO3DebugTextArea->setFontName(SO3DebugFont->getName());
151 SO3DebugOverlay->add2D(SO3DebugPanel);
152 SO3DebugPanel->addChild(SO3DebugTextArea);
153 }
154 }
155 catch (Ogre::Exception &e)
156 {
157 MMechostr(MSKDEBUG, "CreateScene Error : %s\n", e.getDescription().c_str());
158 }
159#endif
160
161 physicWorld = new SPhysicWorld(this);
162
163 // Creating root scene node. Do not add it to node list, to avoid it to be deleted while clearing the scene.
164 rootNode = new SNode(this, O3SceneManager->getRootSceneNode()->getName(), true);
165
166 // Creating the environment instance
167 environment = new SEnvironment(this, sceneName);
168
169 //TODO get all viewports and call RegisterViewport()
170
171 // Creating Lighting manager.
172 lightingManager = new SLightingManager(this);
173
174 //RTSS
175 //const Ogre::RenderSystemCapabilities* caps = O3Render->getCapabilities();
176 //if (caps && caps->hasCapability(Ogre::RSC_FIXED_FUNCTION) == false)
177 Ogre::RTShader::ShaderGenerator::getSingletonPtr()->addSceneManager(O3SceneManager);
178}
179
180SScene::SScene() : SData("")
181{
182 // Forbiden (private).
183}
184
186{
187 if (lightingManager != 0)
188 lightingManager->Reset();
189
190 mLastShadowType = SShadowManager::SO3_SHADOWS_NONE;
191
192 // clear all windows ray cast result to avoid bad pointer reference
193 const SWindowMap windowListCopy = GetParent()->GetRenderWindowList();
194 SWindowMap::const_iterator iWindowList = windowListCopy.begin();
195 while (iWindowList != windowListCopy.end())
196 {
197 iWindowList->second->InvalidateRayCast();
198 iWindowList++;
199 }
200
202 // ! Ogre Compositor Destruction
203 // Destroy all Compositors not protected by /Core /BaseWhite /Stereo
205 /*
206 TODO JEFF
207 Ogre::ResourceManager::ResourceMapIterator itC = Ogre::CompositorManager::getSingleton().getResourceIterator();
208 while(itC.hasMoreElements())
209 {
210 SCompositor* currentCompositor = NULL;
211 Ogre::CompositorPtr cmp = static_cast<Ogre::CompositorPtr>(itC.getNext());
212 GetCompositorByName(this,&currentCompositor,cmp->getName().c_str());
213 if(currentCompositor)
214 {
215 if(currentCompositor->getOgreCompositorViewport()!= NULL)
216 {
217 this->O3CompositorManager->setCompositorEnabled(currentCompositor->getOgreCompositorViewport(), cmp->getName().c_str(), false);
218 if((cmp->getName().find("Ogre/") == string::npos) && (cmp->getName().find("Core/") == string::npos) && (cmp->getName().find("Stereo/") == string::npos))
219 this->O3CompositorManager->removeCompositor(currentCompositor->getOgreCompositorViewport(),cmp->getName().c_str());
220 }
221 }
222 }*/
223
224 // Do this before everithing else, cause this component handles Ogre::Light and other stuff that belongs to the scene, which can be destroy in the lines below.
225 SO3_SAFE_DELETE(environment);
226
227 // Delete all SNode and inherited objects. SBody, SAnimation, etc associated to any SNode are destroyed too.
229
230 // Delete terrains
232
233 // Clear physic material pair callback
234 if(physicWorld)
235 physicWorld->ResetPhysicWorld();
236
237 // Clear sequence animations
239
240 // ! OgreNewton disable
241 if(physicWorld)
242 physicWorld->SetPhysicWorldEnable(false);
243
244 O3SceneManager->destroyAllBillboardChains();
245 O3SceneManager->destroyAllBillboardSets();
246 O3SceneManager->destroyAllRibbonTrails();
247
248 O3SkeletonManager->unloadAll(false);
249 O3SkeletonManager->removeAll();
250
251 // ! Skies Destruction
252 //O3SceneManager->destroyAllInstancedGeometry();
253
254 Ogre::SceneManager::MovableObjectMap movableList = O3SceneManager->getMovableObjects("ManualObject");
255 for (Ogre::SceneManager::MovableObjectMap::iterator itMO = movableList.begin(); itMO != movableList.end(); itMO++)
256 {
257 Ogre::ManualObject* curObj = static_cast<Ogre::ManualObject *>(itMO->second);
258 if(strcmp(curObj->getName().c_str(),"SkyBox"))
259 O3SceneManager->destroyManualObject(curObj->getName());
260 }
261
262 this->O3SceneManager->destroyAllStaticGeometry();
263
264 if(hasSkyBox)
265 O3SceneManager->setSkyBox(false, skyBoxMat->getName());
266
267 if(this->hasSkyDome)
268 O3SceneManager->setSkyDome(false, skyDomeMat->getName());
269
270 if(this->hasSkyPlane)
271 O3SceneManager->setSkyPlane(false, skyPlane, skyPlaneMat->getName());
272
273 // Delete all materials
275
276 // Delete all textures
278
279 // ! Clear Ogre Scene
280 O3SceneManager->clearScene();
281
282 //reset octree settings
283 //bool showOctreeDebug = true;
284 //O3SceneManager->setOption("ShowOctree", &showOctreeDebug);
285
286 //Ogre::AxisAlignedBox octreeBox(-1000, -1000, -1000, 1000, 1000, 1000);
287 //O3SceneManager->setOption("Size", &octreeBox);
288
289 //int octreeDepth = 16;
290 //O3SceneManager->setOption("Depth", &octreeDepth);
291
292 //const Ogre::RenderSystemCapabilities* caps = SRoot::getSingletonPtr()->GetOgreRenderSystem()->getCapabilities();
293 //if (caps && caps->hasCapability(Ogre::RSC_FIXED_FUNCTION) == false)
294 Ogre::RTShader::ShaderGenerator::getSingletonPtr()->removeAllShaderBasedTechniques();
295
296 // Reset fog setting
297 O3SceneManager->setFog(Ogre::FOG_NONE, Ogre::ColourValue::White, 0, 0, 0);
298
299 // Everything was resetted, we can re-create our environment.
300 environment = new SEnvironment(this, name);
301}
302
304{
305 if (SO3DebugOverlay)
306 {
307 Ogre::OverlayManager::getSingleton().destroyOverlayElement(static_cast<Ogre::OverlayElement*>(SO3DebugPanel));
308 Ogre::OverlayManager::getSingleton().destroyOverlayElement(static_cast<Ogre::OverlayElement*>(SO3DebugTextArea));
309 Ogre::OverlayManager::getSingleton().destroy(SO3DebugOverlay);
310 SO3DebugPanel = 0;
311 SO3DebugTextArea = 0;
312 SO3DebugOverlay = 0;
313 }
314
315 if (mRayQuery)
316 {
317 O3SceneManager->destroyQuery(mRayQuery);
318 mRayQuery = 0;
319 }
320
321 // Unload debug font
322 if (SO3DebugFont)
323 {
324 Ogre::FontManager::getSingleton().remove(SO3DebugFont);
325 SO3DebugFont.reset();
326 }
327
328 if (lightingManager != 0)
329 lightingManager->Reset();
330
331 // clear all windows ray cast result to avoid bad pointer reference
332 const SWindowMap windowListCopy = GetParent()->GetRenderWindowList();
333 SWindowMap::const_iterator iWindowList = windowListCopy.begin();
334 while (iWindowList != windowListCopy.end())
335 {
336 iWindowList->second->InvalidateRayCast();
337 iWindowList++;
338 }
339
340 // Do this before everithing else, cause this component handles Ogre::Light and other stuff that belongs to the scene, which can be destroy in the lines below.
341 SO3_SAFE_DELETE(environment);
342
343 // Delete all SNode and inherited objects. SBody, SAnimation, etc associated to any SNode are destroyed too.
345
346 // Delete terrains
348
349 // Clear physic material pair callback
350 if(physicWorld)
351 physicWorld->ResetPhysicWorld();
352
353 // Clear sequence animations
355
356 // ! OgreNewton disable
357 if(physicWorld)
358 physicWorld->SetPhysicWorldEnable(false);
359
360 //$BB Why Snode not enought ?
361 O3SceneManager->destroyAllBillboardChains();
362 O3SceneManager->destroyAllBillboardSets();
363 O3SceneManager->destroyAllRibbonTrails();
364
365 O3SkeletonManager->unloadAll(false);
366 O3SkeletonManager->removeAll();
367
368 // ! Skies Destruction
369 //O3SceneManager->destroyAllInstancedGeometry();
370
371 Ogre::SceneManager::MovableObjectMap movableList = O3SceneManager->getMovableObjects("ManualObject");
372 for (Ogre::SceneManager::MovableObjectMap::iterator itMO = movableList.begin(); itMO != movableList.end(); itMO++)
373 {
374 Ogre::ManualObject* curObj = static_cast<Ogre::ManualObject *>(itMO->second);
375 if (strcmp(curObj->getName().c_str(), "SkyBox"))
376 O3SceneManager->destroyManualObject(curObj->getName());
377 }
378
379 this->O3SceneManager->destroyAllStaticGeometry();
380
381 // Delete all materials
383
384 // Delete all textures
386
387 SO3_SAFE_DELETE(lightingManager);
388 SO3_SAFE_DELETE(rootNode);
389
390 nodeList.clear();
391 listOfMaterial.clear();
392 listOfTexture.clear();
393
394 // ! Clear Ogre Scene
395 O3SceneManager->clearScene();
396
397 Ogre::RTShader::ShaderGenerator::getSingletonPtr()->removeSceneManager(O3SceneManager);
398
399 Ogre::Root::getSingleton().destroySceneManager(O3SceneManager);
400 SAFE_DELETE(physicWorld);
401
402 std::string groupResource(GetName() + Ogre::RGN_DEFAULT);
403 Ogre::ResourceGroupManager::getSingleton().destroyResourceGroup(groupResource);
404}
405
406bool SScene::NodeExist(const std::string &name)
407{
408 SNodeMap::iterator iNodeSearched = nodeList.find(name);
409 if (iNodeSearched == nodeList.end())
410 return false;
411 else
412 return true;
413}
414
415bool SScene::AddNode(SNode* existingNode)
416{
417 string nodeName = existingNode->GetName();
418 SNodeMap::iterator iNodeSearched = nodeList.find(nodeName);
419 if (iNodeSearched == nodeList.end())
420 {
421 nodeList.insert(SNodeMap::value_type(nodeName, existingNode));
422 return true;
423 }
424 else
425 {
426 return false;
427 }
428}
429
430void SScene::RemoveNode(SNode* existingNode)
431{
432 RemoveNode(existingNode->GetName());
433}
434
435void SScene::RemoveNode(const std::string& nodeName)
436{
437 SNodeMap::iterator iNodeSearched = nodeList.find(nodeName);
438 if (iNodeSearched != nodeList.end())
439 {
440 nodeList.erase(iNodeSearched);
441 }
442 else
443 {
444 // Node not found in the handled nodes list
445 OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND, "Can not remove Node named \""+ nodeName +"\", element not found!", "SScene::RemoveNode");
446 }
447}
448
449Ogre::SceneManager* SScene::GetOgreScenePointer()
450{
451 return O3SceneManager;
452}
453
455{
456 return rootNode;
457}
458
459SNode* SScene::GetNode(const std::string& nodeName) const
460{
461 SNodeMap::const_iterator iNodeSearched = nodeList.find(nodeName);
462 if (iNodeSearched != nodeList.end())
463 return iNodeSearched->second;
464 else
465 return 0;
466}
467
469{
470 if (SRoot::getSingletonPtr()->isDeviceLost())
471 return;
472
473 unsigned long frameTime = mPreTimer.getMicroseconds();
474 mPreTimer.reset();
475
476 float timef = (float)frameTime * 0.000001;
477 if (timef == 0.0f)
478 timef = 0.000001f;
479
480 int mframetime = 0;
481 try
482 {
483 mframetime = boost::numeric_cast<int>(frameTime);
484 }
485 catch (std::exception&)
486 {
487 mframetime = 100;
488 }
489
490 getScenePreRenderEvent(mm, SCOL_PTR this, (LONG)mframetime);
491
492 //update animations and bodies for node animation sync
493 Ogre::FrameEvent evt;
494 evt.timeSinceLastFrame = timef;
495 evt.timeSinceLastEvent = timef;
496
497 //UpdateAllTerrains();
498
499 //update sequence animations
500 SAnimMap seqAnimList = animationList;
501 SAnimMap::const_iterator iSeqAnimList = seqAnimList.begin();
502
503 //two pass one for anim sequence the other for nodes
504 while(iSeqAnimList != seqAnimList.end())
505 {
506 SAnim* curAnim = iSeqAnimList->second;
507 if (curAnim->GetType() == SAnim::SO3_SEQUENCE_ANIM)
508 curAnim->Update(evt);
509
510 iSeqAnimList++;
511 }
512
513 iSeqAnimList = seqAnimList.begin();
514 while(iSeqAnimList != seqAnimList.end())
515 {
516 SAnim* curAnim = iSeqAnimList->second;
517 SNode* curNode = curAnim->GetParentNode();
518
519 if ((curAnim->GetType() != SAnim::SO3_SEQUENCE_ANIM) && curAnim->GetEnable() && !curAnim->GetPaused())
520 {
521 curAnim->Update(evt);
522
523 //force animations Update
524 //code from ogre _renderScene, this duplicate the animation update but we do not change the animation frame in the scene manager
525 O3SceneManager->_applySceneAnimations();
526
527 if(curNode && physicWorld && physicWorld->GetPhysicWorldEnable())
528 {
529 curNode->UpdateNodeBody(true);
530
531 // not needed anymore
532 /*if (curNode->GetNodeType() == SNode::ENTITY_TYPE_ID && curAnim->GetType() == SAnim::SO3_SKELETAL_ANIM)
533 {
534 SEntity* curEntity = static_cast<SEntity*> (curNode);
535 SSkeleton* skeleton = curEntity->GetSkeleton();
536 if (skeleton)
537 {
538 SBoneMap boneList = skeleton->GetBones();
539 SBoneMap::const_iterator iBones = boneList.begin();
540 while (iBones != boneList.end());
541 {
542 iBones->second->UpdateNodeBody(false);
543 }
544 }
545 }*/
546 }
547 }
548
549 iSeqAnimList++;
550 }
551
552 getScenePreRenderPhysicEvent(mm, SCOL_PTR this, (LONG)mframetime);
553
554 if(physicWorld)
555 physicWorld->UpdatePhysic(timef);
556
557 // raycast are enable even if physics is disable
558 if (physicWorld && physicWorld->GetPhysicDebugger())
560
561 getScenePreRenderEvent2(mm, SCOL_PTR this, (LONG)mframetime);
562}
563
565{
566 if (SRoot::getSingletonPtr()->isDeviceLost())
567 return;
568
569 int mframetime = 0;
570 try
571 {
572 mframetime = boost::numeric_cast<int>(mPostTimer.getMicroseconds());
573 }
574 catch (std::exception&)
575 {
576 mframetime = 100;
577 }
578
579 if (mframetime == 0)
580 mframetime = 1;
581 mPostTimer.reset();
582
583 getScenePostRenderEvent(mm, SCOL_PTR this, (LONG)mframetime);
584
585 //SendMessage(hwndScol, SCENE_POST_RENDER_EVENT, (int)this, (LONG)frameTime);
586}
587
589{
590 return nodeList;
591}
592
593
595{
596 return terrainList;
597}
598
599SNode* SScene::CreateNode(const std::string& newNodeName)
600{
601 // Node already exist in the handled nodes list.
602 if (NodeExist(newNodeName))
603 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newNodeName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
604
605 SNode* newNode = new SNode(this, newNodeName);
606 AddNode(newNode);
607
608 return newNode;
609}
610
611SNode* SScene::CreateNodeWithUniqueName(const std::string& basename)
612{
613 size_t ID = nodeList.size();
614
615 std::stringstream ss;
616 ss << basename;
617 ss << ID;
618 string name = ss.str();
619
620 // Node already exist in the handled nodes list.
621 if (NodeExist(name))
622 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + name + "\", an element with the same name already exist!", "SScene::CreateNode", true);
623
624 SNode* newNode = new SNode(this, name);
625 AddNode(newNode);
626
627 return newNode;
628}
629
630void SScene::DeleteNode(SNode* existingNode)
631{
632 if (existingNode != rootNode)
633 {
634 RemoveNode(existingNode);
635 SO3_SAFE_DELETE(existingNode);
636 }
637}
638
640{
641 SVirtualPointer* newVirtualPointer = new SVirtualPointer(this, basename);
642
643 if (!AddNode(newVirtualPointer))
644 {
645 SAFE_DELETE(newVirtualPointer);
646 // Node already exist in the handled nodes list.
647 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + basename + "\", an element with the same name already exist!", "SScene::CreateVirtualPointer", true);
648 }
649
650 return newVirtualPointer;
651}
652
653SCamera* SScene::CreateCamera(const std::string& newCameraName)
654{
655 // Node already exist in the handled nodes list.
656 if (NodeExist(newCameraName))
657 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newCameraName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
658
659 SCamera* newCamera = new SCamera(this, newCameraName);
660 AddNode(newCamera);
661
662 return newCamera;
663}
664
665SEntity* SScene::CreateEntity(const std::string& groupName, const std::string& newEntityName, const std::string& meshName, bool loadInBackground)
666{
667 // Node already exist in the handled nodes list.
668 if (NodeExist(newEntityName))
669 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newEntityName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
670
671 SEntity* newEntity = new SEntity(this, groupName, newEntityName, meshName, loadInBackground);
672 AddNode(newEntity);
673
674 return newEntity;
675}
676
677SEntity* SScene::CreateEntity(const std::string& newEntityName, const SEntity::EntityPrefabType& prefabType)
678{
679 // Node already exist in the handled nodes list.
680 if (NodeExist(newEntityName))
681 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newEntityName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
682
683 SEntity* newEntity = new SEntity(this, newEntityName, prefabType);
684 AddNode(newEntity);
685
686 return newEntity;
687}
688
689SEntity* SScene::CreateEntity(const std::string& entityName, const std::string& ressourceGroup, Ogre::MeshPtr meshPointer)
690{
691 // Node already exist in the handled nodes list.
692 if (NodeExist(entityName))
693 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + entityName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
694
695 SEntity* newEntity = new SEntity(this, entityName, ressourceGroup, meshPointer);
696 AddNode(newEntity);
697
698 return newEntity;
699}
700
701SEntity* SScene::CloneEntity(const std::string& newEntityName, SEntity* entity)
702{
703 // Node already exist in the handled nodes list.
704 if (NodeExist(newEntityName))
705 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newEntityName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
706
707 SEntity* newEntity = new SEntity(this, newEntityName, entity->GetGroupName(), entity->getOgreEntityPointer()->getMesh());
708 AddNode(newEntity);
709
710 //Apply source entity parameters
711 newEntity->AttachToParent(entity->GetParentSceneNode());
712 newEntity->SetScale(entity->GetScale());
713 newEntity->SetPosition(entity->GetPosition());
714 newEntity->SetOrientation(entity->GetOrientation());
715 newEntity->SetCastShadows(entity->GetCastShadows());
716 newEntity->SetFlags(entity->GetFlags());
717 newEntity->SetRenderingDistance(entity->GetRenderingDistance());
721 newEntity->SetVisibilityFlags(entity->GetVisibilityFlags());
722 newEntity->SetVisible(entity->GetVisible());
723
724 return newEntity;
725}
726
727SEntity* SScene::CreatePlane(const std::string& groupName, const std::string& newEntityName, const SPointFloat& sizev, const SPointInt& seg, const SPointFloat& uv)
728{
729 // check for valid group name
730 if(!checkGroupExists(groupName))
731 SO3_EXCEPT(SExceptionItemIdentity, "No ressource group named \""+ groupName +"\" found, plane creation aborted!", "SScene::CreatePlane", true);
732
733 // Node already exist in the handled nodes list.
734 if (NodeExist(newEntityName))
735 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newEntityName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
736
737 SEntity* newEntity = new SEntity(this, groupName, newEntityName, sizev, seg, uv);
738 AddNode(newEntity);
739
740 return newEntity;
741}
742
743SEntity* SScene::CreateSphere(const std::string& groupName, const std::string& newEntityName, const float& radius, const int& rings, const int& segments)
744{
745 // check for valid group name
746 if (!checkGroupExists(groupName))
747 SO3_EXCEPT(SExceptionItemIdentity, "No ressource group named \"" + groupName + "\" found, sphere creation aborted!", "SScene::CreateSphere", true);
748
749 // Node already exist in the handled nodes list.
750 if (NodeExist(newEntityName))
751 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newEntityName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
752
753 SEntity* newEntity = new SEntity(this, groupName, newEntityName, radius, rings, segments);
754 AddNode(newEntity);
755
756 return newEntity;
757}
758
759SEntity* SScene::CreateCone(const std::string& groupName, const std::string& newEntityName, const float& radius, const float& height, const int& segments)
760{
761 // check for valid group name
762 if (!checkGroupExists(groupName))
763 SO3_EXCEPT(SExceptionItemIdentity, "No ressource group named \"" + groupName + "\" found, cone creation aborted!", "SScene::CreateCone", true);
764
765 // Node already exist in the handled nodes list.
766 if (NodeExist(newEntityName))
767 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newEntityName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
768
769 SEntity* newEntity = new SEntity(this, groupName, newEntityName, radius, height, segments);
770 AddNode(newEntity);
771
772 return newEntity;
773}
774
775SEntity* SScene::CreateOctahedron(const std::string& groupName, const std::string& newEntityName, const float& base, const float& bottom, const float& dist)
776{
777 // check for valid group name
778 if (!checkGroupExists(groupName))
779 SO3_EXCEPT(SExceptionItemIdentity, "No ressource group named \"" + groupName + "\" found, cone creation aborted!", "SScene::CreateOctahedron", true);
780
781 // Node already exist in the handled nodes list.
782 if (NodeExist(newEntityName))
783 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newEntityName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
784
785 SEntity* newEntity = new SEntity(this, groupName, newEntityName, base, bottom, dist);
786 AddNode(newEntity);
787
788 return newEntity;
789}
790
791void SScene::DeleteEntity(SEntity* existingEntity)
792{
793 DeleteNode(existingEntity);
794}
795
797{
798 SNodeMap::iterator iNodeit = nodeList.begin();
799 while (iNodeit != nodeList.end())
800 {
801 SNode* tnode = iNodeit->second;
802 if (tnode->GetNodeType() == SNode::ENTITY_TYPE_ID)
803 static_cast<SEntity*> (tnode)->Reload();
804
805 iNodeit++;
806 }
807}
808
809SLineEntity* SScene::CreateLineEntity(const std::string& newLineEntityName, bool dashed, bool disableDepth)
810{
811 // Node already exist in the handled nodes list.
812 if (NodeExist(newLineEntityName))
813 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newLineEntityName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
814
815 SLineEntity* newLineEntity = new SLineEntity(this, newLineEntityName, dashed, disableDepth);
816 AddNode(newLineEntity);
817
818 return newLineEntity;
819}
820
821void SScene::DeleteLineEntity(SLineEntity* existingLineEntity)
822{
823 DeleteNode(existingLineEntity);
824}
825
826STerrain* SScene::CreateTerrain(const std::string& name)
827{
828 STerrain* terrain = new STerrain(this, name);
829 terrainList.insert(STerrainMap::value_type(name, terrain));
830
831 return terrain;
832}
833
835{
836 STerrainMap::iterator iTerrainSearched = terrainList.find(terrain->GetName());
837 if (iTerrainSearched != terrainList.end())
838 {
839 terrainList.erase(iTerrainSearched);
840 }
841 SAFE_DELETE(terrain);
842}
843
845{
846 Ogre::Vector3 sunDir(0.5f, 0.5f, 1.0f);
847 Ogre::ColourValue sunColor;
848 Ogre::ColourValue ambColor = O3SceneManager->getAmbientLight();
849 if (environment)
850 {
851 SSun* sun = environment->GetSun();
852 if(sun)
853 {
854 sunColor = sun->GetOgreLight()->getDiffuseColour();
855 sunDir = sun->GetOgreLight()->getDerivedDirection();
856 }
857 SMoon* moon = environment->GetMoon();
858 if(moon)
859 {
860 moon->UpdateShadowFarDistance(O3SceneManager->getShadowFarDistance());
861 moon->UpdateShadowFarClipDistance(O3SceneManager->getShadowDirectionalLightExtrusionDistance());
862 }
863 }
864
865 sunDir.normalise();
866
867 STerrainMap::iterator iTerrainit = terrainList.begin();
868 while (iTerrainit != terrainList.end())
869 {
870 STerrain* terrain = iTerrainit->second;
871 terrain->UpdateLight(ambColor, sunColor, sunDir);
872 iTerrainit++;
873 }
874}
875
877{
878 // Delete all STerrain
879 const STerrainMap terrainListCopy = terrainList;
880 STerrainMap::const_iterator iTerrainList = terrainListCopy.begin();
881 while (iTerrainList != terrainListCopy.end())
882 {
883 DeleteTerrain(iTerrainList->second);
884 iTerrainList++;
885 }
886 terrainList.clear();
887}
888
890{
891 SNodeMap::iterator iNodeit = nodeList.begin();
892 while (iNodeit != nodeList.end())
893 {
894 SNode* tnode = iNodeit->second;
895 if (tnode->GetNodeType() == SNode::LIGHT_TYPE_ID)
896 {
897 SLight* light = static_cast<SLight*>(tnode);
898 light->UpdateShadowFarDistance(O3SceneManager->getShadowFarDistance());
899
901 light->UpdateShadowFarClipDistance(O3SceneManager->getShadowDirectionalLightExtrusionDistance());
902 else
903 light->UpdateShadowFarClipDistance(O3SceneManager->getShadowFarDistance());
904 }
905
906 iNodeit++;
907 }
908
909 if (environment)
910 {
911 SSun* sun = environment->GetSun();
912 if(sun)
913 {
914 sun->UpdateShadowFarDistance(O3SceneManager->getShadowFarDistance());
915 sun->UpdateShadowFarClipDistance(O3SceneManager->getShadowDirectionalLightExtrusionDistance());
916 }
917
918 SMoon* moon = environment->GetMoon();
919 if(moon)
920 {
921 moon->UpdateShadowFarDistance(O3SceneManager->getShadowFarDistance());
922 moon->UpdateShadowFarClipDistance(O3SceneManager->getShadowDirectionalLightExtrusionDistance());
923 }
924 }
925}
926
927SSkeleton* SScene::CreateSkeleton(const std::string& newSkeletonName, SEntity* entity)
928{
929 // Node already exist in the handled nodes list.
930 if (NodeExist(newSkeletonName))
931 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newSkeletonName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
932
933 SSkeleton* newSkeleton = new SSkeleton(this, newSkeletonName, entity);
934 AddNode(newSkeleton);
935
936 // Generate all the bones and animation for this skeleton
937 newSkeleton->Initialise();
938 return newSkeleton;
939}
940
941void SScene::DeleteSkeleton(SSkeleton* existingSkeleton)
942{
943 DeleteNode(existingSkeleton);
944}
945
946SBone* SScene::CreateBone(const std::string& newBoneName, SSkeleton* skeleton, const unsigned short& id)
947{
948 // Node already exist in the handled nodes list.
949 if (NodeExist(newBoneName))
950 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newBoneName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
951
952 SBone* newBone = new SBone(this, newBoneName, skeleton, id);
953 AddNode(newBone);
954
955 return newBone;
956}
957
958void SScene::DeleteBone(SBone* existingBone)
959{
960 DeleteNode(existingBone);
961}
962
963SParticleSystem* SScene::CreateParticleSystem(const std::string& newParticleSystemName, const std::string& particleSystemTemplate)
964{
965 // Node already exist in the handled nodes list.
966 if (NodeExist(newParticleSystemName))
967 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newParticleSystemName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
968
969 SParticleSystem* newParticleSystem = new SParticleSystem(this, newParticleSystemName, particleSystemTemplate);
970 AddNode(newParticleSystem);
971
972 return newParticleSystem;
973}
974
976{
977 DeleteNode(existingParticleSystem);
978}
979
980SLight* SScene::CreateLight(const std::string& newLightName)
981{
982 // Node already exist in the handled nodes list.
983 if (NodeExist(newLightName))
984 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newLightName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
985
986 SLight* newLight = new SLight(this, newLightName);
987 AddNode(newLight);
988
989 return newLight;
990}
991
992void SScene::DeleteLight(SLight* existingLight)
993{
994 DeleteNode(existingLight);
995}
996
997SDynamicCubeMap* SScene::CreateDynamicCubeMap(const std::string& newDynamicCubeMapName)
998{
999 // Node already exist in the handled nodes list.
1000 if (NodeExist(newDynamicCubeMapName))
1001 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newDynamicCubeMapName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
1002
1003 SDynamicCubeMap* newDynamicCubeMap = new SDynamicCubeMap(this, newDynamicCubeMapName);
1004 AddNode(newDynamicCubeMap);
1005
1006 return newDynamicCubeMap;
1007}
1008
1010{
1011 DeleteNode(existingDynamicCubeMap);
1012}
1013
1014SRenderToTexture* SScene::CreateRenderToTexture(const std::string& newRttName, SCamera* povCamera)
1015{
1016 // Node already exist in the handled nodes list.
1017 if (NodeExist(newRttName))
1018 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newRttName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
1019
1020 SRenderToTexture* newRenderToTexture = new SRenderToTexture(this, newRttName, povCamera);
1021 AddNode(newRenderToTexture);
1022
1023 return newRenderToTexture;
1024}
1025
1027{
1028 DeleteNode(existingRenderToTexture);
1029}
1030
1031SDynamicReflectionMap* SScene::CreateDynamicReflectionMap(SViewPort* viewport, const std::string& newDynamicReflectionMapName)
1032{
1033 // Node already exist in the handled nodes list.
1034 if (NodeExist(newDynamicReflectionMapName))
1035 SO3_EXCEPT(SExceptionItemIdentity, "Can not add node named \"" + newDynamicReflectionMapName + "\", an element with the same name already exist!", "SScene::CreateNode", true);
1036
1037 SDynamicReflectionMap* newDynamicReflectionMap = new SDynamicReflectionMap(this, viewport, newDynamicReflectionMapName);
1038 AddNode(newDynamicReflectionMap);
1039
1040 return newDynamicReflectionMap;
1041}
1042
1044{
1045 DeleteNode(existingDynamicReflectionMap);
1046}
1047
1048SMaterial* SScene::CreateMaterial(const std::string& groupname, const std::string& matname, const bool& loadedFromScript)
1049{
1050 // check for valid group name
1051 if (!checkGroupExists(groupname))
1052 SO3_EXCEPT(SExceptionItemIdentity, "No ressource group named \"" + groupname + "\" found, material creation aborted!", "SScene::CreateMaterial", true);
1053
1054 // search for existing material
1055 if (GetMaterial(groupname, matname, false))
1056 SO3_EXCEPT(SExceptionItemIdentity, "A material named \""+ matname +"\" already exist in resource group \""+ groupname +"\", material creation aborted!", "SScene::CreateMaterial", true);
1057
1058 SMaterialMap* materialMap;
1059 SGroupMaterialMap::iterator iGroupSearched = listOfMaterial.find(groupname);
1060 if(iGroupSearched != listOfMaterial.end())
1061 {
1062 materialMap = iGroupSearched->second;
1063 }
1064 else
1065 {
1066 materialMap = new SMaterialMap();
1067 listOfMaterial.insert(SGroupMaterialMap::value_type(groupname, materialMap));
1068 }
1069
1070 SMaterial* material = new SMaterial(this, groupname, matname, loadedFromScript);
1071 materialMap->insert(SMaterialMap::value_type(matname, material));
1072 return material;
1073}
1074
1076{
1077 // Search for the material group in our scene material group list
1078 SGroupMaterialMap::const_iterator iGroupSearched = listOfMaterial.find(material->GetGroupName());
1079 if(iGroupSearched != listOfMaterial.end())
1080 {
1081 // Search for the material in the group, and remove from list
1082 SMaterialMap* materialMap = static_cast<SMaterialMap*> (iGroupSearched->second);
1083 SMaterialMap::const_iterator iMaterialSearched = materialMap->find(material->GetName());
1084 if(iMaterialSearched != materialMap->end())
1085 materialMap->erase(iMaterialSearched);
1086
1087 // If group is empty, then delete if
1088 if(materialMap->empty())
1089 {
1090 listOfMaterial.erase(iGroupSearched);
1091 delete (materialMap);
1092 }
1093
1094 // Delete the material instance
1095 delete(material);
1096 }
1097}
1098
1099SMaterial* SScene::GetMaterial(const std::string& groupName, const std::string& materialName, bool searchOtherGroups)
1100{
1101 SGroupMaterialMap::const_iterator iGroupSearched = listOfMaterial.find(groupName);
1102 if(iGroupSearched != listOfMaterial.end())
1103 {
1104 SMaterialMap* materialMap = iGroupSearched->second;
1105 SMaterialMap::iterator iMaterialSearched = materialMap->find(materialName);
1106 if(iMaterialSearched != materialMap->end())
1107 {
1108 return iMaterialSearched->second;
1109 }
1110 else if (searchOtherGroups)
1111 {
1112 //search other groups
1113 iGroupSearched = listOfMaterial.begin();
1114 while (iGroupSearched != listOfMaterial.end())
1115 {
1116 materialMap = iGroupSearched->second;
1117 iMaterialSearched = materialMap->find(materialName);
1118 if (iMaterialSearched != materialMap->end())
1119 {
1120 return iMaterialSearched->second;
1121 }
1122
1123 iGroupSearched++;
1124 }
1125 return 0;
1126 }
1127 }
1128 else if (searchOtherGroups)
1129 {
1130 //search other groups
1131 iGroupSearched = listOfMaterial.begin();
1132 while (iGroupSearched != listOfMaterial.end())
1133 {
1134 SMaterialMap* materialMap = iGroupSearched->second;
1135 SMaterialMap::iterator iMaterialSearched = materialMap->find(materialName);
1136 if (iMaterialSearched != materialMap->end())
1137 {
1138 return iMaterialSearched->second;
1139 }
1140
1141 iGroupSearched++;
1142 }
1143 }
1144 return 0;
1145}
1146
1147const SMaterialMap* SScene::GetMaterials(const std::string& groupName)
1148{
1149 SGroupMaterialMap::const_iterator iGroupSearched = listOfMaterial.find(groupName);
1150 if(iGroupSearched != listOfMaterial.end())
1151 return iGroupSearched->second;
1152 else
1153 return 0;
1154}
1155
1157{
1158 return &listOfMaterial;
1159}
1160
1161void SScene::CleanGroupMaterials(const std::string& groupName)
1162{
1163 // clear all windows ray cast result to avoid bad pointer reference
1164 const SWindowMap windowListCopy = GetParent()->GetRenderWindowList();
1165 SWindowMap::const_iterator iWindowList = windowListCopy.begin();
1166 while (iWindowList != windowListCopy.end())
1167 {
1168 iWindowList->second->InvalidateRayCast();
1169 iWindowList++;
1170 }
1171
1172 const SGroupMaterialMap groupMaterialListCopy = listOfMaterial;
1173 SGroupMaterialMap::const_iterator iGroupMaterial = groupMaterialListCopy.find(groupName);
1174 if (iGroupMaterial != groupMaterialListCopy.end())
1175 {
1176 const SMaterialMap materialListCopy = (*iGroupMaterial->second);
1177 SMaterialMap::const_iterator iMaterial = materialListCopy.begin();
1178 while(iMaterial != materialListCopy.end())
1179 {
1180 DeleteMaterial(iMaterial->second);
1181 iMaterial++;
1182 }
1183 }
1184}
1185
1186STexture* SScene::CreateTexture(const std::string& groupname, const std::string& texname, const std::string& path, const int& w, const int& h)
1187{
1188 // search for existing material
1189 if (GetTexture (groupname, texname))
1190 return 0;
1191
1192 // check for valid group name
1193 if(!checkGroupExists(groupname))
1194 SO3_EXCEPT(SExceptionItemIdentity, "No ressource group named \""+ groupname +"\" found, texture creation aborted!", "SScene::CreateTexture", true);
1195
1196 STextureMap* textureMap;
1197
1198 SGroupTextureMap::iterator iGroupSearched = listOfTexture.find(groupname);
1199 if(iGroupSearched != listOfTexture.end())
1200 {
1201 textureMap = iGroupSearched->second;
1202 }
1203 else
1204 {
1205 textureMap = new STextureMap();
1206 listOfTexture.insert(SGroupTextureMap::value_type(groupname, textureMap));
1207 }
1208
1209 //search if texture exist
1210 STextureMap::iterator iTextureSearched = textureMap->find(texname);
1211 if(iTextureSearched != textureMap->end())
1212 SO3_EXCEPT(SExceptionItemIdentity, "Texture \""+ texname +"\" already exist, texture creation aborted!", "SScene::CreateTexture", true);
1213
1214 STexture* texture = new STexture(this, groupname, texname, path, w, h);
1215 textureMap->insert(STextureMap::value_type(texname, texture));
1216 return texture;
1217}
1218
1219STexture* SScene::CreateTexture(const std::string& groupname, const std::string& texname, Ogre::Image image)
1220{
1221 // search for existing material
1222 if (GetTexture(groupname, texname))
1223 return 0;
1224
1225 // check for valid group name
1226 if (!checkGroupExists(groupname))
1227 SO3_EXCEPT(SExceptionItemIdentity, "No ressource group named \"" + groupname + "\" found, texture creation aborted!", "SScene::CreateTexture", true);
1228
1229 STextureMap* textureMap;
1230
1231 SGroupTextureMap::iterator iGroupSearched = listOfTexture.find(groupname);
1232 if (iGroupSearched != listOfTexture.end())
1233 {
1234 textureMap = iGroupSearched->second;
1235 }
1236 else
1237 {
1238 textureMap = new STextureMap();
1239 listOfTexture.insert(SGroupTextureMap::value_type(groupname, textureMap));
1240 }
1241
1242 //search if texture exist
1243 STextureMap::iterator iTextureSearched = textureMap->find(texname);
1244 if (iTextureSearched != textureMap->end())
1245 SO3_EXCEPT(SExceptionItemIdentity, "Texture \"" + texname + "\" already exist, texture creation aborted!", "SScene::CreateTexture", true);
1246
1247 STexture* texture = new STexture(this, groupname, texname, image);
1248 textureMap->insert(STextureMap::value_type(texname, texture));
1249 return texture;
1250}
1251
1253{
1254 if(texture)
1255 {
1256 SGroupTextureMap::iterator iGroupSearched = listOfTexture.find(texture->GetGroupName());
1257 if(iGroupSearched != listOfTexture.end())
1258 {
1259 STextureMap* textureMap = static_cast<STextureMap*> (iGroupSearched->second);
1260 STextureMap::iterator iTextureSearched = textureMap->find(texture->GetName());
1261 if(iTextureSearched != textureMap->end())
1262 textureMap->erase(iTextureSearched);
1263
1264 if(textureMap->empty())
1265 {
1266 listOfTexture.erase(iGroupSearched);
1267 delete (textureMap);
1268 }
1269 }
1270
1271 if (texture->getOgreTexturePointer())
1272 {
1273 O3TextureManager->unload(texture->getOgreTexturePointer()->getHandle());
1274 O3TextureManager->remove(texture->getOgreTexturePointer()->getHandle());
1275 }
1276 delete(texture);
1277 }
1278}
1279
1280STexture* SScene::GetTexture(const std::string& groupName, const std::string& texName)
1281{
1282 SGroupTextureMap::iterator iGroupSearched = listOfTexture.find(groupName);
1283 if(iGroupSearched != listOfTexture.end())
1284 {
1285 STextureMap* textureMap = static_cast<STextureMap*> (iGroupSearched->second);
1286 STextureMap::iterator iTextureSearched = textureMap->find(texName);
1287 if(iTextureSearched != textureMap->end())
1288 {
1289 return iTextureSearched->second;
1290 }
1291 return 0;
1292 }
1293 return 0;
1294}
1295
1296const STextureMap* SScene::GetTextures(const std::string& groupName)
1297{
1298 SGroupTextureMap::iterator iGroupSearched = listOfTexture.find(groupName);
1299 if(iGroupSearched != listOfTexture.end())
1300 return iGroupSearched->second;
1301 else
1302 return 0;
1303}
1304
1306{
1307 return &listOfTexture;
1308}
1309
1310void SScene::CleanGroupTextures(const std::string& groupName)
1311{
1312// First, delete all the scene textures
1313 const SGroupTextureMap groupTextureListCopy = listOfTexture;
1314 SGroupTextureMap::const_iterator iGroupTexture = groupTextureListCopy.find(groupName);
1315 if (iGroupTexture != groupTextureListCopy.end())
1316 {
1317 const STextureMap textureListCopy = (*iGroupTexture->second);
1318 STextureMap::const_iterator iTexture = textureListCopy.begin();
1319 while(iTexture != textureListCopy.end())
1320 {
1321 DeleteTexture(iTexture->second);
1322 iTexture++;
1323 }
1324 }
1325}
1326
1328{
1329 return scolRoot;
1330}
1331
1333{
1334 return physicWorld;
1335}
1336
1337SSequenceAnimation* SScene::CreateAnimationSequence(const std::string& animationName)
1338{
1339 SSequenceAnimation* animation = new SSequenceAnimation(this, animationName, animationCounter++);
1340 AddAnimation(animation);
1341 return animation;
1342}
1343
1344void SScene::DeleteAnimation(SAnim* existingAnimation)
1345{
1346 // Verify that anim instance is in handled by this SScene instance.
1347 assert(existingAnimation != 0);
1348 if(GetAnimation(existingAnimation->GetName()) != existingAnimation)
1349 OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS, "Cannot destroy an animation that is not handled by this scene", "SScene::DeleteAnimation");
1350
1351 RemoveAnimation(existingAnimation);
1352 SO3_SAFE_DELETE(existingAnimation);
1353}
1354
1356{
1357 return animationList.size();
1358}
1359
1360SAnim* SScene::GetAnimation(const std::string& animationName)
1361{
1362 SAnimMap::iterator iAnimationSearched = animationList.find(animationName);
1363 if (iAnimationSearched != animationList.end())
1364 return iAnimationSearched->second;
1365 else
1366 return 0;
1367}
1368
1370{
1371 return animationList;
1372}
1373
1374void SScene::AddAnimation(SAnim* existingAnimation)
1375{
1376 string animationName = existingAnimation->GetName();
1377 if (existingAnimation->GetParentNode())
1378 animationName = existingAnimation->GetParentNode()->GetName() + animationName;
1379
1380 SAnimMap::iterator iAnimationSearched = animationList.find(animationName);
1381 if (iAnimationSearched == animationList.end())
1382 {
1383 animationList.insert(SAnimMap::value_type(animationName, existingAnimation));
1384 }
1385 else
1386 {
1387 // Animation already exist in the handled animations list.
1388 SO3_EXCEPT(SExceptionItemIdentity, "Can not add animation named \""+ animationName +"\", an element with the same name already exist!", "SScene::AddAnimation", true);
1389 }
1390}
1391
1392void SScene::RemoveAnimation(SAnim* existingAnimation)
1393{
1394 if (existingAnimation->GetParentNode())
1395 RemoveAnimation(existingAnimation->GetParentNode()->GetName() + existingAnimation->GetName());
1396 else
1397 RemoveAnimation(existingAnimation->GetName());
1398}
1399
1400void SScene::RemoveAnimation(const std::string& animationName)
1401{
1402 SAnimMap::iterator iAnimationSearched = animationList.find(animationName);
1403 if (iAnimationSearched != animationList.end())
1404 {
1405 SAnim* findedAnimation = iAnimationSearched->second;
1406 animationList.erase(iAnimationSearched);
1407 }
1408 else
1409 {
1410 // Animation not found in the handled animations list
1411 OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND, "Can not remove Animation named \""+ animationName +"\", element not found!", "SScene::RemoveAnimation");
1412 }
1413}
1414
1416{
1417 return environment;
1418}
1419
1421{
1422 return lightingManager;
1423}
1424
1426{
1427 if (lightingManager != 0)
1428 return lightingManager->GetShadowManager()->GetShadowType();
1429 else
1431}
1432
1434{
1435 mLastShadowType = shadowType;
1436 if (lightingManager == 0)
1437 return;
1438
1439 lightingManager->GetShadowManager()->SetShadowType(shadowType);
1440}
1441
1443{
1444 if (lightingManager != 0)
1445 return lightingManager->GetShadowManager()->GetShadowQuality();
1446 else
1448}
1449
1451{
1452 if (lightingManager == 0)
1453 return;
1454
1455 lightingManager->GetShadowManager()->SetShadowQuality(quality);
1456}
1457
1459{
1460 if (lightingManager)
1461 return lightingManager->GetShadowManager();
1462 else
1463 return 0;
1464}
1465
1467{
1468 //if (lightingManager)
1469 //lightingManager->GetShadowManager()->SetShadowType(SShadowManager::SO3_SHADOWS_NONE);
1470}
1471
1473{
1474 //if (lightingManager)
1475 //lightingManager->GetShadowManager()->SetShadowType(mLastShadowType);
1476}
1477
1478Ogre::ColourValue SScene::GetAmbientLight()
1479{
1480 return cAmbientLight;
1481}
1482
1483void SScene::SetAmbientLight(const Ogre::ColourValue& color)
1484{
1485 cAmbientLight = color;
1486 O3SceneManager->setAmbientLight(color);
1487}
1488
1490{
1491 if (environment != 0)
1492 environment->UpdateCamera(viewport);
1493}
1494
1496{
1497 //Let manual register
1498 //if (environment != 0)
1499 //environment->RegisterViewport(viewport);
1500}
1501
1503{
1504 if (environment != 0)
1506}
1507
1508bool SScene::UnloadResource(Ogre::ResourceManager* resMgr, const std::string& resName, const std::string& groupName)
1509{
1510 if (!resMgr)
1511 return false;
1512
1513 Ogre::ResourcePtr rPtr = resMgr->getResourceByName(resName, groupName);
1514 if (!rPtr)
1515 {
1516 // Resource no longer exists
1517 return true;
1518 }
1519
1520 rPtr->unload();
1521 if (rPtr->isLoaded())
1522 {
1523 // Resource was not unloaded
1524 0;
1525 }
1526 else
1527 {
1528 // Resource was unloaded
1529 0;
1530 }
1531
1532 resMgr->remove(resName);
1533 rPtr = resMgr->getResourceByName(resName, groupName);
1534 if (!rPtr)
1535 {
1536 // Resource was removed
1537 0;
1538 }
1539 else
1540 {
1541 // Resource was not removed
1542 0;
1543 }
1544
1545 if (resMgr->resourceExists(resName))
1546 {
1547 // Resource still exists:
1548 return false;
1549 0;
1550 }
1551 else
1552 {
1553 // Resource no longer exists
1554 return true;
1555 }
1556}
1557
1558bool SScene::UnloadResource(Ogre::ParticleSystemManager* resMgr, const std::string& resName)
1559{
1560 if (!resMgr)
1561 return false;
1562
1563 try
1564 {
1565 resMgr->removeTemplate(resName, true);
1566 }
1567 catch (Ogre::Exception &)
1568 {
1569 // do not exist
1570 return true;
1571 }
1572
1573 return true;
1574}
1575
1576bool SScene::UnloadMaterials(const std::string& filename, const std::string& groupName)
1577{
1578 if (filename.empty())
1579 {
1580 Ogre::LogManager::getSingleton().logMessage("Filename is empty.");
1581 return false;
1582 }
1583
1584 Ogre::DataStreamPtr stream;
1585 try
1586 {
1587 stream = Ogre::ResourceGroupManager::getSingleton().openResource(filename, groupName);
1588 if (stream)
1589 {
1590 while (!stream->eof())
1591 {
1592 std::string line = stream->getLine();
1593 Ogre::StringUtil::trim(line);
1594
1598 if (Ogre::StringUtil::startsWith(line, "material"))
1599 {
1600 Ogre::StringVector vec = Ogre::StringUtil::split(line, " \t:");
1601 bool skipFirst = true;
1602 for (Ogre::StringVector::iterator it = vec.begin(); it < vec.end(); ++it)
1603 {
1604 if (skipFirst)
1605 {
1606 skipFirst = false;
1607 continue;
1608 }
1609 std::string match = (*it);
1610 Ogre::StringUtil::trim(match);
1611 if (match.front() == '"' && match.back() == '"')
1612 {
1613 match.erase(0, 1); // erase the first character
1614 match.erase(match.size() - 1); // erase the last character
1615 }
1616
1617 if (!match.empty())
1618 {
1619 UnloadResource(Ogre::MaterialManager::getSingletonPtr(), match, groupName);
1620 break;
1621 }
1622 }
1623 }
1624 }
1625 }
1626 else return false;
1627 }
1628 catch (Ogre::Exception &e)
1629 {
1630 Ogre::StringStream msg;
1631 msg << "Exception: FILE: " << __FILE__ << " LINE: " << __LINE__ << " DESC: " << e.getFullDescription() << std::endl;
1632 Ogre::LogManager::getSingleton().logMessage(msg.str());
1633
1634 if (stream)
1635 stream->close();
1636 return false;
1637 }
1638
1639 if (stream)
1640 stream->close();
1641 return true;
1642}
1643
1644bool SScene::UnloadCompositors(const std::string& filename, const std::string& groupName)
1645{
1646 if (filename.empty())
1647 {
1648 Ogre::LogManager::getSingleton().logMessage("Filename is empty.");
1649 return false;
1650 }
1651
1652 Ogre::DataStreamPtr stream;
1653 try
1654 {
1655 stream = Ogre::ResourceGroupManager::getSingleton().openResource(filename, groupName);
1656 if (stream)
1657 {
1658 while (!stream->eof())
1659 {
1660 std::string line = stream->getLine();
1661 Ogre::StringUtil::trim(line);
1662
1666 if (Ogre::StringUtil::startsWith(line, "compositor"))
1667 {
1668 Ogre::StringVector vec = Ogre::StringUtil::split(line, " \t:");
1669 bool skipFirst = true;
1670 for (Ogre::StringVector::iterator it = vec.begin(); it < vec.end(); ++it)
1671 {
1672 if (skipFirst)
1673 {
1674 skipFirst = false;
1675 continue;
1676 }
1677 std::string match = (*it);
1678 Ogre::StringUtil::trim(match);
1679 if (match.front() == '"' && match.back() == '"')
1680 {
1681 match.erase(0, 1); // erase the first character
1682 match.erase(match.size() - 1); // erase the last character
1683 }
1684
1685 if (!match.empty())
1686 {
1687 UnloadResource(Ogre::CompositorManager::getSingletonPtr(), match, groupName);
1688 break;
1689 }
1690 }
1691 }
1692 }
1693 }
1694 else return false;
1695 }
1696 catch (Ogre::Exception &e)
1697 {
1698 Ogre::StringStream msg;
1699 msg << "Exception: FILE: " << __FILE__ << " LINE: " << __LINE__ << " DESC: " << e.getFullDescription() << std::endl;
1700 Ogre::LogManager::getSingleton().logMessage(msg.str());
1701
1702 if(stream)
1703 stream->close();
1704 return false;
1705 }
1706
1707 if (stream)
1708 stream->close();
1709 return true;
1710}
1711
1712bool SScene::UnloadParticles(const std::string& filename, const std::string& groupName)
1713{
1714 if (filename.empty())
1715 {
1716 Ogre::LogManager::getSingleton().logMessage("Filename is empty.");
1717 return false;
1718 }
1719
1720 Ogre::DataStreamPtr stream;
1721 try
1722 {
1723 stream = Ogre::ResourceGroupManager::getSingleton().openResource(filename, groupName);
1724 if (stream)
1725 {
1726 while (!stream->eof())
1727 {
1728 std::string line = stream->getLine();
1729 Ogre::StringUtil::trim(line);
1730
1734 if (Ogre::StringUtil::startsWith(line, "particle_system"))
1735 {
1736 Ogre::StringVector vec = Ogre::StringUtil::split(line, " \t:");
1737 bool skipFirst = true;
1738 for (Ogre::StringVector::iterator it = vec.begin(); it < vec.end(); ++it)
1739 {
1740 if (skipFirst)
1741 {
1742 skipFirst = false;
1743 continue;
1744 }
1745 std::string match = (*it);
1746 Ogre::StringUtil::trim(match);
1747 if (match.front() == '"' && match.back() == '"')
1748 {
1749 match.erase(0, 1); // erase the first character
1750 match.erase(match.size() - 1); // erase the last character
1751 }
1752
1753 if (!match.empty())
1754 {
1755 UnloadResource(Ogre::ParticleSystemManager::getSingletonPtr(), match);
1756 break;
1757 }
1758 }
1759 }
1760 }
1761 }
1762 else return false;
1763 }
1764 catch (Ogre::Exception &e)
1765 {
1766 Ogre::StringStream msg;
1767 msg << "Exception: FILE: " << __FILE__ << " LINE: " << __LINE__ << " DESC: " << e.getFullDescription() << std::endl;
1768 Ogre::LogManager::getSingleton().logMessage(msg.str());
1769
1770 if (stream)
1771 stream->close();
1772 return false;
1773 }
1774
1775 if (stream)
1776 stream->close();
1777 return true;
1778}
1779
1780bool SScene::UnloadVertexPrograms(const std::string& filename, const std::string& groupName)
1781{
1782 if (filename.empty())
1783 {
1784 Ogre::LogManager::getSingleton().logMessage("Filename is empty.");
1785 return false;
1786 }
1787
1788 Ogre::DataStreamPtr stream;
1789 try
1790 {
1791 stream = Ogre::ResourceGroupManager::getSingleton().openResource(filename, groupName);
1792 if (stream)
1793 {
1794 while (!stream->eof())
1795 {
1796 std::string line = stream->getLine();
1797 Ogre::StringUtil::trim(line);
1798
1802 if (Ogre::StringUtil::startsWith(line, "vertex_program") && !Ogre::StringUtil::startsWith(line, "vertex_program_ref"))
1803 {
1804 Ogre::StringVector vec = Ogre::StringUtil::split(line, " \t:");
1805 bool skipFirst = true;
1806 for (Ogre::StringVector::iterator it = vec.begin(); it < vec.end(); ++it)
1807 {
1808 if (skipFirst)
1809 {
1810 skipFirst = false;
1811 continue;
1812 }
1813 std::string match = (*it);
1814 Ogre::StringUtil::trim(match);
1815 if (match.front() == '"' && match.back() == '"')
1816 {
1817 match.erase(0, 1); // erase the first character
1818 match.erase(match.size() - 1); // erase the last character
1819 }
1820
1821 if (!match.empty())
1822 {
1823 UnloadResource(Ogre::GpuProgramManager::getSingletonPtr(), match, groupName);
1824 break;
1825 }
1826 }
1827 }
1828 }
1829 }
1830 else return false;
1831 }
1832 catch (Ogre::Exception &e)
1833 {
1834 Ogre::StringStream msg;
1835 msg << "Exception: FILE: " << __FILE__ << " LINE: " << __LINE__ << " DESC: " << e.getFullDescription() << std::endl;
1836 Ogre::LogManager::getSingleton().logMessage(msg.str());
1837
1838 if (stream)
1839 stream->close();
1840 return false;
1841 }
1842
1843 if (stream)
1844 stream->close();
1845 return true;
1846}
1847
1848bool SScene::UnloadFragmentPrograms(const std::string& filename, const std::string& groupName)
1849{
1850 if (filename.empty())
1851 {
1852 Ogre::LogManager::getSingleton().logMessage("Filename is empty.");
1853 return false;
1854 }
1855
1856 Ogre::DataStreamPtr stream;
1857 try
1858 {
1859 stream = Ogre::ResourceGroupManager::getSingleton().openResource(filename, groupName);
1860 if (stream)
1861 {
1862 while (!stream->eof())
1863 {
1864 std::string line = stream->getLine();
1865 Ogre::StringUtil::trim(line);
1866
1870 if (Ogre::StringUtil::startsWith(line, "fragment_program") && !Ogre::StringUtil::startsWith(line, "fragment_program_ref"))
1871 {
1872 Ogre::StringVector vec = Ogre::StringUtil::split(line, " \t:");
1873 bool skipFirst = true;
1874 for (Ogre::StringVector::iterator it = vec.begin(); it < vec.end(); ++it)
1875 {
1876 if (skipFirst)
1877 {
1878 skipFirst = false;
1879 continue;
1880 }
1881 std::string match = (*it);
1882 Ogre::StringUtil::trim(match);
1883 if (match.front() == '"' && match.back() == '"')
1884 {
1885 match.erase(0, 1); // erase the first character
1886 match.erase(match.size() - 1); // erase the last character
1887 }
1888
1889 if (!match.empty())
1890 {
1891 UnloadResource(Ogre::GpuProgramManager::getSingletonPtr(), match, groupName);
1892 break;
1893 }
1894 }
1895 }
1896 }
1897 }
1898 else return false;
1899 }
1900 catch (Ogre::Exception &e)
1901 {
1902 Ogre::StringStream msg;
1903 msg << "Exception: FILE: " << __FILE__ << " LINE: " << __LINE__ << " DESC: " << e.getFullDescription() << std::endl;
1904 Ogre::LogManager::getSingleton().logMessage(msg.str());
1905
1906 if (stream)
1907 stream->close();
1908 return false;
1909 }
1910
1911 if (stream)
1912 stream->close();
1913 return true;
1914}
1915
1916bool SScene::ParseResourceScript(const std::string& groupName, const std::string& scriptName, const SResource::ResourceType& scriptType)
1917{
1918 Ogre::DataStreamPtr ds;
1919 ds.reset();
1920
1921 try
1922 {
1923 // unload resource first
1924 switch(scriptType)
1925 {
1927 //UnloadResource(Ogre::MeshManager::getSingletonPtr(), scriptName, groupName);
1928 break;
1930 UnloadMaterials(scriptName, groupName);
1931 UnloadVertexPrograms(scriptName, groupName);
1932 UnloadFragmentPrograms(scriptName, groupName);
1933 break;
1935 UnloadCompositors(scriptName, groupName);
1936 break;
1938 UnloadParticles(scriptName, groupName);
1939 break;
1941 {
1942 Ogre::TexturePtr tex = Ogre::TextureManager::getSingletonPtr()->getByName(scriptName, groupName);
1943 if (tex && tex.use_count() == 0)
1944 UnloadResource(Ogre::TextureManager::getSingletonPtr(), scriptName, groupName);
1945 }
1946 break;
1948 {
1949 Ogre::SkeletonPtr skl = Ogre::SkeletonManager::getSingletonPtr()->getByName(scriptName, groupName);
1950 if (skl && skl.use_count() == 0)
1951 UnloadResource(Ogre::SkeletonManager::getSingletonPtr(), scriptName, groupName);
1952 }
1953 break;
1955 UnloadResource(Ogre::MaterialManager::getSingletonPtr(), scriptName, groupName);
1956 break;
1958 UnloadResource(Ogre::GpuProgramManager::getSingletonPtr(), scriptName, groupName);
1959 break;
1960 }
1961
1962 // Open data stream
1963 if ((scriptType != SResource::SO3_RESOURCE_TEXTURE) || (scriptType != SResource::SO3_RESOURCE_MESH))
1964 ds = Ogre::ResourceGroupManager::getSingleton().openResource(scriptName, groupName);
1965
1966 // Set current scene as target for the resource loader
1968
1969 // Parse content
1970 Ogre::ResourceGroupManager* ogreResourceGroupManager = Ogre::ResourceGroupManager::getSingletonPtr();
1971
1972 switch(scriptType)
1973 {
1975 O3MeshManager->load(scriptName, groupName);
1976 break;
1978 O3MaterialManager->parseScript(ds, groupName);
1980 break;
1982 Ogre::CompositorManager::getSingleton().parseScript(ds, groupName);
1983 break;
1985 Ogre::ScriptCompilerManager::getSingleton().parseScript(ds, groupName);
1986 break;
1988 // Declare resource only, no parsing.
1989 ogreResourceGroupManager->declareResource(scriptName, "Texture", groupName);
1990 break;
1992 O3SkeletonManager->createResource(scriptName, groupName);
1993 O3SkeletonManager->load(scriptName, groupName);
1994 //O3SkeletonManager->parseScript(ds, groupName);
1995 break;
1997 // *.program files are managed by material script
1998 O3MaterialManager->parseScript(ds, groupName);
1999 break;
2001 //Ogre::GpuProgramManager::getSingleton().parseScript(ds, groupName);
2002 break;
2003 }
2004
2005 // Reset the current scene in the resource loader
2007
2008 // Close data stream
2009 if (ds)
2010 {
2011 ds->close();
2012 ds.reset();
2013 }
2014 return true;
2015 }
2016 catch(const Ogre::Exception& e)
2017 {
2018 // Reset the current scene in the resource loader
2020
2021 // Cleaning opened data stream
2022 if(ds)
2023 {
2024 ds->close();
2025 ds.reset();
2026 }
2027
2028 MMechostr(MSKRUNTIME, "SO3 Error while parsing %s : %s\n", scriptName.c_str(), e.what());
2029 return true;
2030 }
2031}
2032
2034{
2035 // Delete all SNode and inherited objects. SBody, SAnimation, etc associated to any SNode are destroyed too.
2036 const SNodeMap nodeListCopy = nodeList;
2037 SNodeMap::const_iterator iNodeList = nodeListCopy.begin();
2038 while (iNodeList != nodeListCopy.end())
2039 {
2040 DeleteNode(iNodeList->second);
2041 iNodeList++;
2042 }
2043 nodeList.clear();
2044
2045 // Clean ogre just in case...
2046 O3SceneManager->destroyAllEntities();
2047 O3SceneManager->destroyAllLights();
2048 O3SceneManager->destroyAllParticleSystems();
2049 //O3SceneManager->destroyAllCameras();
2050}
2051
2053{
2054 const SAnimMap seqAnimCopy = animationList;
2055 SAnimMap::const_iterator iSeqAnim = seqAnimCopy.begin();
2056 while (iSeqAnim != seqAnimCopy.end())
2057 {
2058 try
2059 {
2060 DeleteAnimation(iSeqAnim->second);
2061 }
2062 catch(Ogre::Exception&)
2063 {
2064 //not found
2065 0;
2066 }
2067 iSeqAnim++;
2068 }
2069 animationList.clear();
2070
2071 // Clean ogre just in case...
2072 O3SceneManager->destroyAllAnimations();
2073 O3SceneManager->destroyAllAnimationStates();
2074}
2075
2077{
2078 const SGroupMaterialMap groupMaterialListCopy = listOfMaterial;
2079 SGroupMaterialMap::const_iterator iGroupMaterial = groupMaterialListCopy.begin();
2080 while (iGroupMaterial != groupMaterialListCopy.end())
2081 {
2082 const SMaterialMap materialListCopy = (*iGroupMaterial->second);
2083 SMaterialMap::const_iterator iMaterial = materialListCopy.begin();
2084 while(iMaterial != materialListCopy.end())
2085 {
2086 DeleteMaterial(iMaterial->second);
2087 iMaterial++;
2088 }
2089 iGroupMaterial++;
2090 }
2091 listOfMaterial.clear();
2092}
2093
2095{
2096 // First, delete all the scene textures
2097 const SGroupTextureMap groupTextureListCopy = listOfTexture;
2098 SGroupTextureMap::const_iterator iGroupTexture = groupTextureListCopy.begin();
2099 while (iGroupTexture != groupTextureListCopy.end())
2100 {
2101 const STextureMap textureListCopy = (*iGroupTexture->second);
2102 STextureMap::const_iterator iTexture = textureListCopy.begin();
2103 while(iTexture != textureListCopy.end())
2104 {
2105 DeleteTexture(iTexture->second);
2106 iTexture++;
2107 }
2108 iGroupTexture++;
2109 }
2110 listOfTexture.clear();
2111
2112 // Destroy all Textures not protected by /Core /BaseWhite /Stereo
2113 /*std::vector<Ogre::TexturePtr> listTextureToDelete;
2114 Ogre::ResourceManager::ResourceMapIterator itT = Ogre::TextureManager::getSingleton().getResourceIterator();
2115 while(itT.hasMoreElements())
2116 {
2117 Ogre::TexturePtr tex = static_cast<Ogre::TexturePtr>(itT.getNext());
2118 if((tex->getName() != "SO3DebugFontTexture")
2119 &&(tex->getName() != "BlueHighway-10Texture")
2120 &&(tex->getGroup() != "OgreInternal")
2121 &&(tex->getGroup().substr(0, std::string(SO3_INTERNAL_RESOURCE_GROUP).length()) != SO3_INTERNAL_RESOURCE_GROUP)
2122 &&(tex->getGroup() != SO3_INTERNAL_HYDRAX_RESOURCE_GROUP)
2123 &&(tex->getGroup() != SO3_INTERNAL_SKYX_RESOURCE_GROUP))
2124 {
2125 // ATTENTION: Store for further removal cause "O3TextureManager->remove" modify the iterator.
2126 listTextureToDelete.push_back(tex);
2127 }
2128 }
2129
2130 // Now that Ogre iterator is processed, remove the texture that we do not need anymore.
2131 std::vector<Ogre::TexturePtr>::iterator iListTextureToDelete = listTextureToDelete.begin();
2132 while(iListTextureToDelete != listTextureToDelete.end())
2133 {
2134 O3TextureManager->unload((*iListTextureToDelete)->getName());
2135 O3TextureManager->remove((*iListTextureToDelete)->getName());
2136 iListTextureToDelete++;
2137 }
2138 listTextureToDelete.clear();*/
2139}
2140
2141void SScene::SetDebugEnable(const bool& enable)
2142{
2143 if (SO3DebugOverlay)
2144 {
2145 if (enable)
2146 SO3DebugOverlay->show();
2147 else
2148 SO3DebugOverlay->hide();
2149 }
2150}
2151
2152
2153void SScene::SetDebugDisplay(const int& color, const int& posx, const int& posy, const int& width, const int& height, const int& charHeight)
2154{
2155 if (SO3DebugOverlay)
2156 {
2157 SO3DebugPanel->setMetricsMode(Ogre::GMM_PIXELS);
2158 SO3DebugPanel->setDimensions(Ogre::Real(width), Ogre::Real(height));
2159 SO3DebugPanel->setPosition(Ogre::Real(posx), Ogre::Real(posy));
2160
2161 SO3DebugTextArea->setMetricsMode(Ogre::GMM_PIXELS);
2162 SO3DebugTextArea->setPosition(0.0, 0.0);
2163 SO3DebugTextArea->setDimensions(Ogre::Real(width), Ogre::Real(height));
2164 SO3DebugTextArea->setCharHeight(Ogre::Real(charHeight));
2165 SO3DebugTextArea->setColour(ConversionTools::ScolToOgreColorRGBA(color));
2166 SO3DebugTextArea->setColourBottom(ConversionTools::ScolToOgreColorRGBA(color));
2167 SO3DebugTextArea->setColourTop(ConversionTools::ScolToOgreColorRGBA(color));
2168 SO3DebugOverlay->show();
2169 }
2170}
2171
2172void SScene::SetDebugText(const std::string& text)
2173{
2174 if (SO3DebugOverlay)
2175 {
2176 SO3DebugTextArea->setCaption(text);
2177 //SO3DebugTextArea->_update();
2178 //SO3DebugPanel->_update();
2179 }
2180}
2181
2182void SScene::GetSimpleRayCast(Ogre::Ray cameraRay, SEntity* selected, SRaycastResult &result)
2183{
2184 mRayQuery->setRay(cameraRay);
2185 mRayQuery->setSortByDistance(true, 20);
2186 mRayQuery->setQueryTypeMask(Ogre::SceneManager::ENTITY_TYPE_MASK);
2187 Ogre::RaySceneQueryResult& qresult = mRayQuery->execute();
2188 Ogre::RaySceneQueryResult::iterator itr = qresult.begin();
2189
2190 bool found = false;
2191 for (itr = qresult.begin(); itr != qresult.end() && !found; itr++)
2192 {
2193 /*
2194 if (itr->worldFragment)
2195 {
2196 Ogre::Real terrainHeight = itr->worldFragment->singleIntersection.y;
2197 continue;
2198 }
2199 else
2200 */
2201 if (itr->movable && itr->movable->getVisible())
2202 {
2203 if (itr->movable->getMovableType() != "Entity")
2204 continue;
2205
2206 Ogre::Entity* oentity = static_cast<Ogre::Entity*>(itr->movable);
2207 if (oentity->getNumSubEntities() == 0)
2208 continue;
2209
2210 Ogre::SubEntity* subent = oentity->getSubEntity(0);
2211 Ogre::Any bindedCustomEntity = subent->getUserObjectBindings().getUserAny("SEntity");
2212 if (!bindedCustomEntity.has_value())
2213 continue;
2214
2215 SEntity* entity = Ogre::any_cast<SEntity*> (bindedCustomEntity);
2216 if (entity == selected)
2217 {
2218 result.entity = entity;
2219 result.entityName = entity->GetName();
2220 result.scene = this;
2221 result.sceneName = GetName();
2222 result.closestDistance = itr->distance;
2223 result.point = cameraRay.getOrigin() + (cameraRay.getDirection() * itr->distance);
2224 found = true;
2225 }
2226 }
2227 }
2228
2229 mRayQuery->clearResults();
2230}
2231
2232void SScene::GetSimpleRayCast(Ogre::Ray cameraRay, SRaycastResult &result)
2233{
2234 mRayQuery->setRay(cameraRay);
2235 mRayQuery->setSortByDistance(true, 20);
2236 Ogre::RaySceneQueryResult& qresult = mRayQuery->execute();
2237 Ogre::RaySceneQueryResult::iterator itr = qresult.begin();
2238
2239 int lsize = 0;
2240
2241 //get number of enabled entities
2242 for (itr = qresult.begin(); itr != qresult.end(); itr++)
2243 {
2244 /*
2245 if (itr->worldFragment)
2246 {
2247 Ogre::Real terrainHeight = itr->worldFragment->singleIntersection.y;
2248 continue;
2249 }
2250 else */
2251 if (itr->movable && itr->movable->getVisible())
2252 {
2253 if (itr->movable->getMovableType() != "Entity")
2254 continue;
2255
2256 Ogre::Entity* oentity = static_cast<Ogre::Entity*>(itr->movable);
2257
2258 if (oentity->getNumSubEntities() == 0)
2259 continue;
2260
2261 Ogre::SubEntity* subent = oentity->getSubEntity(0);
2262 Ogre::Any bindedCustomEntity = subent->getUserObjectBindings().getUserAny("SEntity");
2263 if (!bindedCustomEntity.has_value())
2264 continue;
2265
2266 SEntity* entity = Ogre::any_cast<SEntity*> (bindedCustomEntity);
2267 if (entity && entity->GetSceneNodeIsMouseClick())
2268 lsize++;
2269 }
2270 }
2271
2272 bool firstFound = false;
2273 int i = 0;
2274 for (itr = qresult.begin(); itr != qresult.end(); itr++)
2275 {
2276 /*
2277 if (itr->worldFragment)
2278 {
2279 Ogre::Real terrainHeight = itr->worldFragment->singleIntersection.y;
2280 //TODO terrain
2281 }
2282 else */
2283 if (itr->movable && itr->movable->getVisible())
2284 {
2285 if (itr->movable->getMovableType() != "Entity")
2286 continue;
2287
2288 Ogre::Entity* oentity = static_cast<Ogre::Entity*>(itr->movable);
2289 if (oentity->getNumSubEntities() == 0)
2290 continue;
2291
2292 Ogre::SubEntity* subent = oentity->getSubEntity(0);
2293 Ogre::Any bindedCustomEntity = subent->getUserObjectBindings().getUserAny("SEntity");
2294 if (!bindedCustomEntity.has_value())
2295 continue;
2296
2297 SEntity* entity = Ogre::any_cast<SEntity*> (bindedCustomEntity);
2298 if (entity && entity->GetSceneNodeIsMouseClick() && (!firstFound || entity->GetSceneNodeIsMouseForeground()))
2299 {
2300 i++;
2301
2302 //if the camera is in the bounding box we ignore it
2303 if (oentity->getWorldBoundingBox().contains(cameraRay.getOrigin()) && (i < lsize))
2304 continue;
2305
2306 firstFound = true;
2307 result.entity = entity;
2308 result.entityName = entity->GetName();
2309 result.scene = this;
2310 result.sceneName = GetName();
2311 result.material = GetMaterial(entity->GetGroupName(), subent->getMaterial()->getName());
2312 result.indexSubEntity = 0;
2313 result.closestDistance = itr->distance;
2314 result.point = cameraRay.getOrigin() + (cameraRay.getDirection() * itr->distance);
2315
2316 if (entity->GetSceneNodeIsMouseForeground())
2317 break;
2318 }
2319 }
2320 }
2321
2322 mRayQuery->clearResults();
2323}
2324
2326{
2327 SGroupMaterialMap::const_iterator iGroupMaterial = listOfMaterial.begin();
2328 while (iGroupMaterial != listOfMaterial.end())
2329 {
2330 const SMaterialMap materialList = (*iGroupMaterial->second);
2331 SMaterialMap::const_iterator iMaterial = materialList.begin();
2332 while (iMaterial != materialList.end())
2333 {
2334 iMaterial->second->SetPointSize(size);
2335 iMaterial++;
2336 }
2337 iGroupMaterial++;
2338 }
2339}
2340
2341}
int getScenePostRenderEvent(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
int getScenePreRenderEvent2(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
int getScenePreRenderEvent(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
int getScenePreRenderPhysicEvent(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
long LONG
Definition SO3Android.h:59
MMechostr(MSKDEBUG, " > Start loading Plugin SO3Engine dll\n")
SCOL_EXPORT int cbmachine w
Definition SO3SCOL.cpp:5150
bool checkGroupExists(std::string group)
function to check if an Ogre resource group exists
Definition SO3SCOL.cpp:955
mmachine mm
Definition SO3SCOL.cpp:109
int getScenePreRenderEvent(struct Mmachine *, SCOL_PTR_TYPE, SCOL_PTR_TYPE)
int SCENE_POST_RENDER_EVENT
Definition SO3SCOL.cpp:191
int getScenePreRenderEvent2(struct Mmachine *, SCOL_PTR_TYPE, SCOL_PTR_TYPE)
SMaterialPair * getMaterialPairByWorld(SPhysicWorld *world, int ID1, int ID2)
function to check if a material ID exists
int SO3_BODY_LEAVE_WORLD_MSG
int SCENE_PRE_RENDER_EVENT2
Definition SO3SCOL.cpp:190
int SCENE_PRE_RENDER_PHYSIC_EVENT
Definition SO3SCOL.cpp:192
int SCENE_PRE_RENDER_EVENT
Scol CallBack declaration.
Definition SO3SCOL.cpp:189
int getScenePostRenderEvent(struct Mmachine *, SCOL_PTR_TYPE, SCOL_PTR_TYPE)
int ANIMATION_END_EVENT
main include
Definition SCOLAnim.cpp:51
int getScenePreRenderPhysicEvent(struct Mmachine *, SCOL_PTR_TYPE, SCOL_PTR_TYPE)
void clearRaycastsRecorded()
clears all raycasts, that are currently shown, should probably be done once per frame!
static Ogre::ColourValue ScolToOgreColorRGBA(const int &scolColor)
void Update(const Ogre::FrameEvent &evt)
Definition SO3Anim.cpp:367
AnimType GetType()
Definition SO3Anim.cpp:125
SNode * GetParentNode()
Definition SO3Anim.cpp:120
virtual bool GetEnable()
Definition SO3Anim.cpp:302
bool GetPaused()
Definition SO3Anim.cpp:362
@ SO3_SEQUENCE_ANIM
Definition SO3Anim.h:52
std::string GetName() const
std::string name
Definition SO3DataScol.h:44
virtual void SetCastShadows(const bool &castShadows)
virtual void SetRenderingDistance(const float &distance)
void SetVisibilityFlags(const Ogre::uint32 &flags)
std::string GetGroupName()
virtual bool GetCastShadows()
Ogre::uint32 GetVisibilityFlags()
Ogre::Entity * getOgreEntityPointer()
virtual float GetRenderingDistance()
void UnregisterViewport(SViewPort *targetViewport)
void UpdateCamera(SViewPort *viewport)
SException indicating that an attempt to create a new item with a given identifier fails cause anothe...
@ SO3_DIRECTIONAL_LIGHT
Definition SO3Light.h:49
void UpdateShadowFarDistance(const float &distance)
Definition SO3Light.cpp:201
LightType GetType()
Definition SO3Light.cpp:225
void UpdateShadowFarClipDistance(const float &distance)
Definition SO3Light.cpp:207
SShadowManager * GetShadowManager()
std::string GetGroupName()
void UpdateNodeBody(const bool &bScale)
void SetFlags(const int &flags)
bool GetSceneNodeIsMouseClick()
virtual Ogre::Vector3 GetPosition()
bool GetVisible()
virtual void SetScale(const Ogre::Vector3 &scale)
virtual Ogre::Vector3 GetScale()
void SetSceneNodeIsMouseForeground(const bool &mForeground)
NodeType GetNodeType()
int GetSceneNodeMouseFlags()
void SetSceneNodeIsMouseClick(const bool &mClickable)
virtual void SetOrientation(const Ogre::Quaternion &quat)
virtual void SetPosition(const Ogre::Vector3 &pos)
virtual Ogre::Quaternion GetOrientation()
void SetSceneNodeMouseFlags(const int &flags)
void SetVisible(const bool &visible, const bool &cascade=true)
SNode * GetParentSceneNode()
bool GetSceneNodeIsMouseForeground()
void AttachToParent(SNode *newParentNode)
void UpdatePhysic(const float &frameTime)
bool GetPhysicWorldEnable()
void SetPhysicWorldEnable(const bool &enable)
OgreNewt::Debugger * GetPhysicDebugger()
Ogre::Vector3 point
Definition SO3RayCast.h:50
std::string sceneName
Definition SO3RayCast.h:44
std::string entityName
Definition SO3RayCast.h:47
SMaterial * material
Definition SO3RayCast.h:48
@ SO3_RESOURCE_HIGHLEVELGPUPROGRAM
Definition SO3Resource.h:50
@ SO3_RESOURCE_PARTICLE_SYSTEM
Definition SO3Resource.h:52
static SResourceLoader & getSingleton()
void SetResourceScene(SScene *scene)
const SWindowMap & GetRenderWindowList() const
Definition SO3Root.cpp:821
const SSceneMap & GetSceneList() const
Definition SO3Root.cpp:560
static SRoot * getSingletonPtr()
Definition SO3Root.cpp:111
bool UnloadFragmentPrograms(const std::string &filename, const std::string &groupName)
void AddAnimation(SAnim *existingAnimation)
bool UnloadCompositors(const std::string &filename, const std::string &groupName)
void DestroyInternalRessources()
void DeleteDynamicReflectionMap(SDynamicReflectionMap *existingDynamicReflectionMap)
SDynamicReflectionMap * CreateDynamicReflectionMap(SViewPort *viewport, const std::string &newDynamicReflectionMapName)
void DeleteAnimation(SAnim *existingAnimation)
SVirtualPointer * CreateVirtualPointer(const std::string &basename)
Definition SO3Scene.cpp:639
void DeleteAllAnimations()
void DeleteAllTerrains()
Definition SO3Scene.cpp:876
bool hasSkyPlane
Definition SO3Scene.h:136
Ogre::MaterialPtr materialReceiver
Definition SO3Scene.h:142
SNode * CreateNodeWithUniqueName(const std::string &basename)
Definition SO3Scene.cpp:611
SShadowManager::ShadowQuality GetShadowQuality()
void ReloadEntities()
Definition SO3Scene.cpp:796
Ogre::SceneManager * O3SceneManager
Definition SO3Scene.h:127
SAnimMap GetAnimations() const
void UpdateAllTerrains()
Definition SO3Scene.cpp:844
bool ParseResourceScript(const std::string &groupName, const std::string &scriptName, const SResource::ResourceType &scriptType)
void DeleteAllNodes()
SShadowManager * GetShadowManager()
void SetDebugDisplay(const int &color, const int &posx, const int &posy, const int &width, const int &height, const int &charHeight)
SAnim * GetAnimation(const std::string &animationName)
void UnregisterViewport(SViewPort *viewport)
Ogre::MaterialPtr skyPlaneMat
Definition SO3Scene.h:140
bool skyPlaneDrawFirst
Definition SO3Scene.h:137
void DeleteBone(SBone *existingBone)
Definition SO3Scene.cpp:958
STexture * CreateTexture(const std::string &groupname, const std::string &texname, const std::string &path, const int &w=0, const int &h=0)
SNode * CreateNode(const std::string &newNodeName)
Definition SO3Scene.cpp:599
void UpdateLightsShadowParameters()
Definition SO3Scene.cpp:889
Ogre::SkeletonManager * O3SkeletonManager
Definition SO3Scene.h:130
void RegisterViewport(SViewPort *viewport)
SEntity * CreateOctahedron(const std::string &groupName, const std::string &newEntityName, const float &base, const float &bottom, const float &dist)
Definition SO3Scene.cpp:775
SMaterial * GetMaterial(const std::string &groupName, const std::string &materialName, bool searchOtherGroups=true)
void DeleteTerrain(STerrain *terrain)
Definition SO3Scene.cpp:834
SLight * CreateLight(const std::string &newLightName)
Definition SO3Scene.cpp:980
void SetMaterialsPointSize(Ogre::Real size)
void SetDebugText(const std::string &text)
void SetShadowType(const SShadowManager::ShadowType &shadowType)
const SNodeMap & GetNodeList() const
Definition SO3Scene.cpp:588
bool UnloadResource(Ogre::ResourceManager *resMgr, const std::string &resName, const std::string &groupName)
Ogre::MaterialPtr skyBoxMat
Definition SO3Scene.h:138
bool UnloadParticles(const std::string &filename, const std::string &groupName)
void SetShadowQuality(const SShadowManager::ShadowQuality &quality)
void PostUpdate()
Definition SO3Scene.cpp:564
const SGroupMaterialMap * GetMaterials()
Ogre::MaterialPtr materialCaster
Definition SO3Scene.h:141
SEnvironment * GetEnvironment() const
Ogre::TextureManager * O3TextureManager
Definition SO3Scene.h:131
SDynamicCubeMap * CreateDynamicCubeMap(const std::string &newDynamicCubeMapName)
Definition SO3Scene.cpp:997
Ogre::MaterialPtr skyDomeMat
Definition SO3Scene.h:139
SEnvironment * environment
Definition SO3Scene.h:145
SRenderToTexture * CreateRenderToTexture(const std::string &newRttName, SCamera *povCamera)
SEntity * CreateCone(const std::string &groupName, const std::string &newEntityName, const float &radius, const float &height, const int &segments)
Definition SO3Scene.cpp:759
bool AddNode(SNode *existingNode)
Definition SO3Scene.cpp:415
void PreUpdate()
Definition SO3Scene.cpp:468
Ogre::MaterialManager * O3MaterialManager
Definition SO3Scene.h:129
SEntity * CreatePlane(const std::string &groupName, const std::string &newEntityName, const SPointFloat &sizev, const SPointInt &seg, const SPointFloat &uv)
Definition SO3Scene.cpp:727
void SetDebugEnable(const bool &enable)
void UpdateCamera(SViewPort *viewport)
bool UnloadMaterials(const std::string &filename, const std::string &groupName)
unsigned short GetNumAnimations()
SParticleSystem * CreateParticleSystem(const std::string &newParticleSystemName, const std::string &particleSystemTemplate)
Definition SO3Scene.cpp:963
SCamera * CreateCamera(const std::string &newCameraName)
Definition SO3Scene.cpp:653
void CleanGroupTextures(const std::string &groupName)
void DeleteDynamicCubeMap(SDynamicCubeMap *existingDynamicCubeMap)
SBone * CreateBone(const std::string &newBoneName, SSkeleton *skeleton, const unsigned short &id)
Definition SO3Scene.cpp:946
SRoot * GetParent()
SEntity * CreateSphere(const std::string &groupName, const std::string &newEntityName, const float &radius, const int &rings, const int &segments)
Definition SO3Scene.cpp:743
void RemoveNode(SNode *existingNode)
Definition SO3Scene.cpp:430
const SGroupTextureMap * GetTextures()
void DeleteAllTextures()
const STerrainMap & GetTerrainList() const
Definition SO3Scene.cpp:594
SShadowManager::ShadowType GetShadowType()
SNode * GetNode(const std::string &nodeName) const
Definition SO3Scene.cpp:459
STexture * GetTexture(const std::string &groupName, const std::string &texName)
void DeleteLight(SLight *existingLight)
Definition SO3Scene.cpp:992
bool skyDomeDrawFirst
Definition SO3Scene.h:135
void DeleteTexture(STexture *texture)
SMaterial * CreateMaterial(const std::string &groupname, const std::string &matname, const bool &loadedFromScript=false)
bool hasSkyDome
Definition SO3Scene.h:134
SPhysicWorld * GetPhysicsWorld()
bool UnloadVertexPrograms(const std::string &filename, const std::string &groupName)
SEntity * CloneEntity(const std::string &newEntityName, SEntity *entity)
Definition SO3Scene.cpp:701
void clearOgreScene()
Definition SO3Scene.cpp:185
SSkeleton * CreateSkeleton(const std::string &newSkeletonName, SEntity *entity)
Definition SO3Scene.cpp:927
void ReloadInternalRessources()
bool NodeExist(const std::string &name)
Definition SO3Scene.cpp:406
SEntity * CreateEntity(const std::string &groupName, const std::string &newEntityName, const std::string &meshName, bool loadInBackground=false)
Definition SO3Scene.cpp:665
Ogre::SceneManager * GetOgreScenePointer()
Definition SO3Scene.cpp:449
void DeleteRenderToTexture(SRenderToTexture *existingRenderToTexture)
SNode * GetRootNode()
Definition SO3Scene.cpp:454
void RemoveAnimation(SAnim *existingAnimation)
void DeleteNode(SNode *existingNode)
Definition SO3Scene.cpp:630
void DeleteLineEntity(SLineEntity *existingLineEntity)
Definition SO3Scene.cpp:821
SSequenceAnimation * CreateAnimationSequence(const std::string &animationName)
SLineEntity * CreateLineEntity(const std::string &newLineEntityName, bool dashed=false, bool disableDepth=false)
Definition SO3Scene.cpp:809
void DeleteMaterial(SMaterial *material)
void DeleteSkeleton(SSkeleton *existingSkeleton)
Definition SO3Scene.cpp:941
void GetSimpleRayCast(Ogre::Ray cameraRay, SRaycastResult &result)
STerrain * CreateTerrain(const std::string &name)
Definition SO3Scene.cpp:826
void DeleteParticleSystem(SParticleSystem *existingParticleSystem)
Definition SO3Scene.cpp:975
Ogre::MeshManager * O3MeshManager
Definition SO3Scene.h:128
void DeleteEntity(SEntity *existingEntity)
Definition SO3Scene.cpp:791
Ogre::Plane skyPlane
Definition SO3Scene.h:143
Ogre::ColourValue GetAmbientLight()
bool skyBoxDrawFirst
Definition SO3Scene.h:133
bool hasSkyBox
Definition SO3Scene.h:132
SLightingManager * GetLightingManager()
void SetAmbientLight(const Ogre::ColourValue &color)
void DeleteAllMaterials()
void CleanGroupMaterials(const std::string &groupName)
void SetShadowType(const ShadowType &type)
void SetShadowQuality(ShadowQuality quality)
ShadowQuality GetShadowQuality()
void UpdateShadowFarDistance(const float &distance)
void UpdateShadowFarClipDistance(const float &distance)
Ogre::Light * GetOgreLight()
void UpdateLight(Ogre::ColourValue ambColor, Ogre::ColourValue sunColor, Ogre::Vector3 sunDir)
std::string GetGroupName()
Ogre::TexturePtr getOgreTexturePointer()
std::unordered_map< std::string, STexture * > STextureMap
std::unordered_map< std::string, SMaterial * > SMaterialMap
std::unordered_map< std::string, STextureMap * > SGroupTextureMap
std::unordered_map< std::string, STerrain * > STerrainMap
std::unordered_map< std::string, SNode * > SNodeMap
std::unordered_map< std::string, SWindow * > SWindowMap
std::unordered_map< std::string, SAnim * > SAnimMap
std::unordered_map< std::string, SMaterialMap * > SGroupMaterialMap