40#include "OgreFontManager.h"
42#include <OgreOctreePlugin.h>
44#include <boost/numeric/conversion/cast.hpp>
63SScene::SScene(
SRoot* parent,
const std::string& sceneName) :
SData(sceneName)
66 O3SceneManager = Ogre::Root::getSingleton().createSceneManager(
"OctreeSceneManager", sceneName);
113 mRayQuery =
O3SceneManager->createRayQuery(Ogre::Ray(), Ogre::SceneManager::ENTITY_TYPE_MASK);
114 mRayQuery->setSortByDistance(
true);
118 SO3DebugTextArea = 0;
121 std::string groupResource =
name + Ogre::RGN_DEFAULT;
124 Ogre::ResourceGroupManager::getSingleton().createResourceGroup(groupResource,
false);
126 catch (Ogre::Exception &e)
128 MMechostr(MSKDEBUG,
"SScene: An exception has occurred: %s\n", e.what());
132#if !defined(ANDROID) && !defined(RPI) && !defined(__APPLE__)
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");
145 SO3DebugFont->load();
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);
155 catch (Ogre::Exception &e)
157 MMechostr(MSKDEBUG,
"CreateScene Error : %s\n", e.getDescription().c_str());
177 Ogre::RTShader::ShaderGenerator::getSingletonPtr()->addSceneManager(
O3SceneManager);
180SScene::SScene() :
SData(
"")
187 if (lightingManager != 0)
188 lightingManager->
Reset();
194 SWindowMap::const_iterator iWindowList = windowListCopy.begin();
195 while (iWindowList != windowListCopy.end())
197 iWindowList->second->InvalidateRayCast();
254 Ogre::SceneManager::MovableObjectMap movableList =
O3SceneManager->getMovableObjects(
"ManualObject");
255 for (Ogre::SceneManager::MovableObjectMap::iterator itMO = movableList.begin(); itMO != movableList.end(); itMO++)
257 Ogre::ManualObject* curObj =
static_cast<Ogre::ManualObject *
>(itMO->second);
258 if(strcmp(curObj->getName().c_str(),
"SkyBox"))
294 Ogre::RTShader::ShaderGenerator::getSingletonPtr()->removeAllShaderBasedTechniques();
297 O3SceneManager->setFog(Ogre::FOG_NONE, Ogre::ColourValue::White, 0, 0, 0);
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);
311 SO3DebugTextArea = 0;
324 Ogre::FontManager::getSingleton().remove(SO3DebugFont);
325 SO3DebugFont.reset();
328 if (lightingManager != 0)
329 lightingManager->
Reset();
333 SWindowMap::const_iterator iWindowList = windowListCopy.begin();
334 while (iWindowList != windowListCopy.end())
336 iWindowList->second->InvalidateRayCast();
371 Ogre::SceneManager::MovableObjectMap movableList =
O3SceneManager->getMovableObjects(
"ManualObject");
372 for (Ogre::SceneManager::MovableObjectMap::iterator itMO = movableList.begin(); itMO != movableList.end(); itMO++)
374 Ogre::ManualObject* curObj =
static_cast<Ogre::ManualObject *
>(itMO->second);
375 if (strcmp(curObj->getName().c_str(),
"SkyBox"))
387 SO3_SAFE_DELETE(lightingManager);
388 SO3_SAFE_DELETE(rootNode);
391 listOfMaterial.clear();
392 listOfTexture.clear();
397 Ogre::RTShader::ShaderGenerator::getSingletonPtr()->removeSceneManager(
O3SceneManager);
400 SAFE_DELETE(physicWorld);
402 std::string groupResource(
GetName() + Ogre::RGN_DEFAULT);
403 Ogre::ResourceGroupManager::getSingleton().destroyResourceGroup(groupResource);
408 SNodeMap::iterator iNodeSearched = nodeList.find(
name);
409 if (iNodeSearched == nodeList.end())
417 string nodeName = existingNode->
GetName();
418 SNodeMap::iterator iNodeSearched = nodeList.find(nodeName);
419 if (iNodeSearched == nodeList.end())
421 nodeList.insert(SNodeMap::value_type(nodeName, existingNode));
437 SNodeMap::iterator iNodeSearched = nodeList.find(nodeName);
438 if (iNodeSearched != nodeList.end())
440 nodeList.erase(iNodeSearched);
445 OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND,
"Can not remove Node named \""+ nodeName +
"\", element not found!",
"SScene::RemoveNode");
461 SNodeMap::const_iterator iNodeSearched = nodeList.find(nodeName);
462 if (iNodeSearched != nodeList.end())
463 return iNodeSearched->second;
473 unsigned long frameTime = mPreTimer.getMicroseconds();
476 float timef = (float)frameTime * 0.000001;
483 mframetime = boost::numeric_cast<int>(frameTime);
485 catch (std::exception&)
493 Ogre::FrameEvent evt;
494 evt.timeSinceLastFrame = timef;
495 evt.timeSinceLastEvent = timef;
500 SAnimMap seqAnimList = animationList;
501 SAnimMap::const_iterator iSeqAnimList = seqAnimList.begin();
504 while(iSeqAnimList != seqAnimList.end())
506 SAnim* curAnim = iSeqAnimList->second;
513 iSeqAnimList = seqAnimList.begin();
514 while(iSeqAnimList != seqAnimList.end())
516 SAnim* curAnim = iSeqAnimList->second;
572 mframetime = boost::numeric_cast<int>(mPostTimer.getMicroseconds());
574 catch (std::exception&)
603 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + newNodeName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
605 SNode* newNode =
new SNode(
this, newNodeName);
613 size_t ID = nodeList.size();
615 std::stringstream ss;
618 string name = ss.str();
622 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" +
name +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
632 if (existingNode != rootNode)
635 SO3_SAFE_DELETE(existingNode);
643 if (!
AddNode(newVirtualPointer))
645 SAFE_DELETE(newVirtualPointer);
647 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + basename +
"\", an element with the same name already exist!",
"SScene::CreateVirtualPointer",
true);
650 return newVirtualPointer;
657 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + newCameraName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
669 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + newEntityName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
671 SEntity* newEntity =
new SEntity(
this, groupName, newEntityName, meshName, loadInBackground);
681 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + newEntityName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
683 SEntity* newEntity =
new SEntity(
this, newEntityName, prefabType);
693 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + entityName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
695 SEntity* newEntity =
new SEntity(
this, entityName, ressourceGroup, meshPointer);
705 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + newEntityName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
731 SO3_EXCEPT(
SExceptionItemIdentity,
"No ressource group named \""+ groupName +
"\" found, plane creation aborted!",
"SScene::CreatePlane",
true);
735 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + newEntityName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
737 SEntity* newEntity =
new SEntity(
this, groupName, newEntityName, sizev, seg, uv);
743SEntity*
SScene::CreateSphere(
const std::string& groupName,
const std::string& newEntityName,
const float& radius,
const int& rings,
const int& segments)
747 SO3_EXCEPT(
SExceptionItemIdentity,
"No ressource group named \"" + groupName +
"\" found, sphere creation aborted!",
"SScene::CreateSphere",
true);
751 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + newEntityName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
753 SEntity* newEntity =
new SEntity(
this, groupName, newEntityName, radius, rings, segments);
759SEntity*
SScene::CreateCone(
const std::string& groupName,
const std::string& newEntityName,
const float& radius,
const float& height,
const int& segments)
763 SO3_EXCEPT(
SExceptionItemIdentity,
"No ressource group named \"" + groupName +
"\" found, cone creation aborted!",
"SScene::CreateCone",
true);
767 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + newEntityName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
769 SEntity* newEntity =
new SEntity(
this, groupName, newEntityName, radius, height, segments);
779 SO3_EXCEPT(
SExceptionItemIdentity,
"No ressource group named \"" + groupName +
"\" found, cone creation aborted!",
"SScene::CreateOctahedron",
true);
783 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + newEntityName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
785 SEntity* newEntity =
new SEntity(
this, groupName, newEntityName, base, bottom, dist);
798 SNodeMap::iterator iNodeit = nodeList.begin();
799 while (iNodeit != nodeList.end())
801 SNode* tnode = iNodeit->second;
803 static_cast<SEntity*
> (tnode)->Reload();
813 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + newLineEntityName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
818 return newLineEntity;
829 terrainList.insert(STerrainMap::value_type(
name, terrain));
836 STerrainMap::iterator iTerrainSearched = terrainList.find(terrain->
GetName());
837 if (iTerrainSearched != terrainList.end())
839 terrainList.erase(iTerrainSearched);
841 SAFE_DELETE(terrain);
846 Ogre::Vector3 sunDir(0.5f, 0.5f, 1.0f);
847 Ogre::ColourValue sunColor;
867 STerrainMap::iterator iTerrainit = terrainList.begin();
868 while (iTerrainit != terrainList.end())
870 STerrain* terrain = iTerrainit->second;
880 STerrainMap::const_iterator iTerrainList = terrainListCopy.begin();
881 while (iTerrainList != terrainListCopy.end())
891 SNodeMap::iterator iNodeit = nodeList.begin();
892 while (iNodeit != nodeList.end())
894 SNode* tnode = iNodeit->second;
931 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + newSkeletonName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
950 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + newBoneName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
952 SBone* newBone =
new SBone(
this, newBoneName, skeleton,
id);
967 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + newParticleSystemName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
972 return newParticleSystem;
984 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + newLightName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
1001 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + newDynamicCubeMapName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
1006 return newDynamicCubeMap;
1018 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add node named \"" + newRttName +
"\", an element with the same name already exist!",
"SScene::CreateNode",
true);
1023 return newRenderToTexture;
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);
1038 AddNode(newDynamicReflectionMap);
1040 return newDynamicReflectionMap;
1052 SO3_EXCEPT(
SExceptionItemIdentity,
"No ressource group named \"" + groupname +
"\" found, material creation aborted!",
"SScene::CreateMaterial",
true);
1056 SO3_EXCEPT(
SExceptionItemIdentity,
"A material named \""+ matname +
"\" already exist in resource group \""+ groupname +
"\", material creation aborted!",
"SScene::CreateMaterial",
true);
1059 SGroupMaterialMap::iterator iGroupSearched = listOfMaterial.find(groupname);
1060 if(iGroupSearched != listOfMaterial.end())
1062 materialMap = iGroupSearched->second;
1067 listOfMaterial.insert(SGroupMaterialMap::value_type(groupname, materialMap));
1071 materialMap->insert(SMaterialMap::value_type(matname, material));
1078 SGroupMaterialMap::const_iterator iGroupSearched = listOfMaterial.find(material->
GetGroupName());
1079 if(iGroupSearched != listOfMaterial.end())
1083 SMaterialMap::const_iterator iMaterialSearched = materialMap->find(material->
GetName());
1084 if(iMaterialSearched != materialMap->end())
1085 materialMap->erase(iMaterialSearched);
1088 if(materialMap->empty())
1090 listOfMaterial.erase(iGroupSearched);
1091 delete (materialMap);
1101 SGroupMaterialMap::const_iterator iGroupSearched = listOfMaterial.find(groupName);
1102 if(iGroupSearched != listOfMaterial.end())
1105 SMaterialMap::iterator iMaterialSearched = materialMap->find(materialName);
1106 if(iMaterialSearched != materialMap->end())
1108 return iMaterialSearched->second;
1110 else if (searchOtherGroups)
1113 iGroupSearched = listOfMaterial.begin();
1114 while (iGroupSearched != listOfMaterial.end())
1116 materialMap = iGroupSearched->second;
1117 iMaterialSearched = materialMap->find(materialName);
1118 if (iMaterialSearched != materialMap->end())
1120 return iMaterialSearched->second;
1128 else if (searchOtherGroups)
1131 iGroupSearched = listOfMaterial.begin();
1132 while (iGroupSearched != listOfMaterial.end())
1135 SMaterialMap::iterator iMaterialSearched = materialMap->find(materialName);
1136 if (iMaterialSearched != materialMap->end())
1138 return iMaterialSearched->second;
1149 SGroupMaterialMap::const_iterator iGroupSearched = listOfMaterial.find(groupName);
1150 if(iGroupSearched != listOfMaterial.end())
1151 return iGroupSearched->second;
1158 return &listOfMaterial;
1165 SWindowMap::const_iterator iWindowList = windowListCopy.begin();
1166 while (iWindowList != windowListCopy.end())
1168 iWindowList->second->InvalidateRayCast();
1173 SGroupMaterialMap::const_iterator iGroupMaterial = groupMaterialListCopy.find(groupName);
1174 if (iGroupMaterial != groupMaterialListCopy.end())
1176 const SMaterialMap materialListCopy = (*iGroupMaterial->second);
1177 SMaterialMap::const_iterator iMaterial = materialListCopy.begin();
1178 while(iMaterial != materialListCopy.end())
1194 SO3_EXCEPT(
SExceptionItemIdentity,
"No ressource group named \""+ groupname +
"\" found, texture creation aborted!",
"SScene::CreateTexture",
true);
1198 SGroupTextureMap::iterator iGroupSearched = listOfTexture.find(groupname);
1199 if(iGroupSearched != listOfTexture.end())
1201 textureMap = iGroupSearched->second;
1206 listOfTexture.insert(SGroupTextureMap::value_type(groupname, textureMap));
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);
1215 textureMap->insert(STextureMap::value_type(texname, texture));
1227 SO3_EXCEPT(
SExceptionItemIdentity,
"No ressource group named \"" + groupname +
"\" found, texture creation aborted!",
"SScene::CreateTexture",
true);
1231 SGroupTextureMap::iterator iGroupSearched = listOfTexture.find(groupname);
1232 if (iGroupSearched != listOfTexture.end())
1234 textureMap = iGroupSearched->second;
1239 listOfTexture.insert(SGroupTextureMap::value_type(groupname, textureMap));
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);
1248 textureMap->insert(STextureMap::value_type(texname, texture));
1256 SGroupTextureMap::iterator iGroupSearched = listOfTexture.find(texture->
GetGroupName());
1257 if(iGroupSearched != listOfTexture.end())
1260 STextureMap::iterator iTextureSearched = textureMap->find(texture->
GetName());
1261 if(iTextureSearched != textureMap->end())
1262 textureMap->erase(iTextureSearched);
1264 if(textureMap->empty())
1266 listOfTexture.erase(iGroupSearched);
1267 delete (textureMap);
1282 SGroupTextureMap::iterator iGroupSearched = listOfTexture.find(groupName);
1283 if(iGroupSearched != listOfTexture.end())
1286 STextureMap::iterator iTextureSearched = textureMap->find(texName);
1287 if(iTextureSearched != textureMap->end())
1289 return iTextureSearched->second;
1298 SGroupTextureMap::iterator iGroupSearched = listOfTexture.find(groupName);
1299 if(iGroupSearched != listOfTexture.end())
1300 return iGroupSearched->second;
1307 return &listOfTexture;
1314 SGroupTextureMap::const_iterator iGroupTexture = groupTextureListCopy.find(groupName);
1315 if (iGroupTexture != groupTextureListCopy.end())
1317 const STextureMap textureListCopy = (*iGroupTexture->second);
1318 STextureMap::const_iterator iTexture = textureListCopy.begin();
1319 while(iTexture != textureListCopy.end())
1347 assert(existingAnimation != 0);
1349 OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
"Cannot destroy an animation that is not handled by this scene",
"SScene::DeleteAnimation");
1352 SO3_SAFE_DELETE(existingAnimation);
1357 return animationList.size();
1362 SAnimMap::iterator iAnimationSearched = animationList.find(animationName);
1363 if (iAnimationSearched != animationList.end())
1364 return iAnimationSearched->second;
1371 return animationList;
1376 string animationName = existingAnimation->
GetName();
1380 SAnimMap::iterator iAnimationSearched = animationList.find(animationName);
1381 if (iAnimationSearched == animationList.end())
1383 animationList.insert(SAnimMap::value_type(animationName, existingAnimation));
1388 SO3_EXCEPT(
SExceptionItemIdentity,
"Can not add animation named \""+ animationName +
"\", an element with the same name already exist!",
"SScene::AddAnimation",
true);
1402 SAnimMap::iterator iAnimationSearched = animationList.find(animationName);
1403 if (iAnimationSearched != animationList.end())
1405 SAnim* findedAnimation = iAnimationSearched->second;
1406 animationList.erase(iAnimationSearched);
1411 OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND,
"Can not remove Animation named \""+ animationName +
"\", element not found!",
"SScene::RemoveAnimation");
1422 return lightingManager;
1427 if (lightingManager != 0)
1435 mLastShadowType = shadowType;
1436 if (lightingManager == 0)
1444 if (lightingManager != 0)
1452 if (lightingManager == 0)
1460 if (lightingManager)
1480 return cAmbientLight;
1485 cAmbientLight = color;
1513 Ogre::ResourcePtr rPtr = resMgr->getResourceByName(resName, groupName);
1521 if (rPtr->isLoaded())
1532 resMgr->remove(resName);
1533 rPtr = resMgr->getResourceByName(resName, groupName);
1545 if (resMgr->resourceExists(resName))
1565 resMgr->removeTemplate(resName,
true);
1567 catch (Ogre::Exception &)
1578 if (filename.empty())
1580 Ogre::LogManager::getSingleton().logMessage(
"Filename is empty.");
1584 Ogre::DataStreamPtr stream;
1587 stream = Ogre::ResourceGroupManager::getSingleton().openResource(filename, groupName);
1590 while (!stream->eof())
1592 std::string line = stream->getLine();
1593 Ogre::StringUtil::trim(line);
1598 if (Ogre::StringUtil::startsWith(line,
"material"))
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)
1609 std::string match = (*it);
1610 Ogre::StringUtil::trim(match);
1611 if (match.front() ==
'"' && match.back() ==
'"')
1614 match.erase(match.size() - 1);
1619 UnloadResource(Ogre::MaterialManager::getSingletonPtr(), match, groupName);
1628 catch (Ogre::Exception &e)
1630 Ogre::StringStream msg;
1631 msg <<
"Exception: FILE: " << __FILE__ <<
" LINE: " << __LINE__ <<
" DESC: " << e.getFullDescription() << std::endl;
1632 Ogre::LogManager::getSingleton().logMessage(msg.str());
1646 if (filename.empty())
1648 Ogre::LogManager::getSingleton().logMessage(
"Filename is empty.");
1652 Ogre::DataStreamPtr stream;
1655 stream = Ogre::ResourceGroupManager::getSingleton().openResource(filename, groupName);
1658 while (!stream->eof())
1660 std::string line = stream->getLine();
1661 Ogre::StringUtil::trim(line);
1666 if (Ogre::StringUtil::startsWith(line,
"compositor"))
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)
1677 std::string match = (*it);
1678 Ogre::StringUtil::trim(match);
1679 if (match.front() ==
'"' && match.back() ==
'"')
1682 match.erase(match.size() - 1);
1687 UnloadResource(Ogre::CompositorManager::getSingletonPtr(), match, groupName);
1696 catch (Ogre::Exception &e)
1698 Ogre::StringStream msg;
1699 msg <<
"Exception: FILE: " << __FILE__ <<
" LINE: " << __LINE__ <<
" DESC: " << e.getFullDescription() << std::endl;
1700 Ogre::LogManager::getSingleton().logMessage(msg.str());
1714 if (filename.empty())
1716 Ogre::LogManager::getSingleton().logMessage(
"Filename is empty.");
1720 Ogre::DataStreamPtr stream;
1723 stream = Ogre::ResourceGroupManager::getSingleton().openResource(filename, groupName);
1726 while (!stream->eof())
1728 std::string line = stream->getLine();
1729 Ogre::StringUtil::trim(line);
1734 if (Ogre::StringUtil::startsWith(line,
"particle_system"))
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)
1745 std::string match = (*it);
1746 Ogre::StringUtil::trim(match);
1747 if (match.front() ==
'"' && match.back() ==
'"')
1750 match.erase(match.size() - 1);
1755 UnloadResource(Ogre::ParticleSystemManager::getSingletonPtr(), match);
1764 catch (Ogre::Exception &e)
1766 Ogre::StringStream msg;
1767 msg <<
"Exception: FILE: " << __FILE__ <<
" LINE: " << __LINE__ <<
" DESC: " << e.getFullDescription() << std::endl;
1768 Ogre::LogManager::getSingleton().logMessage(msg.str());
1782 if (filename.empty())
1784 Ogre::LogManager::getSingleton().logMessage(
"Filename is empty.");
1788 Ogre::DataStreamPtr stream;
1791 stream = Ogre::ResourceGroupManager::getSingleton().openResource(filename, groupName);
1794 while (!stream->eof())
1796 std::string line = stream->getLine();
1797 Ogre::StringUtil::trim(line);
1802 if (Ogre::StringUtil::startsWith(line,
"vertex_program") && !Ogre::StringUtil::startsWith(line,
"vertex_program_ref"))
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)
1813 std::string match = (*it);
1814 Ogre::StringUtil::trim(match);
1815 if (match.front() ==
'"' && match.back() ==
'"')
1818 match.erase(match.size() - 1);
1823 UnloadResource(Ogre::GpuProgramManager::getSingletonPtr(), match, groupName);
1832 catch (Ogre::Exception &e)
1834 Ogre::StringStream msg;
1835 msg <<
"Exception: FILE: " << __FILE__ <<
" LINE: " << __LINE__ <<
" DESC: " << e.getFullDescription() << std::endl;
1836 Ogre::LogManager::getSingleton().logMessage(msg.str());
1850 if (filename.empty())
1852 Ogre::LogManager::getSingleton().logMessage(
"Filename is empty.");
1856 Ogre::DataStreamPtr stream;
1859 stream = Ogre::ResourceGroupManager::getSingleton().openResource(filename, groupName);
1862 while (!stream->eof())
1864 std::string line = stream->getLine();
1865 Ogre::StringUtil::trim(line);
1870 if (Ogre::StringUtil::startsWith(line,
"fragment_program") && !Ogre::StringUtil::startsWith(line,
"fragment_program_ref"))
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)
1881 std::string match = (*it);
1882 Ogre::StringUtil::trim(match);
1883 if (match.front() ==
'"' && match.back() ==
'"')
1886 match.erase(match.size() - 1);
1891 UnloadResource(Ogre::GpuProgramManager::getSingletonPtr(), match, groupName);
1900 catch (Ogre::Exception &e)
1902 Ogre::StringStream msg;
1903 msg <<
"Exception: FILE: " << __FILE__ <<
" LINE: " << __LINE__ <<
" DESC: " << e.getFullDescription() << std::endl;
1904 Ogre::LogManager::getSingleton().logMessage(msg.str());
1918 Ogre::DataStreamPtr ds;
1942 Ogre::TexturePtr tex = Ogre::TextureManager::getSingletonPtr()->getByName(scriptName, groupName);
1943 if (tex && tex.use_count() == 0)
1944 UnloadResource(Ogre::TextureManager::getSingletonPtr(), scriptName, groupName);
1949 Ogre::SkeletonPtr skl = Ogre::SkeletonManager::getSingletonPtr()->getByName(scriptName, groupName);
1950 if (skl && skl.use_count() == 0)
1951 UnloadResource(Ogre::SkeletonManager::getSingletonPtr(), scriptName, groupName);
1955 UnloadResource(Ogre::MaterialManager::getSingletonPtr(), scriptName, groupName);
1958 UnloadResource(Ogre::GpuProgramManager::getSingletonPtr(), scriptName, groupName);
1964 ds = Ogre::ResourceGroupManager::getSingleton().openResource(scriptName, groupName);
1970 Ogre::ResourceGroupManager* ogreResourceGroupManager = Ogre::ResourceGroupManager::getSingletonPtr();
1982 Ogre::CompositorManager::getSingleton().parseScript(ds, groupName);
1985 Ogre::ScriptCompilerManager::getSingleton().parseScript(ds, groupName);
1989 ogreResourceGroupManager->declareResource(scriptName,
"Texture", groupName);
2016 catch(
const Ogre::Exception& e)
2028 MMechostr(MSKRUNTIME,
"SO3 Error while parsing %s : %s\n", scriptName.c_str(), e.what());
2036 const SNodeMap nodeListCopy = nodeList;
2037 SNodeMap::const_iterator iNodeList = nodeListCopy.begin();
2038 while (iNodeList != nodeListCopy.end())
2054 const SAnimMap seqAnimCopy = animationList;
2055 SAnimMap::const_iterator iSeqAnim = seqAnimCopy.begin();
2056 while (iSeqAnim != seqAnimCopy.end())
2062 catch(Ogre::Exception&)
2069 animationList.clear();
2079 SGroupMaterialMap::const_iterator iGroupMaterial = groupMaterialListCopy.begin();
2080 while (iGroupMaterial != groupMaterialListCopy.end())
2082 const SMaterialMap materialListCopy = (*iGroupMaterial->second);
2083 SMaterialMap::const_iterator iMaterial = materialListCopy.begin();
2084 while(iMaterial != materialListCopy.end())
2091 listOfMaterial.clear();
2098 SGroupTextureMap::const_iterator iGroupTexture = groupTextureListCopy.begin();
2099 while (iGroupTexture != groupTextureListCopy.end())
2101 const STextureMap textureListCopy = (*iGroupTexture->second);
2102 STextureMap::const_iterator iTexture = textureListCopy.begin();
2103 while(iTexture != textureListCopy.end())
2110 listOfTexture.clear();
2143 if (SO3DebugOverlay)
2146 SO3DebugOverlay->show();
2148 SO3DebugOverlay->hide();
2153void SScene::SetDebugDisplay(
const int& color,
const int& posx,
const int& posy,
const int& width,
const int& height,
const int& charHeight)
2155 if (SO3DebugOverlay)
2157 SO3DebugPanel->setMetricsMode(Ogre::GMM_PIXELS);
2158 SO3DebugPanel->setDimensions(Ogre::Real(width), Ogre::Real(height));
2159 SO3DebugPanel->setPosition(Ogre::Real(posx), Ogre::Real(posy));
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));
2168 SO3DebugOverlay->show();
2174 if (SO3DebugOverlay)
2176 SO3DebugTextArea->setCaption(text);
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();
2191 for (itr = qresult.begin(); itr != qresult.end() && !found; itr++)
2201 if (itr->movable && itr->movable->getVisible())
2203 if (itr->movable->getMovableType() !=
"Entity")
2206 Ogre::Entity* oentity =
static_cast<Ogre::Entity*
>(itr->movable);
2207 if (oentity->getNumSubEntities() == 0)
2210 Ogre::SubEntity* subent = oentity->getSubEntity(0);
2211 Ogre::Any bindedCustomEntity = subent->getUserObjectBindings().getUserAny(
"SEntity");
2212 if (!bindedCustomEntity.has_value())
2215 SEntity* entity = Ogre::any_cast<SEntity*> (bindedCustomEntity);
2216 if (entity == selected)
2220 result.
scene =
this;
2223 result.
point = cameraRay.getOrigin() + (cameraRay.getDirection() * itr->distance);
2229 mRayQuery->clearResults();
2234 mRayQuery->setRay(cameraRay);
2235 mRayQuery->setSortByDistance(
true, 20);
2236 Ogre::RaySceneQueryResult& qresult = mRayQuery->execute();
2237 Ogre::RaySceneQueryResult::iterator itr = qresult.begin();
2242 for (itr = qresult.begin(); itr != qresult.end(); itr++)
2251 if (itr->movable && itr->movable->getVisible())
2253 if (itr->movable->getMovableType() !=
"Entity")
2256 Ogre::Entity* oentity =
static_cast<Ogre::Entity*
>(itr->movable);
2258 if (oentity->getNumSubEntities() == 0)
2261 Ogre::SubEntity* subent = oentity->getSubEntity(0);
2262 Ogre::Any bindedCustomEntity = subent->getUserObjectBindings().getUserAny(
"SEntity");
2263 if (!bindedCustomEntity.has_value())
2266 SEntity* entity = Ogre::any_cast<SEntity*> (bindedCustomEntity);
2272 bool firstFound =
false;
2274 for (itr = qresult.begin(); itr != qresult.end(); itr++)
2283 if (itr->movable && itr->movable->getVisible())
2285 if (itr->movable->getMovableType() !=
"Entity")
2288 Ogre::Entity* oentity =
static_cast<Ogre::Entity*
>(itr->movable);
2289 if (oentity->getNumSubEntities() == 0)
2292 Ogre::SubEntity* subent = oentity->getSubEntity(0);
2293 Ogre::Any bindedCustomEntity = subent->getUserObjectBindings().getUserAny(
"SEntity");
2294 if (!bindedCustomEntity.has_value())
2297 SEntity* entity = Ogre::any_cast<SEntity*> (bindedCustomEntity);
2303 if (oentity->getWorldBoundingBox().contains(cameraRay.getOrigin()) && (i < lsize))
2309 result.
scene =
this;
2314 result.
point = cameraRay.getOrigin() + (cameraRay.getDirection() * itr->distance);
2322 mRayQuery->clearResults();
2327 SGroupMaterialMap::const_iterator iGroupMaterial = listOfMaterial.begin();
2328 while (iGroupMaterial != listOfMaterial.end())
2330 const SMaterialMap materialList = (*iGroupMaterial->second);
2331 SMaterialMap::const_iterator iMaterial = materialList.begin();
2332 while (iMaterial != materialList.end())
2334 iMaterial->second->SetPointSize(size);
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)
MMechostr(MSKDEBUG, " > Start loading Plugin SO3Engine dll\n")
SCOL_EXPORT int cbmachine w
bool checkGroupExists(std::string group)
function to check if an Ogre resource group exists
int getScenePreRenderEvent(struct Mmachine *, SCOL_PTR_TYPE, SCOL_PTR_TYPE)
int SCENE_POST_RENDER_EVENT
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
int SCENE_PRE_RENDER_PHYSIC_EVENT
int SCENE_PRE_RENDER_EVENT
Scol CallBack declaration.
int getScenePostRenderEvent(struct Mmachine *, SCOL_PTR_TYPE, SCOL_PTR_TYPE)
int ANIMATION_END_EVENT
main include
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!
void Update(const Ogre::FrameEvent &evt)
std::string GetName() const
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...
void UpdateShadowFarDistance(const float &distance)
void UpdateShadowFarClipDistance(const float &distance)
SShadowManager * GetShadowManager()
std::string GetGroupName()
void UpdateNodeBody(const bool &bScale)
void SetFlags(const int &flags)
bool GetSceneNodeIsMouseClick()
virtual Ogre::Vector3 GetPosition()
virtual void SetScale(const Ogre::Vector3 &scale)
virtual Ogre::Vector3 GetScale()
void SetSceneNodeIsMouseForeground(const bool &mForeground)
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()
@ SO3_RESOURCE_HIGHLEVELGPUPROGRAM
@ SO3_RESOURCE_COMPOSITOR
@ SO3_RESOURCE_GPUPROGRAM
@ SO3_RESOURCE_PARTICLE_SYSTEM
void SyncParsedMaterials()
static SResourceLoader & getSingleton()
void SetResourceScene(SScene *scene)
const SWindowMap & GetRenderWindowList() const
const SSceneMap & GetSceneList() const
static SRoot * getSingletonPtr()
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)
void DeleteAllAnimations()
Ogre::MaterialPtr materialReceiver
SNode * CreateNodeWithUniqueName(const std::string &basename)
SShadowManager::ShadowQuality GetShadowQuality()
Ogre::SceneManager * O3SceneManager
SAnimMap GetAnimations() const
bool ParseResourceScript(const std::string &groupName, const std::string &scriptName, const SResource::ResourceType &scriptType)
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
void DeleteBone(SBone *existingBone)
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)
void UpdateLightsShadowParameters()
Ogre::SkeletonManager * O3SkeletonManager
void RegisterViewport(SViewPort *viewport)
SEntity * CreateOctahedron(const std::string &groupName, const std::string &newEntityName, const float &base, const float &bottom, const float &dist)
SMaterial * GetMaterial(const std::string &groupName, const std::string &materialName, bool searchOtherGroups=true)
void DeleteTerrain(STerrain *terrain)
SLight * CreateLight(const std::string &newLightName)
void SetMaterialsPointSize(Ogre::Real size)
void SetDebugText(const std::string &text)
void SetShadowType(const SShadowManager::ShadowType &shadowType)
const SNodeMap & GetNodeList() const
bool UnloadResource(Ogre::ResourceManager *resMgr, const std::string &resName, const std::string &groupName)
Ogre::MaterialPtr skyBoxMat
bool UnloadParticles(const std::string &filename, const std::string &groupName)
void SetShadowQuality(const SShadowManager::ShadowQuality &quality)
const SGroupMaterialMap * GetMaterials()
Ogre::MaterialPtr materialCaster
SEnvironment * GetEnvironment() const
Ogre::TextureManager * O3TextureManager
SDynamicCubeMap * CreateDynamicCubeMap(const std::string &newDynamicCubeMapName)
Ogre::MaterialPtr skyDomeMat
SEnvironment * environment
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)
bool AddNode(SNode *existingNode)
Ogre::MaterialManager * O3MaterialManager
SEntity * CreatePlane(const std::string &groupName, const std::string &newEntityName, const SPointFloat &sizev, const SPointInt &seg, const SPointFloat &uv)
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)
SCamera * CreateCamera(const std::string &newCameraName)
void CleanGroupTextures(const std::string &groupName)
void DeleteDynamicCubeMap(SDynamicCubeMap *existingDynamicCubeMap)
SBone * CreateBone(const std::string &newBoneName, SSkeleton *skeleton, const unsigned short &id)
SEntity * CreateSphere(const std::string &groupName, const std::string &newEntityName, const float &radius, const int &rings, const int &segments)
void RemoveNode(SNode *existingNode)
const SGroupTextureMap * GetTextures()
const STerrainMap & GetTerrainList() const
SShadowManager::ShadowType GetShadowType()
SNode * GetNode(const std::string &nodeName) const
STexture * GetTexture(const std::string &groupName, const std::string &texName)
void DeleteLight(SLight *existingLight)
void DeleteTexture(STexture *texture)
SMaterial * CreateMaterial(const std::string &groupname, const std::string &matname, const bool &loadedFromScript=false)
SPhysicWorld * GetPhysicsWorld()
bool UnloadVertexPrograms(const std::string &filename, const std::string &groupName)
SEntity * CloneEntity(const std::string &newEntityName, SEntity *entity)
SSkeleton * CreateSkeleton(const std::string &newSkeletonName, SEntity *entity)
void ReloadInternalRessources()
bool NodeExist(const std::string &name)
SEntity * CreateEntity(const std::string &groupName, const std::string &newEntityName, const std::string &meshName, bool loadInBackground=false)
Ogre::SceneManager * GetOgreScenePointer()
void DeleteRenderToTexture(SRenderToTexture *existingRenderToTexture)
void RemoveAnimation(SAnim *existingAnimation)
void DeleteNode(SNode *existingNode)
void DeleteLineEntity(SLineEntity *existingLineEntity)
SSequenceAnimation * CreateAnimationSequence(const std::string &animationName)
SLineEntity * CreateLineEntity(const std::string &newLineEntityName, bool dashed=false, bool disableDepth=false)
void DeleteMaterial(SMaterial *material)
void DeleteSkeleton(SSkeleton *existingSkeleton)
void GetSimpleRayCast(Ogre::Ray cameraRay, SRaycastResult &result)
STerrain * CreateTerrain(const std::string &name)
void DeleteParticleSystem(SParticleSystem *existingParticleSystem)
Ogre::MeshManager * O3MeshManager
void DeleteEntity(SEntity *existingEntity)
Ogre::ColourValue GetAmbientLight()
SLightingManager * GetLightingManager()
void SetAmbientLight(const Ogre::ColourValue &color)
void DeleteAllMaterials()
void CleanGroupMaterials(const std::string &groupName)
void SetShadowType(const ShadowType &type)
ShadowType GetShadowType()
void SetShadowQuality(ShadowQuality quality)
ShadowQuality GetShadowQuality()
@ SO3_SHADOWS_QUALITY_LOW
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