MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scenemanager.h
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_h
41 #define _graphicsscenemanager_h
42 
43 #include "colourvalue.h"
44 #include "worldmanager.h"
45 #include "managerfactory.h"
46 #include "singleton.h"
47 #include "quaternion.h"
48 #include "vector3.h"
49 #include "Graphics/graphicsenumerations.h"
50 #ifndef SWIG
51  #include "XML/xml.h"
52 #endif
53 #include "Threading/workunit.h"
54 
55 namespace Ogre
56 {
57  class SceneManager;
58 }
59 
60 namespace Mezzanine
61 {
62  class Entresol;
63  class Plane;
64  namespace Graphics
65  {
66  class RenderableProxy;
67  class BillboardSetProxy;
68  class EntityProxy;
69  class LightProxy;
70  class ParticleSystemProxy;
71  class SceneManager;
72  class SceneManagerData;
73  class Mesh;
74 
75  ///////////////////////////////////////////////////////////////////////////////
76  /// @brief This class contains utilities and functions to allow the manipulation of the Graphical
77  /// scene, rather then the physics inside, or the object inside.
78  /// @details This class contains functions that allow the manipulation of lighting, skyboxes, internal
79  /// scenemanager types, and more.
80  ///////////////////////////////////////
82  {
83  public:
84  /// @brief Basic container type for RenderableProxy storage by this class.
85  typedef std::vector< RenderableProxy* > ProxyContainer;
86  /// @brief Iterator type for RenderableProxy instances stored by this class.
87  typedef ProxyContainer::iterator ProxyIterator;
88  /// @brief Const Iterator type for RenderableProxy instances stored by this class.
89  typedef ProxyContainer::const_iterator ConstProxyIterator;
90 
91  /// @brief needs to be documented
93  { //Shadow Docs from Ogre ShadowTechnique Documentation.
94  SST_None = 0, ///< No shadows.
95  SST_Stencil_Modulative = 1, ///< Stencil shadow technique which renders all shadow volumes as a modulation after all the non-transparent areas have been rendered.
96  SST_Stencil_Additive = 2, ///< Stencil shadow technique which renders each light as a separate additive pass to the scene.
97  SST_Texture_Modulative = 11, ///< Texture-based shadow technique which involves a monochrome render-to-texture of the shadow caster and a projection of that texture onto the shadow receivers as a modulative pass.
98  SST_Texture_Additive = 12, ///< Texture-based shadow technique which involves a render-to-texture of the shadow caster and a projection of that texture onto the shadow receivers, built up per light as additive passes.
99  SST_Texture_Additive_Integrated = 13, ///< Texture-based shadow technique which involves a render-to-texture of the shadow caster and a projection of that texture on to the shadow receivers, with the usage of those shadow textures completely controlled by the materials of the receivers.
100  SST_Texture_Modulative_Integrated = 14 ///< Texture-based shadow technique which involves a render-to-texture of the shadow caster and a projection of that texture on to the shadow receivers, with the usage of those shadow textures completely controlled by the materials of the receivers.
101  };
102 
103  /// @brief Used to help identify which method is used to draw the sky, if any
105  {
106  SkyNone = 0, ///< No Sky rendering at all.
107  SkyPlane = 1, ///< A flat plane use to draw the sky.
108  SkyBox = 2, ///< A box using 5 Rectangles to draw the sky.
109  SkyDome = 3 ///< A multifaceted hemispherical dome, the most sophisticated sky background.
110  };
111  protected:
112  friend class TrackingNodeUpdateWorkUnit;
113 
114  /// @internal
115  /// @brief Container storing all of the RenderableProxy instances created by this manager.
117 
118  /// @internal
119  /// @brief Pointer to a class storing sensative internal data for the scene.
121 
122  /// @internal
123  /// @brief Can be used for thread safe logging and other thread specific resources.
125  public:
126  /// @brief Class Constructor.
127  /// @details Standard class initialization constructor.
128  /// @param InternalManagerTypeName The name of the scenemanager type to be constructed.
129  SceneManager(const String& InternalManagerTypeName = "DefaultSceneManager");
130  /// @brief XML constructor.
131  /// @param XMLNode The node of the xml document to construct from.
132  SceneManager(XML::Node& XMLNode);
133  /// @brief Class Destructor.
134  /// @details The class destructor.
135  virtual ~SceneManager();
136 
137  ///////////////////////////////////////////////////////////////////////////////
138  // Shadow Management
139 
140  /// @brief Sets the type of shadows to be used when rendering the scene.
141  /// @details The scene manager defaults to no shadows.
142  /// @param Shadows The technique to be applied, see SceneShadowTechnique enum for more info.
143  void SetSceneShadowTechnique(SceneShadowTechnique Shadows);
144  /// @brief Gets the currently set shadow technique.
145  /// @return Returns a SceneShadowTechnique enum value representing the currently set shadow technique.
146  SceneShadowTechnique GetSceneShadowTechnique() const;
147  /// @brief Sets the number of textures to be alloted for creating shadows.
148  /// @details Defaults to 1.
149  /// @param Count The amount of textures to be used for creating texture-based shadows.
150  void SetShadowTextureCount(const Whole& Count);
151  /// @brief Gets the currently set number of textures being used to make texture shadows.
152  /// @return Returns a Whole indicating the number of textures used to make texture shadows.
153  Whole GetShadowTextureCount() const;
154  /// @brief Sets the size of all texture based shadows.
155  /// @details This defaults to 512. Sizes must be a power of 2.
156  /// @param Size The size of all textures to be used with shadows, in KB(?).
157  void SetShadowTextureSize(unsigned short Size);
158  /// @brief Retrieve the size of textures.
159  /// @return An unsigned short which is the size of the textures.
160  unsigned short GetShadowTextureSize() const;
161  /// @brief Sets the maximum distance from the camera that shadows will be visible.
162  /// @param FarDist The maximum distance from the camera shadows will be rendered.
163  void SetShadowFarDistance(const Real& FarDist);
164  /// @brief Gets the maximum distance from the camera that shadows will be visible.
165  /// @return Returns a Real representing the maximum distance from the camera shadows will be rendered.
166  Real GetShadowFarDistance() const;
167  /// @brief Sets the colour to be used when casting shadows.
168  /// @param ShadowColour The colour desired to be used when rendering shadows.
169  void SetShadowColour(const ColourValue& ShadowColour);
170  /// @brief Gets the colour being used when casting shadows.
171  /// @return Returns a ColourValue representing the colour used when casting shadows.
172  ColourValue GetShadowColour() const;
173 
174  ///////////////////////////////////////////////////////////////////////////////
175  // Sky Surface Management
176 
177  /// @brief Creates a skyplane for use in making a sky.
178  /// @details Only one skyplane can exist in a scene. Making a new one will remove the old one. Skyplanes are
179  /// flat planes that face in one direction. They are ideal for levels with surrounding mountains or anything
180  /// where the horizon is not visable.
181  /// @param SkyPlane The plane that will become the sky.
182  /// @param Material The name of the material to be applied to the skyplane. Note: This is not referring to the
183  /// filename, but the specific material script within the file.
184  /// @param Group The resource group where the material can be found.
185  /// @param Scale The scaling to be applied to the skyplane. This may need to be tweaked based on how high you
186  /// set the plane off the ground.
187  /// @param Tiling The number of times to tile the texture or textures listed in the material script across the skyplane.
188  /// @param DrawFirst Whether or not the skyplane should be the first thing rendered in the scene. Usually you will
189  /// want this to be true as it'll ensure all other objects are rendered on top of it.
190  /// @param Bow This will add curvature to the skyplane if set above zero. Note: Use small numbers. A bow of 1.5
191  /// should be noticable.
192  /// @param XSegments The number of segments, or boxes, the skyplane consists of on the planes X axis. This is usful
193  /// when giving the skyplane a bow. By default the skyplane is just one massive box.
194  /// @param YSegments The number of segments, or boxes, the skyplane consists of on the planes Y axis. This is usful
195  /// when giving the skyplane a bow. By default the skyplane is just one massive box.
196  void CreateSkyPlane(const Plane& SkyPlane_, const String& Material, const String& Group, Real Scale=1000.0, Real Tiling=10.0,
197  bool DrawFirst=true, Real Bow=0, int XSegments=1, int YSegments=1);
198  /// @brief Disables the currently active skyplane.
199  /// @details Using this function effectively deletes the skyplane, so you will have to provide a new set of parameters
200  /// if you wish to re-create the skyplane.
201  void DisableSkyPlane();
202 
203  /// @brief Creates a skybox for use in making a sky.
204  /// @details Like skyplanes, only one can exist per scene. Unlike skyplanes, skyboxes will be applied individually to
205  /// each camera in the scene. The skybox will move with the camera, so as a result the camera will never be able to
206  /// "touch" the sky. Skyboxes are more performance intensive then skyplanes.
207  /// @param Material The name of the material to be applied to the skybox. Note: This is not referring to the
208  /// filename, but the specific material script within the file.
209  /// @param Group The resource group where the material can be found.
210  /// @param Distance The distance from the camera where the skybox is found. This is in world units.
211  /// @param DrawFirst Whether or not the skybox should be the first thing rendered in the scene. Usually you will
212  /// want this to be true as it'll ensure all other objects are rendered on top of it.
213  /// @param Orientation Optional quaternion to rotate the orientation of the skybox.
214  void CreateSkyBox(const String& Material, const String& Group, Real Distance, bool DrawFirst=true, Quaternion Orientation=Quaternion());
215  /// @brief Disables the currently active skybox.
216  /// @details Using this function effectively deletes the skybox, so you will have to provide a new set of parameters
217  /// if you wish to re-create the skybox.
218  void DisableSkyBox();
219 
220  /// @brief Creates a skydome for use in making a sky.
221  /// @details Like the other two types of sky's, their can be only one skydome per scene. Skydomes much like skyboxes, except
222  /// they have 5 sides(the bottom side is missing), and they bow each of the sides to make the dome. In all other respects they
223  /// are the same.
224  /// @param Material The name of the material to be applied to the skydome. Note: This is not referring to the
225  /// filename, but the specific material script within the file.
226  /// @param Group The resource group where the material can be found.
227  /// @param Distance The distance from the camera where the skydome is found. This is in world units.
228  /// @param Curvature Curvature of the dome. Usually you want this value to be between 2 and 65.
229  /// @param Tiling The number of times to tile the texture or textures listed in the material script across the skydome.
230  /// @param DrawFirst Whether or not the skybox should be the first thing rendered in the scene. Usually you will
231  /// want this to be true as it'll ensure all other objects are rendered on top of it.
232  /// @param Orientation Optional quaternion to rotate the orientation of the skydome.
233  /// @param XSegments The number of segments, or boxes, the skydome consists of on the dome's X axis.
234  /// @param YSegments The number of segments, or boxes, the skydome consists of on the dome's Y axis.
235  void CreateSkyDome(const String& Material, const String& Group, Real Distance, Real Curvature=10.0, Real Tiling=8.0, bool DrawFirst=true,
236  Quaternion Orientation=Quaternion(), int XSegments=16, int YSegments=16);
237  /// @brief Disables the currently active skydome.
238  /// @details Using this function effectively deletes the skydome, so you will have to provide a new set of parameters
239  /// if you wish to re-create the skydome.
240  void DisableSkyDome();
241 
242  /// @brief If any sky is active, disable it
243  void DisableSky();
244 
245  /// @brief get the kind of sy in use
246  /// @return The kind of sky in use
247  SkyMethod WhichSky() const;
248 
249  ///////////////////////////////////////////////////////////////////////////////
250  // Creating Proxies
251 
252  /// @brief Creates a new BillboardSetProxy.
253  /// @param InitialPoolSize The number of billboards to reserve space for.
254  /// @return Returns a pointer to the created proxy.
255  BillboardSetProxy* CreateBillboardSetProxy(const UInt32 InitialPoolSize = 20);
256  /// @brief Creates a new BillboardSetProxy.
257  /// @param SelfRoot An XML::Node containing the data to populate this class with.
258  /// @return Returns a pointer to the created proxy.
259  BillboardSetProxy* CreateBillboardSetProxy(const XML::Node& SelfRoot);
260  /// @brief Creates a new EntityProxy.
261  /// @return Returns a pointer to the created proxy.
262  EntityProxy* CreateEntityProxy();
263  /// @brief Creates a new EntityProxy.
264  /// @param TheMesh A pointer to the mesh to be applied to this proxy.
265  /// @return Returns a pointer to the created proxy.
266  EntityProxy* CreateEntityProxy(Mesh* TheMesh);
267  /// @brief Creates a new EntityProxy.
268  /// @param MeshName The name of the mesh to be loaded and applied to this proxy.
269  /// @param GroupName The resource group name where the mesh can be found.
270  /// @return Returns a pointer to the created proxy.
271  EntityProxy* CreateEntityProxy(const String& MeshName, const String& GroupName);
272  /// @brief Creates a new EntityProxy.
273  /// @param SelfRoot An XML::Node containing the data to populate this class with.
274  /// @return Returns a pointer to the created proxy.
275  EntityProxy* CreateEntityProxy(const XML::Node& SelfRoot);
276  /// @brief Creates a new LightProxy.
277  /// @return Returns a pointer to the created proxy.
278  LightProxy* CreateLightProxy();
279  /// @brief Creates a new LightProxy.
280  /// @param Type The type of light this light is to be constructed as.
281  /// @return Returns a pointer to the created proxy.
282  LightProxy* CreateLightProxy(const Graphics::LightType Type);
283  /// @brief Creates a new LightProxy.
284  /// @param SelfRoot An XML::Node containing the data to populate this class with.
285  /// @return Returns a pointer to the created proxy.
286  LightProxy* CreateLightProxy(const XML::Node& SelfRoot);
287  /// @brief Creates a new ParticleSystemProxy.
288  /// @param Template Name of the particle script to be used in creating this particle effect.
289  /// @return Returns a pointer to the created proxy.
290  ParticleSystemProxy* CreateParticleSystemProxy(const String& Template);
291  /// @brief Creates a new ParticleSystemProxy.
292  /// @param SelfRoot An XML::Node containing the data to populate this class with.
293  /// @return Returns a pointer to the created proxy.
294  ParticleSystemProxy* CreateParticleSystemProxy(const XML::Node& SelfRoot);
295 
296  ///////////////////////////////////////////////////////////////////////////////
297  // Proxy Management
298 
299  /// @brief Gets a RenderableProxy instance by index.
300  /// @param Index The index of the RenderableProxy to be retrieved.
301  /// @return Returns a pointer to the RenderableProxy at the specified index.
302  RenderableProxy* GetProxy(const UInt32 Index) const;
303  /// @brief Gets the number of RenderableProxy instances in this manager.
304  /// @return Returns a UInt32 representing the number of RenderableProxy instances contained in this manager.
305  UInt32 GetNumProxies() const;
306  /// @brief Deletes a RenderableProxy.
307  /// @param ToBeDestroyed A pointer to the RenderableProxy you want deleted.
308  void DestroyProxy(RenderableProxy* ToBeDestroyed);
309  /// @brief Deletes all stored RenderableProxy instances.
310  void DestroyAllProxies();
311 
312  ///////////////////////////////////////////////////////////////////////////////
313  // Light Management
314 
315  /// @brief Sets the ambient light for the scene.
316  /// @details Not all scene's will need ambient light. Ambient light is light that hits all objects from
317  /// all directions.
318  /// @param Red The value representing the amount of red color in the ambient light.
319  /// @param Green The value representing the amount of green color in the ambient light.
320  /// @param Blue The value representing the amount of blue color in the ambient light.
321  /// @param Alpha The value representing the transparency of the color in the ambient light.
322  void SetAmbientLight(Real Red=1.0, Real Green=1.0, Real Blue=1.0, Real Alpha=1.0);
323  /// @brief Sets the ambient light for the scene, in a single value.
324  /// @param Red The value representing the amount of red color in the ambient light.
325  void SetAmbientLight(const ColourValue &LightColor);
326  /// @brief Retrieve the level of the ambient light
327  /// @return A ColourValue with the ambient light levels
328  ColourValue GetAmbientLight() const;
329 
330  ///////////////////////////////////////////////////////////////////////////////
331  // Utility
332 
333  /// @brief Gets the name of this manager.
334  /// @return Returns the name of this manager.
335  ConstString& GetName() const;
336 
337  /// @brief Pauses(or unpauses) all particles stored in this manager.
338  /// @param Pause Will pause all Particles if true, unpause if false.
339  void PauseAllParticles(bool Pause);
340 
341  /// @copydoc WorldManager::Pause(const UInt32)
342  virtual void Pause(const UInt32 PL);
343 
344  /// @copydoc WorldManager::Initialize()
345  virtual void Initialize();
346  /// @copydoc ManagerBase::Deinitialize()
347  virtual void Deinitialize();
348 
349  ///////////////////////////////////////////////////////////////////////////////
350  // Type Identifier Methods
351 
352  /// @copydoc ManagerBase::GetInterfaceType()
353  virtual ManagerType GetInterfaceType() const;
354  /// @copydoc ManagerBase::GetImplementationTypeName()
355  virtual String GetImplementationTypeName() const;
356 
357  ///////////////////////////////////////////////////////////////////////////////
358  // Internal/Other
359 
360  /// @internal
361  /// @brief Gets the internal Ogre Scene Manager pointer.
362  /// @return Returns a pointer to the ogre Scene Manager.
363  Ogre::SceneManager* _GetGraphicsWorldPointer() const;
364  /// @internal
365  /// @brief Gets the raw internal internal data.
366  /// @return Returns a to the raw internal data.
367  SceneManagerData* _GetRawInternalDataPointer() const;
368  };//SceneManager
369 
370  ///////////////////////////////////////////////////////////////////////////////
371  /// @class DefaultSceneManagerFactory
372  /// @headerfile scenemanager.h
373  /// @brief A factory responsible for the creation and destruction of the default scenemanager.
374  ///////////////////////////////////////
376  {
377  public:
378  /// @brief Class constructor.
380  /// @brief Class destructor.
381  virtual ~DefaultSceneManagerFactory();
382 
383  /// @copydoc ManagerFactory::GetManagerTypeName()
384  String GetManagerTypeName() const;
385 
386  /// @copydoc ManagerFactory::CreateManager(NameValuePairList&)
387  ManagerBase* CreateManager(NameValuePairList& Params);
388  /// @copydoc ManagerFactory::CreateManager(XML::Node&)
389  ManagerBase* CreateManager(XML::Node& XMLNode);
390  /// @copydoc ManagerFactory::DestroyManager(ManagerBase*)
391  void DestroyManager(ManagerBase* ToBeDestroyed);
392  };//DefaultSceneManagerFactory
393  }//Graphics
394 }//Mezzanine
395 
396 ///////////////////////////////////////////////////////////////////////////////
397 // Class External << Operators for streaming or assignment
398 /// @brief Serializes the passed Mezzanine::Graphics::SceneManager to XML
399 /// @param stream The ostream to send the xml to.
400 /// @param Ev the Mezzanine::Graphics::SceneManager to be serialized
401 /// @return this returns the ostream, now with the serialized data
402 std::ostream& MEZZ_LIB operator << (std::ostream& stream, const Mezzanine::Graphics::SceneManager& Ev);
403 
404 /// @brief Deserialize a Mezzanine::Graphics::SceneManager
405 /// @param stream The istream to get the xml from to (re)make the Mezzanine::Graphics::SceneManager.
406 /// @param Ev the Mezzanine::Graphics::SceneManager to be deserialized.
407 /// @return this returns the ostream, advanced past the Mezzanine::Graphics::SceneManager that was recreated onto Ev.
408 std::istream& MEZZ_LIB operator >> (std::istream& stream, Mezzanine::Graphics::SceneManager& Ev);
409 
410 /// @brief Set all values of a Mezzanine::Graphics::SceneManager from parsed xml.
411 /// @param OneNode The istream to get the xml from to (re)make the Mezzanine::Graphics::SceneManager.
412 /// @param Ev the Mezzanine::Graphics::SceneManager to be reset.
413 /// @return This returns the XML::Node that was passed in.
415 
416 
417 #endif