MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scenemanager.cpp
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _graphicsscenemanager_cpp
41 #define _graphicsscenemanager_cpp
42 
43 #include "Graphics/cameramanager.h"
44 #include "Graphics/scenemanager.h"
45 
46 #include "Physics/physicsmanager.h"
47 
48 #include "UI/uimanager.h"
49 
50 #include "areaeffectmanager.h"
51 #include "plane.h"
52 #include "worldobject.h"
53 #include "stringtool.h"
54 #include "entresol.h"
55 
57 #include "Graphics/entityproxy.h"
58 #include "Graphics/lightproxy.h"
60 
61 #include <memory>
62 
63 #include <Ogre.h>
64 
65 namespace Mezzanine
66 {
67  namespace Graphics
68  {
69  /// @brief Stores internal data for the SCeneManager to keep it from cluttering the Header file
70  /// @internal
72  {
73  public:
74 
75  /// @internal
76  /// @brief A Pointer to the scenemanager this works with
78 
79  /// @internal
80  /// @brief The currently active sky, if set to anything other than SkyNone, then the 5 other skycache variable may have meaning
82 
83  // The SkyCache
84  /// @internal
85  /// @brief The Name of the Material the sky is made of
87  /// @internal
88  /// @brief The orientation of the sky, unless it's a Skyplane, this this is all 0s
90  /// @internal
91  /// @brief The name of the group the sky material is in
93  /// @internal
94  /// @brief When is the sky drawn, first or per Z-order
96  /// @internal
97  /// @brief Used to describe a skyplane instead of orientation
99 
100  /// @brief The size
101  unsigned short ShadowTextureSize;
102 
103  /// @internal
104  /// @brief Pointer for the Ogre Scenemanager, where this manager gets it's functionality.
105  Ogre::SceneManager* OgreManager;
106 
107  /// @internal
108  /// @brief Disable the sky ina given scenemanager
109  /// @param ScenePTR A pointer to the scenmanager.
110  void DisableSky(SceneManager* ScenePTR)
111  {
112  switch(ActiveSky)
113  {
115  break;
117  ScenePTR->DisableSkyPlane();
118  break;
120  ScenePTR->DisableSkyBox();
121  break;
123  ScenePTR->DisableSkyDome();
124  break;
125  }
127  }
128 
129  /// @internal
130  /// @brief update the information that is cached about the sky
133  String FreshSkyMaterialName = "",
134  Quaternion FreshSkyOrientation = Quaternion(0,0,0,0),
135  String FreshSkyMaterialGroupName = "",
136  bool FreshSkyDrawnFirst = false,
137  Plane FreshSkyThePlane = Plane(Vector3(0,0,0),0)
138  )
139  {
140  ActiveSky=FreshSkyMethod;
141  SkyOrientation=FreshSkyOrientation;
142  SkyMaterialName=FreshSkyMaterialName;
143  SkyMaterialGroupName=FreshSkyMaterialGroupName;
144  SkyDrawnFirst=FreshSkyDrawnFirst;
145  SkyThePlane=FreshSkyThePlane;
146  }
147 
148  /// @internal
149  /// @brief Create One of these, the data every scenemanager needs.
150  /// @param _SM A pointer to the scenemanager this with work with in general
152  SM(_SM),
153  ActiveSky(SceneManager::SkyNone),
154  SkyMaterialName(""),
155  SkyOrientation(0,0,0,0),
157  SkyDrawnFirst(false),
158  SkyThePlane(Vector3(0,0,0),0),
159  ShadowTextureSize(512),
160  OgreManager(0)
161  {
162 
163  }
164 
165 
166  /// @internal
167  /// @brief Destructor
169  {
170  Ogre::Root::getSingleton().destroySceneManager(OgreManager);
171  }
172  };//SceneManagerData
173 
174  ///////////////////////////////////////////////////////////////////////////////
175  // SceneManager Methods
176 
177  SceneManager::SceneManager(const String& InternalManagerTypeName) :
178  ThreadResources(NULL)
179  {
180  this->SMD = new SceneManagerData(this);
181  this->SMD->OgreManager = Ogre::Root::getSingleton().createSceneManager(InternalManagerTypeName);
182  //this->SetAmbientLight(ColourValue(0.0,0.0,0.0));
183  // ©onst Ogre::ShadowCameraSetupPtr ShadowCam = Ogre::ShadowCameraSetupPtr(new Ogre::DefaultShadowCameraSetup());
184  //OgreManager->setShadowCameraSetup(ShadowCam);
185  }
186 
188  ThreadResources(NULL)
189  {
190  this->SMD = new SceneManagerData(this);
191 
192  XML::Attribute CurrAttrib;
193  // Get the name of the manager to construct.
194  String ManagerName;
195  XML::Node ManagerType = XMLNode.GetChild("ManagerType");
196  if(!ManagerType.Empty())
197  {
198  CurrAttrib = ManagerType.GetAttribute("TypeName");
199  if(!CurrAttrib.Empty())
200  ManagerName = CurrAttrib.AsString();
201  }
202  if(ManagerName.empty())
203  ManagerName = "Default";
204  this->SMD->OgreManager = Ogre::Root::getSingleton().createSceneManager(ManagerName+"SceneManager");
205 
206  // Setup the shadow configuration
207  bool TextureShadows = false;
208  XML::Node ShadowSettings = XMLNode.GetChild("ShadowSettings");
209  if(!ShadowSettings.Empty())
210  {
211  String TechniqueName;
212  CurrAttrib = ShadowSettings.GetAttribute("Technique");
213  if(!CurrAttrib.Empty())
214  {
215  TechniqueName = CurrAttrib.AsString();
216  if( "StencilModulative" == TechniqueName )
218  else if( "StencilAdditive" == TechniqueName )
220  else if( "TextureModulative" == TechniqueName )
222  else if( "TextureAdditive" == TechniqueName )
224  else if( "TextureAdditiveIntegrated" == TechniqueName )
226  else if( "TextureModulativeIntegrated" == TechniqueName )
228  }
229 
230  if(!TechniqueName.empty())
231  {
232  if(String::npos != TechniqueName.find("Texture"))
233  TextureShadows = true;
234 
235  CurrAttrib = ShadowSettings.GetAttribute("ShadowColour");
236  if(!CurrAttrib)
238 
239  CurrAttrib = ShadowSettings.GetAttribute("ShadowFarDistance");
240  if(!CurrAttrib)
241  SetShadowFarDistance(CurrAttrib.AsReal());
242  }
243  }
244 
245  // Setup texture shadow settings if any are set.
246  XML::Node TextureShadowSettings = XMLNode.GetChild("TextureShadowSettings");
247  if(!TextureShadowSettings.Empty() && TextureShadows)
248  {
249  CurrAttrib = TextureShadowSettings.GetAttribute("ShadowTextureCount");
250  if(!CurrAttrib.Empty())
251  SetShadowTextureCount(CurrAttrib.AsWhole());
252 
253  CurrAttrib = TextureShadowSettings.GetAttribute("ShadowTextureSize");
254  if(!CurrAttrib.Empty())
255  SetShadowTextureSize(static_cast<unsigned short>(CurrAttrib.AsWhole()));
256  }
257  }
258 
260  {
261  this->Deinitialize();
262 
263  delete this->SMD;
264  }
265 
266  ///////////////////////////////////////////////////////////////////////////////
267  // Shadow Management
268 
270  {
271  Ogre::ShadowTechnique Type;
272  switch (Shadows)
273  {
275  Type = Ogre::SHADOWTYPE_STENCIL_MODULATIVE;
276  break;
278  Type = Ogre::SHADOWTYPE_STENCIL_ADDITIVE;
279  break;
281  Type = Ogre::SHADOWTYPE_TEXTURE_MODULATIVE;
282  break;
284  Type = Ogre::SHADOWTYPE_TEXTURE_ADDITIVE;
285  break;
287  Type = Ogre::SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED;
288  break;
290  Type = Ogre::SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED;
291  break;
292  default:
293  Type = Ogre::SHADOWTYPE_NONE;
294  }
295  this->SMD->OgreManager->setShadowTechnique(Type);
296  }
297 
299  {
300  Ogre::ShadowTechnique ShadowType = this->SMD->OgreManager->getShadowTechnique();
301  switch (ShadowType)
302  {
303  case Ogre::SHADOWTYPE_STENCIL_MODULATIVE:
304  return SST_Stencil_Modulative;
305  break;
306  case Ogre::SHADOWTYPE_STENCIL_ADDITIVE:
307  return SST_Stencil_Additive;
308  break;
309  case Ogre::SHADOWTYPE_TEXTURE_MODULATIVE:
310  return SST_Texture_Modulative;
311  break;
312  case Ogre::SHADOWTYPE_TEXTURE_ADDITIVE:
313  return SST_Texture_Additive;
314  break;
315  case Ogre::SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED:
317  break;
318  case Ogre::SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED:
320  break;
321  default:
322  return SST_None;
323  }
324  }
325 
327  { this->SMD->OgreManager->setShadowTextureCount(Count); }
328 
330  { return this->SMD->OgreManager->getShadowTextureCount(); }
331 
332  void SceneManager::SetShadowTextureSize(unsigned short Size)
333  {
334  this->SMD->OgreManager->setShadowTextureSize(Size);
335  this->SMD->ShadowTextureSize=Size;
336  }
337 
338  unsigned short SceneManager::GetShadowTextureSize() const
339  { return this->SMD->ShadowTextureSize; }
340 
342  { this->SMD->OgreManager->setShadowFarDistance(FarDist); }
343 
345  { return this->SMD->OgreManager->getShadowFarDistance(); }
346 
347  void SceneManager::SetShadowColour(const ColourValue& ShadowColour)
348  { this->SMD->OgreManager->setShadowColour(ShadowColour.GetOgreColourValue()); }
349 
351  {
352  ColourValue Shadow(this->SMD->OgreManager->getShadowColour());
353  return Shadow;
354  }
355 
356  ///////////////////////////////////////////////////////////////////////////////
357  // Sky Surface Management
358 
359  void SceneManager::CreateSkyPlane(const Plane& SkyPlane_, const String& Material, const String& Group, Real Scale, Real Tiling, bool DrawFirst, Real Bow, int XSegments, int YSegments)
360  {
361  this->SMD->DisableSky(this);
362  this->SMD->UpdateSkyCache(SkyPlane, Material, Quaternion(0,0,0,0), Group, DrawFirst, SkyPlane_);
363  this->SMD->OgreManager->setSkyPlane(true, SkyPlane_.GetOgrePlane(), Material, Scale, Tiling, DrawFirst, Bow, XSegments, YSegments, Group);
364  }
365 
367  {
368  this->SMD->OgreManager->setSkyPlane(false, Ogre::Plane(), "");
369  }
370 
371  void SceneManager::CreateSkyBox(const String& Material, const String& Group, Real Distance, bool DrawFirst, Quaternion Orientation)
372  {
373  this->SMD->DisableSky(this);
374  this->SMD->UpdateSkyCache(SkyBox, Material, Orientation, Group, DrawFirst);
375  this->SMD->OgreManager->setSkyBox(true, Material, Distance, DrawFirst, Orientation.GetOgreQuaternion(), Group);
376  }
377 
379  {
380  this->SMD->OgreManager->setSkyBox(false, "");
381  }
382 
383  void SceneManager::CreateSkyDome(const String& Material, const String& Group, Real Distance, Real Curvature, Real Tiling, bool DrawFirst,
384  Quaternion Orientation, int XSegments, int YSegments)
385  {
386  this->SMD->DisableSky(this);
387  this->SMD->UpdateSkyCache(SkyDome, Material, Orientation, Group, DrawFirst);
388  this->SMD->OgreManager->setSkyDome(true, Material, Curvature, Tiling, Distance, DrawFirst, Orientation.GetOgreQuaternion(), XSegments, YSegments, -1, Group);
389  }
390 
392  {
393  this->SMD->OgreManager->setSkyDome(false, "");
394  }
395 
397  {
398  this->SMD->DisableSky(this);
399  this->SMD->UpdateSkyCache();
400  }
401 
403  { return this->SMD->ActiveSky; }
404 
405  ///////////////////////////////////////////////////////////////////////////////
406  // Creating Proxies
407 
409  {
410  BillboardSetProxy* NewProxy = new BillboardSetProxy(InitialPoolSize,this);
411  this->Proxies.push_back(NewProxy);
412  return NewProxy;
413  }
414 
416  {
417  BillboardSetProxy* NewProxy = new BillboardSetProxy(SelfRoot,this);
418  this->Proxies.push_back(NewProxy);
419  return NewProxy;
420  }
421 
423  {
424  EntityProxy* NewProxy = new EntityProxy(this);
425  this->Proxies.push_back(NewProxy);
426  return NewProxy;
427  }
428 
430  {
431  EntityProxy* NewProxy = new EntityProxy(TheMesh,this);
432  this->Proxies.push_back(NewProxy);
433  return NewProxy;
434  }
435 
436  EntityProxy* SceneManager::CreateEntityProxy(const String& MeshName, const String& GroupName)
437  {
438  EntityProxy* NewProxy = new EntityProxy(MeshName,GroupName,this);
439  this->Proxies.push_back(NewProxy);
440  return NewProxy;
441  }
442 
444  {
445  EntityProxy* NewProxy = new EntityProxy(SelfRoot,this);
446  this->Proxies.push_back(NewProxy);
447  return NewProxy;
448  }
449 
451  {
452  LightProxy* NewProxy = new LightProxy(this);
453  this->Proxies.push_back(NewProxy);
454  return NewProxy;
455  }
456 
458  {
459  LightProxy* NewProxy = new LightProxy(Type,this);
460  this->Proxies.push_back(NewProxy);
461  return NewProxy;
462  }
463 
465  {
466  LightProxy* NewProxy = new LightProxy(SelfRoot,this);
467  this->Proxies.push_back(NewProxy);
468  return NewProxy;
469  }
470 
472  {
473  ParticleSystemProxy* NewProxy = new ParticleSystemProxy(Template,this);
474  this->Proxies.push_back(NewProxy);
475  return NewProxy;
476  }
477 
479  {
480  ParticleSystemProxy* NewProxy = new ParticleSystemProxy(SelfRoot,this);
481  this->Proxies.push_back(NewProxy);
482  return NewProxy;
483  }
484 
485  ///////////////////////////////////////////////////////////////////////////////
486  // Proxy Management
487 
489  { return this->Proxies.at(Index); }
490 
492  { return this->Proxies.size(); }
493 
495  {
496  for( ProxyIterator ProxIt = this->Proxies.begin() ; ProxIt != this->Proxies.end() ; ++ProxIt )
497  {
498  if( ToBeDestroyed == (*ProxIt) ) {
499  WorldObject* Parent = (*ProxIt)->GetParentObject();
500  if( Parent )
501  Parent->_NotifyProxyDestroyed( (*ProxIt) );
502 
503  delete (*ProxIt);
504  this->Proxies.erase(ProxIt);
505  return;
506  }
507  }
508  }
509 
511  {
512  for( ProxyIterator ProxIt = this->Proxies.begin() ; ProxIt != this->Proxies.end() ; ++ProxIt )
513  {
514  WorldObject* Parent = (*ProxIt)->GetParentObject();
515  if( Parent )
516  Parent->_NotifyProxyDestroyed( (*ProxIt) );
517 
518  delete (*ProxIt);
519  }
520  this->Proxies.clear();
521  }
522 
523  ///////////////////////////////////////////////////////////////////////////////
524  // Light Management
525 
526  void SceneManager::SetAmbientLight(Real Red, Real Green, Real Blue, Real Alpha)
527  {
528  this->SMD->OgreManager->setAmbientLight(Ogre::ColourValue(Red, Green, Blue, Alpha));
529  }
530 
532  {
533  this->SMD->OgreManager->setAmbientLight(LightColor.GetOgreColourValue());
534  }
535 
537  {
538 
539  return ColourValue(this->SMD->OgreManager->getAmbientLight());
540  }
541 
542  ///////////////////////////////////////////////////////////////////////////////
543  // Utility
544 
546  { return this->SMD->OgreManager->getName(); }
547 
549  {
550  for( SceneManager::ProxyIterator it = Proxies.begin() ; it != Proxies.end() ; it++ )
551  if( (*it)->GetProxyType() == Mezzanine::PT_Graphics_ParticleSystemProxy )
552  static_cast<ParticleSystemProxy*>( (*it) )->PauseParticleSystem(Pause);
553  }
554 
556  {
557  // Do nothing for now
558  }
559 
561  {
562  if( !this->Initialized )
563  {
564  // Manager Initializations
565  //WorldManager::Initialize();
566 
567  CameraManager* CamMan = this->TheEntresol->GetCameraManager();
568  if( CamMan ) {
569  CamMan->Initialize();
570  }
571 
572  this->Initialized = true;
573  }
574  }
575 
577  {
578  if( this->Initialized )
579  {
580  this->DestroyAllProxies();
581 
582  // Manager Initializations
583  CameraManager* CamMan = this->TheEntresol->GetCameraManager();
584  if( CamMan ) {
585  CamMan->Deinitialize();
586  }
587 
588  this->Initialized = false;
589  }
590  }
591 
592  ///////////////////////////////////////////////////////////////////////////////
593  // Type Identifier Methods
594 
596  { return ManagerBase::MT_SceneManager; }
597 
599  { return "DefaultSceneManager"; }
600 
601  ///////////////////////////////////////////////////////////////////////////////
602  // Internal/Other
603 
604  Ogre::SceneManager* SceneManager::_GetGraphicsWorldPointer() const
605  { return (this->SMD && this->SMD->OgreManager) ? this->SMD->OgreManager : 0; }
606 
608  { return this->SMD; }
609 
610  ///////////////////////////////////////////////////////////////////////////////
611  // DefaultSceneManagerFactory Methods
612 
614  {
615  }
616 
618  {
619  }
620 
622  {
623  return "DefaultSceneManager";
624  }
625 
627  {
628  if(Params.empty()) return new SceneManager();
629  else
630  {
631  String InternalManagerTypeName;
632  for( NameValuePairList::iterator ParIt = Params.begin() ; ParIt != Params.end() ; ++ParIt )
633  {
634  String Lower = (*ParIt).first;
636  if( "internalmanagertypename" == Lower )
637  {
638  InternalManagerTypeName = (*ParIt).second;
639  }
640  }
641  return new SceneManager(InternalManagerTypeName);
642  }
643  }
644 
646  {
647  return new SceneManager(XMLNode);
648  }
649 
651  {
652  delete ToBeDestroyed;
653  }
654  }//Graphics
655 }//Mezzanine
656 
657 ///////////////////////////////////////////////////////////////////////////////
658 // Class External << Operators for streaming or assignment
659 std::ostream& operator << (std::ostream& stream, const Mezzanine::Graphics::SceneManager& Ev)
660 {
661  stream << "<SceneManager Version=\"1\" Name=\"" << Ev.GetName()
662  //<< "\" Type=\"" << Ev.GetType()
663  << "\" SceneShadowTechnique=\"" << Ev.GetSceneShadowTechnique()
664  << "\" ShadowTextureCount=\"" << Ev.GetShadowTextureCount()
665  << "\" ShadowTextureSize=\"" << Ev.GetShadowTextureSize()
666  << "\" ShadowFarDistance=\"" << Ev.GetShadowFarDistance()
667  << "\" SkyMethod=\"" << Ev.WhichSky()
668  << "\">"
669  << "<ShadowColour>" << Ev.GetShadowColour() << "</ShadowColour>"
670  << "<AmbientLight>" << Ev.GetAmbientLight() << "</AmbientLight>";
671 
673  switch (Ev.WhichSky())
674  {
676  // Nothing to do
677  break;
679  Ogre::SceneManager::SkyPlaneGenParameters Values=SMD->OgreManager->getSkyPlaneGenParameters();
680  stream << "<SkyPlane Version=\"1"
681  << "\" MaterialName=\"" << SMD->SkyMaterialName
682  << "\" MaterialGroupName=\"" << SMD->SkyMaterialGroupName
683  << "\" DrawFirst=\"" << SMD->SkyDrawnFirst
684  << "\" Scale=\"" << Values.skyPlaneScale
685  << "\" Tiling=\"" << Values.skyPlaneTiling
686  << "\" Bow=\"" << Values.skyPlaneBow
687  << "\" XSegments=\"" << Values.skyPlaneXSegments
688  << "\" YSegments=\"" << Values.skyPlaneYSegments
689  << "\" >"
690  << SMD->SkyThePlane
691  << "</SkyPlane>";
692  // ©onst Plane& SkyPlane_, const String& Material, const String& Group, Real Scale, Real Tiling, bool DrawFirst, Real Bow, int XSegments, int YSegments
693  }
694  break;
696  Ogre::SceneManager::SkyBoxGenParameters Values = SMD->OgreManager->getSkyBoxGenParameters();
697  stream << "<SkyBox Version=\"1"
698  << "\" MaterialName=\"" << SMD->SkyMaterialName
699  << "\" MaterialGroupName=\"" << SMD->SkyMaterialGroupName
700  << "\" DrawFirst=\"" << SMD->SkyDrawnFirst
701  << "\" Distance=\"" << Values.skyBoxDistance
702  << "\" >"
703  << "<Orientation>" << SMD->SkyOrientation << "</Orientation>"
704  << "</SkyBox>";
705  // ©onst String& Material, const String& Group, Real Distance, bool DrawFirst=true, Quaternion Orientation=Quaternion()
706  }
707  break;
709  Ogre::SceneManager::SkyDomeGenParameters Values=SMD->OgreManager->getSkyDomeGenParameters();
710  stream << "<SkyDome Version=\"1"
711  << "\" MaterialName=\"" << SMD->SkyMaterialName
712  << "\" MaterialGroupName=\"" << SMD->SkyMaterialGroupName
713  << "\" DrawFirst=\"" << SMD->SkyDrawnFirst
714  << "\" Distance=\"" << Values.skyDomeDistance
715  << "\" Curvature=\"" << Values.skyDomeCurvature
716  << "\" Tiling=\"" << Values.skyDomeTiling
717  << "\" XSegments=\"" << Values.skyDomeXSegments
718  << "\" YSegments=\"" << Values.skyDomeYSegments
719  << "\" YSegments_keep=\"" << Values.skyDomeYSegments_keep
720  << "\" >"
721  << "<Orientation>" << SMD->SkyOrientation << "</Orientation>"
722  << "</SkyDome>";
723  // ©onst String& Material, const String& Group, Real Distance, Real Curvature=10.0, Real Tiling=8.0, bool DrawFirst=true, Quaternion Orientation=Quaternion(), int XSegments=16, int YSegments=16
724  }
725  break;
726  }
727  /* Sky Cache Member - String SkyMaterialName; Quaternion SkyOrientation; String SkyMaterialGroupName; bool SkyDrawnFirst; Plane SkyThePlane; */
728  stream << "</SceneManager>";
729 
730 
731 // --name
732 // --shadow type
733 // --shadow Texture count
734 // --shadpw texture size
735 // --shadow distance
736 // --shadow colour
737 // --Sky
738 // -- Disable
739 // -- Plane& SkyPlane, String& Material, String& Group, Real Scale=1000.0, Real Tiling=10.0, bool DrawFirst=true, Real Bow=0, int XSegments=1, int YSegments=1
740 // -- SkyBox(String& Material, String& Group, Real Distance, bool DrawFirst=true, Quaternion Orientation=Quaternion());
741 // -- SkyDome(String& Material, String& Group, Real Distance, Real Curvature=10.0, Real Tiling=8.0, bool DrawFirst=true, Quaternion Orientation=Quaternion(), int XSegments=16, int YSegments=16);
742 // -- Ambient light
743 // -- iterate over
744 // -- lights
745 // -- particles
746 // -- Worldnodes
747 
748  return stream;
749 }
750 
751 std::istream& MEZZ_LIB operator >> (std::istream& stream, Mezzanine::Graphics::SceneManager& Ev)
752 {
755 
756  Doc->GetFirstChild() >> Ev;
757 
758  return stream;
759 }
760 
762 {
763  if ( Mezzanine::String(OneNode.Name())==Mezzanine::String("SceneManager") )
764  {
765  if(OneNode.GetAttribute("Version").AsInt() == 1)
766  {
767  //Ev.SetType(static_cast<Mezzanine::SceneManager::SceneManagerType>(OneNode.GetAttribute("Type").AsInt()));
769  Ev.SetShadowTextureCount(OneNode.GetAttribute("ShadowTextureCount").AsInt());
770  Ev.SetShadowTextureSize(OneNode.GetAttribute("ShadowTextureSize").AsInt());
771  Ev.SetShadowFarDistance(OneNode.GetAttribute("ShadowFarDistance").AsReal());
773 
774  for(Mezzanine::XML::Node Child = OneNode.GetFirstChild(); Child!=0; Child = Child.GetNextSibling())
775  {
776  Mezzanine::String Name(Child.Name());
777  switch(Name[0])
778  {
779  case 'A': // AmbientLight
780  if(Name==Mezzanine::String("AmbientLight"))
781  {
782  if(Mezzanine::String(Child.GetFirstChild().Name()) == "ColourValue")
783  {
784  Mezzanine::ColourValue AllAroundUs;
785  Child.GetFirstChild() >> AllAroundUs;
786  Ev.SetAmbientLight(AllAroundUs);
787  }else{
788  MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML for SceneManager: Includes unknown Element AmbientLight-\"" + Name + "\".");
789  }
790  }else{
791  MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML for SceneManager: Includes unknown Element Sd-\"" + Name + "\".");
792  }
793  break;
794  case 'S': // Sky of some kind or "ShadowColor"
795  switch(Name[3])
796  {
797  case 'd': // ShadowColour
798  if(Name==Mezzanine::String("ShadowColour"))
799  {
800  if(Child.GetFirstChild())
801  {
802  if(Mezzanine::String(Child.GetFirstChild().Name()) == "ColourValue")
803  {
804  Mezzanine::ColourValue InTheShade;
805  Child.GetFirstChild() >> InTheShade;
806  Ev.SetShadowColour(InTheShade);
807  }else{
808  MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML for SceneManager: Includes unknown Element ShadowColour-\"" + Mezzanine::String(Child.GetFirstChild().Name()) + "\".");
809  }
810  }else{
811  MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML for SceneManager: ShadowColour has no child");
812  }
813  }else{
814  MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML for SceneManager: Includes unknown Element Sd-\"" + Name + "\".");
815  }
816  break;
817  case 'B': // SkyBox
818  if(Name==Mezzanine::String("SkyBox"))
819  {
820  if(Child.GetAttribute("Version").AsInt() == 1)
821  {
822  Mezzanine::Quaternion Orientation;
823  if(Mezzanine::String(Child.GetFirstChild().Name()) == "Orientation")
824  {
825  Child.GetFirstChild().GetFirstChild() >> Orientation;
826  }else{
827  MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML for SceneManager: Includes unknown Element Orientation-\"" + Name + "\".");
828  }
829  Ev.CreateSkyBox( Child.GetAttribute("MaterialName").AsString(),
830  Child.GetAttribute("MaterialGroupName").AsString(),
831  Child.GetAttribute("Distance").AsReal(),
832  Child.GetAttribute("DrawFirst").AsBool(),
833  Orientation);
834  }else{
835  MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML for SkyBox: Not Version 1.");
836  }
837  }else{
838  MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML for SceneManager: Includes unknown Element SB-\"" + Name + "\".");
839  }
840  break;
841  case 'D': // SkyDome
842  if(Name==Mezzanine::String("SkyDome"))
843  {
844  if(Child.GetAttribute("Version").AsInt() == 1)
845  {
846  Mezzanine::Quaternion Orientation;
847  if(Mezzanine::String(Child.GetFirstChild().Name()) == "Orientation")
848  {
849  Child.GetFirstChild().GetFirstChild() >> Orientation;
850  }else{
851  MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML for SceneManager: Includes unknown Element Orientation-\"" + Name + "\".");
852  }
853  Ev.CreateSkyDome( Child.GetAttribute("MaterialName").AsString(),
854  Child.GetAttribute("MaterialGroupName").AsString(),
855  Child.GetAttribute("Distance").AsReal(),
856  Child.GetAttribute("Curvature").AsReal(),
857  Child.GetAttribute("Tiling").AsReal(),
858  Child.GetAttribute("DrawFirst").AsBool(),
859  Orientation,
860  Child.GetAttribute("XSegments").AsInt(),
861  Child.GetAttribute("YSegments").AsInt());
862 
863  }else{
864  MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML for SkyDome: Not Version 1.");
865  }
866  }else{
867  MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML for SceneManager: Includes unknown Element SD-\"" + Name + "\".");
868  }
869  break;
870  case 'P': // SkyPlane
871  if(Name==Mezzanine::String("SkyPlane"))
872  {
873  Mezzanine::Plane SkyOrientation;
874  Child.GetFirstChild() >> SkyOrientation;
875 
876  if(Child.GetAttribute("Version").AsInt() == 1)
877  {
878  Ev.CreateSkyPlane( SkyOrientation,
879  Child.GetAttribute("MaterialName").AsString(),
880  Child.GetAttribute("MaterialGroupName").AsString(),
881  Child.GetAttribute("Scale").AsReal(),
882  Child.GetAttribute("Tiling").AsReal(),
883  Child.GetAttribute("DrawFirst").AsBool(),
884  Child.GetAttribute("Bow").AsBool(),
885  Child.GetAttribute("XSegments").AsInt(),
886  Child.GetAttribute("YSegments").AsInt());
887  }else{
888  MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML for SkyPlane: Not Version 1.");
889  }
890  }else{
891  MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML for SceneManager: Includes unknown Element SP-\"" + Name + "\".");
892  }
893  break;
894  }
895  break;
896  default:
897  { MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML for SceneManager: Includes unknown Element def-\"" + Name + "\"."); }
898  }
899  }
900  }else{
901  MEZZ_EXCEPTION(Mezzanine::Exception::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for SceneManager: Not Version 1.");
902  }
903  }else{
904  MEZZ_EXCEPTION(Mezzanine::Exception::II_IDENTITY_INVALID_EXCEPTION,"Attempting to deserialize a SceneManager, found a " + Mezzanine::String(OneNode.Name()));
905  }
906 }
907 
908 
909 
910 #endif