MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
meshmanager.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 _graphicsmeshmanager_h
41 #define _graphicsmeshmanager_h
42 
43 #include "vector3.h"
44 #include "colourvalue.h"
45 #include "managerbase.h"
46 #include "managerfactory.h"
47 #include "singleton.h"
48 
49 namespace Mezzanine
50 {
51  namespace Physics
52  {
53  class CollisionShape;
54  }
55  namespace Graphics
56  {
57  class Mesh;
58  // Used by the scripting language binder to help create bindgings for this class. SWIG does know to creation template instances
59  #ifdef SWIG
60  %template(SingletonMeshManager) Singleton<MeshManager>;
61  #endif
62 
63  ///////////////////////////////////////////////////////////////////////////////
64  /// @class MeshManager
65  /// @headerfile meshmanager.h
66  /// @brief This manager handles the storage, generation, and query of of Graphics Meshes.
67  /// @details
68  ///////////////////////////////////////
70  {
71  public:
72  typedef std::map< String, Mesh* > MeshContainer;
73  typedef MeshContainer::iterator MeshIterator;
74  typedef MeshContainer::const_iterator ConstMeshIterator;
75  protected:
76  MeshContainer GeneratedMeshes;
77  MeshContainer LoadedMeshes;
78  public:
79  /// @brief Class constructor.
80  MeshManager();
81  /// @brief XML constructor.
82  /// @param XMLNode The node of the xml document to construct from.
83  MeshManager(XML::Node& XMLNode);
84  /// @brief Class destructor.
85  virtual ~MeshManager();
86 
87  ///////////////////////////////////////////////////////////////////////////////
88  // Generic Mesh Utility
89 
90  /// @brief Gets a mesh stored in this manager.
91  /// @return Returns a pointer to the requested mesh.
92  /// @param MeshName The name of the mesh to retrieve.
93  Mesh* GetMesh(const String& MeshName);
94  /// @brief Clears this manager of all meshes, both loaded and generated.
95  void DestroyAllMeshes();
96 
97  ///////////////////////////////////////////////////////////////////////////////
98  // Non-Generated Mesh Management
99 
100  /// @brief Loads a mesh file from disk and prepares it for use.
101  /// @return Returns a pointer to the loaded mesh.
102  /// @param MeshName The name of the mesh file to be loaded.
103  /// @param Group The resource group from which the mesh file should be loaded.
104  virtual Mesh* LoadMesh(const String& MeshName, const String& Group);
105  /// @brief Unloads a mesh file.
106  /// @param MeshName The name of the mesh to be unloaded.
107  virtual void UnloadMesh(const String& MeshName);
108  /// @brief Gets the number of currently loaded mesh files.
109  /// @return Returns a whole representing the number of mesh files currently loaded.
110  virtual Whole GetNumLoadedMeshes();
111  /// @brief Unloads every mesh that is currently loaded.
112  virtual void UnloadAllLoadedMeshes();
113 
114  ///////////////////////////////////////////////////////////////////////////////
115  // Generated Mesh Management
116 
117  /// @brief Gets the number of meshes this generator has created and are in use.
118  /// @return Returns a Whole representing the number of meshes created by this generator.
119  virtual Whole GetNumGeneratedMeshes();
120  /// @brief Destroys a named Mesh, freeing it's resources.
121  /// @param MeshName The name of the mesh to be destroyed.
122  virtual void DestroyGeneratedMesh(const String& MeshName);
123  /// @brief Destroys all the meshes generated by this generator.
124  virtual void DestroyAllGeneratedMeshes();
125 
126  ///////////////////////////////////////////////////////////////////////////////
127  // Mesh Generation
128 
129  /// @brief Creates a box graphical mesh.
130  /// @return Returns a pointer to the created Mesh.
131  /// @param MeshName The name for the mesh which will be created. Use this to reference the mesh when creating other objects that need a mesh.
132  /// @param MaterialName The name of the material script which will be applied to this mesh.
133  /// @param HalfExtents Half of the full dimentions of the final object in world units. This allows the objects origin to be it's center.
134  virtual Mesh* CreateBoxMesh(const String& MeshName, const String& MaterialName, const Vector3& HalfExtents);
135  /// @brief Creates a box graphical mesh.
136  /// @return Returns a pointer to the created Mesh.
137  /// @param MeshName The name for the mesh which will be created. Use this to reference the mesh when creating other objects that need a mesh.
138  /// @param Colour The colour to generate the material with that will be applied to the mesh. The created material's name will be autogenerated to "[Meshname]+Mat".
139  /// @param HalfExtents Half of the full dimentions of the final object in world units. This allows the objects origin to be it's center.
140  virtual Mesh* CreateBoxMesh(const String& MeshName, const ColourValue& Colour, const Vector3& HalfExtents);
141  /// @brief Creates a cylinder graphical mesh.
142  /// @return Returns a pointer to the created Mesh.
143  /// @param MeshName The name for the mesh which will be created. Use this to reference the mesh when creating other objects that need a mesh.
144  /// @param MaterialName The name of the material script which will be applied to this mesh.
145  /// @param HalfExtents Half of the full dimentions of the final object in world units. This allows the objects origin to be it's center.
146  /// @param AxisOrientation Vector3 representing which axis the cylinder should be aligned on. Should be one of the three: (1,0,0), (0,1,0), (0,0,1).
147  /// @param CircleRes The number of segments the circle should be comprised of. Determines the "resolution" of the cylinder.
148  /// @param Segments Optional parameter to specify the number of segments the cylinder should be comprised of. Mostly just useful if a special material is made for his.
149  virtual Mesh* CreateCylinderMesh(const String& MeshName, const String& MaterialName, const Vector3& HalfExtents, const Vector3& AxisOrientation, const Whole& CircleRes = 16, const Whole& Segments = 1);
150  /// @brief Creates a cylinder graphical mesh and simple material.
151  /// @return Returns a pointer to the created Mesh.
152  /// @param MeshName The name for the mesh which will be created. Use this to reference the mesh when creating other objects that need a mesh.
153  /// @param Colour The colour to generate the material with that will be applied to the mesh. The created material's name will be autogenerated to "[Meshname]+Mat".
154  /// @param HalfExtents Half of the full dimentions of the final object in world units. This allows the objects origin to be it's center.
155  /// @param AxisOrientation Vector3 representing which axis the cylinder should be aligned on. Should be one of the three: (1,0,0), (0,1,0), (0,0,1).
156  /// @param CircleRes The number of segments the circle should be comprised of. Determines the "resolution" of the cylinder.
157  /// @param Segments Optional parameter to specify the number of segments the cylinder should be comprised of. Mostly just useful if a special material is made for his.
158  virtual Mesh* CreateCylinderMesh(const String& MeshName, const ColourValue& Colour, const Vector3& HalfExtents, const Vector3& AxisOrientation, const Whole& CircleRes = 16, const Whole& Segments = 1);
159  /// @brief Creates a sphere graphical mesh.
160  /// @return Returns a pointer to the created Mesh.
161  /// @param MeshName The name for the mesh which will be created. Use this to reference the mesh when creating other objects that need a mesh.
162  /// @param MaterialName The name of the material script which will be applied to this mesh.
163  /// @param Radius The radius to generate the sphere with in world units.
164  /// @param Rings The number of horizontal rings the sphere is to be comprised of.
165  /// This along with the segments parameter controls the overall resolution of the sphere. Less then 16 is not recommended.
166  /// @param Segments The number of vertical rings the sphere is to be comprised of.
167  /// This along with the rings parameter controls the overall resolution of the sphere. Less then 16 is not recommended.
168  virtual Mesh* CreateSphereMesh(const String& MeshName, const String& MaterialName, const Real& Radius, const Real& Rings = 16, const Real& Segments = 16);
169  /// @brief Creates a sphere graphical mesh and simple material.
170  /// @return Returns a pointer to the created Mesh.
171  /// @param MeshName The name for the mesh which will be created. Use this to reference the mesh when creating other objects that need a mesh.
172  /// @param Colour The colour to generate the material with that will be applied to the mesh. The created material's name will be autogenerated to "[Meshname]+Mat".
173  /// @param Radius The radius to generate the sphere with in world units.
174  /// @param Rings The number of horizontal rings the sphere is to be comprised of.
175  /// This along with the segments parameter controls the overall resolution of the sphere. Less then 16 is not recommended.
176  /// @param Segments The number of vertical rings the sphere is to be comprised of.
177  /// This along with the rings parameter controls the overall resolution of the sphere. Less then 16 is not recommended.
178  virtual Mesh* CreateSphereMesh(const String& MeshName, const ColourValue& Colour, const Real& Radius, const Real& Rings = 16, const Real& Segments = 16);
179  /// @brief Creates a mesh composed of boxes that outline the corner edges of a larger box.
180  /// @return Returns a pointer to the created Mesh.
181  /// @param MeshName The name for the mesh which will be created. Use this to reference the mesh when creating other objects that need a mesh.
182  /// @param MaterialName The name of the material script which will be applied to this mesh.
183  /// @param HalfExtents Half of the full dimentions of the final object in world units. This allows the objects origin to be it's center.
184  /// @param BoxThickness The width/thickness of the smaller boxes that will outline the corners of the larger box.
185  virtual Mesh* CreateBoxCornerMesh(const String& MeshName, const String& MaterialName, const Vector3& HalfExtents, const Real& BoxThickness);
186  /// @brief Creates a mesh composed of boxes that outline the corner edges of a larger box.
187  /// @return Returns a pointer to the created Mesh.
188  /// @param MeshName The name for the mesh which will be created. Use this to reference the mesh when creating other objects that need a mesh.
189  /// @param Colour The colour to generate the material with that will be applied to the mesh. The created material's name will be autogenerated to "[Meshname]+Mat".
190  /// @param HalfExtents Half of the full dimentions of the final object in world units. This allows the objects origin to be it's center.
191  /// @param BoxThickness The width/thickness of the smaller boxes that will outline the corners of the larger box.
192  virtual Mesh* CreateBoxCornerMesh(const String& MeshName, const ColourValue& Colour, const Vector3& HalfExtents, const Real& BoxThickness);
193 
194  /// @brief Generates a mesh based on a collision shape.
195  /// @remarks This is just a convenience function. You can fetch the information and build the mesh yourself with greater flexability then what
196  /// this function has to offer. This function only supports building the shapes this manager can generate, and it will only use default options
197  /// when deciding the parameters to use(if it's a parameter it can't get from the shape).
198  /// @return Returns a pointer to the created mesh.
199  /// @param MeshName The name that will be given to the generated mesh.
200  /// @param MaterialName The name of the material to use with this mesh.
201  /// @param Shape The shape to base the mesh on.
202  virtual Mesh* CreateMeshFromShape(const String& MeshName, const String& MaterialName, Physics::CollisionShape* Shape);
203 
204  ///////////////////////////////////////////////////////////////////////////////
205  // Material Utilities - Until we can get a Material Manager
206 
207  /// @brief Creates a basic material in code using the provided colour.
208  /// @return Returns a string containing the name of the created Material.
209  /// This is actually the same string as whats passed in as the MatName,
210  /// just here as convenience when calling the function as an argument in other functions.
211  /// @param MatName The name to assign to the created material.
212  /// @param Colour The colour to assign to the created material.
213  /// @param Group The resource group where to place this material. Will be placed in an internal resouce group if left blank.
214  virtual const String& CreateColouredMaterial(const String& MatName, const ColourValue& Colour, const String& Group = "");
215 
216  ///////////////////////////////////////////////////////////////////////////////
217  // Utility
218 
219  /// @copydoc ManagerBase::Initialize()
220  virtual void Initialize();
221  /// @copydoc ManagerBase::Deinitialize()
222  virtual void Deinitialize();
223 
224  ///////////////////////////////////////////////////////////////////////////////
225  // Type Identifier Methods
226 
227  /// @copydoc ManagerBase::GetInterfaceType()
228  virtual ManagerType GetInterfaceType() const;
229  /// @copydoc ManagerBase::GetImplementationTypeName()
230  virtual String GetImplementationTypeName() const;
231  };//MeshManager
232 
233  ///////////////////////////////////////////////////////////////////////////////
234  /// @class DefaultMeshManagerFactory
235  /// @headerfile meshmanager.h
236  /// @brief A factory responsible for the creation and destruction of the default meshmanager.
237  ///////////////////////////////////////
239  {
240  public:
241  /// @brief Class constructor.
243  /// @brief Class destructor.
244  virtual ~DefaultMeshManagerFactory();
245 
246  /// @copydoc ManagerFactory::GetManagerTypeName()
247  String GetManagerTypeName() const;
248 
249  /// @copydoc ManagerFactory::CreateManager(NameValuePairList&)
250  ManagerBase* CreateManager(NameValuePairList& Params);
251  /// @copydoc ManagerFactory::CreateManager(XML::Node&)
252  ManagerBase* CreateManager(XML::Node& XMLNode);
253  /// @copydoc ManagerFactory::DestroyManager(ManagerBase*)
254  void DestroyManager(ManagerBase* ToBeDestroyed);
255  };//DefaultMeshManagerFactory
256  }//Graphics
257 }//Mezzanine
258 
259 #endif