1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #ifndef __MeshManager_H__
|
---|
26 | #define __MeshManager_H__
|
---|
27 |
|
---|
28 | #include "OgrePrerequisites.h"
|
---|
29 |
|
---|
30 | #include "OgreResourceManager.h"
|
---|
31 | #include "OgreSingleton.h"
|
---|
32 | #include "OgreVector3.h"
|
---|
33 | #include "OgreHardwareBuffer.h"
|
---|
34 | #include "OgreMesh.h"
|
---|
35 | #include "OgrePatchMesh.h"
|
---|
36 |
|
---|
37 | namespace Ogre {
|
---|
38 |
|
---|
39 | /** Handles the management of mesh resources.
|
---|
40 | @remarks
|
---|
41 | This class deals with the runtime management of
|
---|
42 | mesh data; like other resource managers it handles
|
---|
43 | the creation of resources (in this case mesh data),
|
---|
44 | working within a fixed memory budget.
|
---|
45 | */
|
---|
46 | class _OgreExport MeshManager: public ResourceManager, public Singleton<MeshManager>,
|
---|
47 | public ManualResourceLoader
|
---|
48 | {
|
---|
49 | public:
|
---|
50 | MeshManager();
|
---|
51 | ~MeshManager();
|
---|
52 |
|
---|
53 | /** Initialises the manager, only to be called by OGRE internally. */
|
---|
54 | void _initialise(void);
|
---|
55 |
|
---|
56 | /** Loads a mesh from a file, making it immediately available for use.
|
---|
57 | @note
|
---|
58 | If the model has already been loaded, the existing instance
|
---|
59 | will be returned.
|
---|
60 | @remarks
|
---|
61 | Ogre loads model files from it's own proprietary
|
---|
62 | format called .mesh. This is because having a single file
|
---|
63 | format is better for runtime performance, and we also have
|
---|
64 | control over pre-processed data (such as
|
---|
65 | collision boxes, LOD reductions etc).
|
---|
66 | @param filename The name of the .mesh file
|
---|
67 | @param groupName The name of the resource group to assign the mesh to
|
---|
68 | @param vertexBufferUsage The usage flags with which the vertex buffer(s)
|
---|
69 | will be created
|
---|
70 | @param indexBufferUsage The usage flags with which the index buffer(s) created for
|
---|
71 | this mesh will be created with.
|
---|
72 | @param vertexBufferShadowed If true, the vertex buffers will be shadowed by system memory
|
---|
73 | copies for faster read access
|
---|
74 | @param indexBufferShadowed If true, the index buffers will be shadowed by system memory
|
---|
75 | copies for faster read access
|
---|
76 | @param priority The priority of this mesh in the resource system
|
---|
77 | */
|
---|
78 | MeshPtr load( const String& filename, const String& groupName,
|
---|
79 | HardwareBuffer::Usage vertexBufferUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY,
|
---|
80 | HardwareBuffer::Usage indexBufferUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY,
|
---|
81 | bool vertexBufferShadowed = true, bool indexBufferShadowed = true);
|
---|
82 |
|
---|
83 |
|
---|
84 | /** Creates a new Mesh specifically for manual definition rather
|
---|
85 | than loading from an object file.
|
---|
86 | @remarks
|
---|
87 | Note that once you've defined your mesh, you must call Mesh::_setBounds and
|
---|
88 | Mesh::_setBoundingRadius in order to define the bounds of your mesh. In previous
|
---|
89 | versions of OGRE you could call Mesh::_updateBounds, but OGRE's support of
|
---|
90 | write-only vertex buffers makes this no longer appropriate.
|
---|
91 | @param name The name to give the new mesh
|
---|
92 | @param groupName The name of the resource group to assign the mesh to
|
---|
93 | @param loader ManualResourceLoader which will be called to load this mesh
|
---|
94 | when the time comes. It is recommended that you populate this field
|
---|
95 | in order that the mesh can be rebuilt should the need arise
|
---|
96 | */
|
---|
97 | MeshPtr createManual( const String& name, const String& groupName,
|
---|
98 | ManualResourceLoader* loader = 0);
|
---|
99 |
|
---|
100 | /** Creates a basic plane, by default majoring on the x/y axes facing positive Z.
|
---|
101 | @param
|
---|
102 | name The name to give the resulting mesh
|
---|
103 | @param
|
---|
104 | groupName The name of the resource group to assign the mesh to
|
---|
105 | @param
|
---|
106 | plane The orientation of the plane and distance from the origin
|
---|
107 | @param
|
---|
108 | width The width of the plane in world coordinates
|
---|
109 | @param
|
---|
110 | height The height of the plane in world coordinates
|
---|
111 | @param
|
---|
112 | xsegments The number of segements to the plane in the x direction
|
---|
113 | @param
|
---|
114 | ysegments The number of segements to the plane in the y direction
|
---|
115 | @param
|
---|
116 | normals If true, normals are created perpendicular to the plane
|
---|
117 | @param
|
---|
118 | numTexCoordSets The number of 2D texture coordinate sets created - by default the corners
|
---|
119 | are created to be the corner of the texture.
|
---|
120 | @param
|
---|
121 | uTile The number of times the texture should be repeated in the u direction
|
---|
122 | @param
|
---|
123 | vTile The number of times the texture should be repeated in the v direction
|
---|
124 | @param
|
---|
125 | upVector The 'Up' direction of the plane.
|
---|
126 | @param
|
---|
127 | vertexBufferUsage The usage flag with which the vertex buffer for this plane will be created
|
---|
128 | @param
|
---|
129 | indexBufferUsage The usage flag with which the index buffer for this plane will be created
|
---|
130 | @param
|
---|
131 | vertexShadowBuffer If this flag is set to true, the vertex buffer will be created
|
---|
132 | with a system memory shadow buffer,
|
---|
133 | allowing you to read it back more efficiently than if it is in hardware
|
---|
134 | @param
|
---|
135 | indexShadowBuffer If this flag is set to true, the index buffer will be
|
---|
136 | created with a system memory shadow buffer,
|
---|
137 | allowing you to read it back more efficiently than if it is in hardware
|
---|
138 | */
|
---|
139 | MeshPtr createPlane(
|
---|
140 | const String& name, const String& groupName, const Plane& plane,
|
---|
141 | Real width, Real height,
|
---|
142 | int xsegments = 1, int ysegments = 1,
|
---|
143 | bool normals = true, int numTexCoordSets = 1,
|
---|
144 | Real uTile = 1.0f, Real vTile = 1.0f, const Vector3& upVector = Vector3::UNIT_Y,
|
---|
145 | HardwareBuffer::Usage vertexBufferUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY,
|
---|
146 | HardwareBuffer::Usage indexBufferUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY,
|
---|
147 | bool vertexShadowBuffer = true, bool indexShadowBuffer = true);
|
---|
148 |
|
---|
149 |
|
---|
150 | /** Creates a plane, which because of it's texture coordinates looks like a curved
|
---|
151 | surface, useful for skies in a skybox.
|
---|
152 | @param
|
---|
153 | name The name to give the resulting mesh
|
---|
154 | @param
|
---|
155 | groupName The name of the resource group to assign the mesh to
|
---|
156 | @param
|
---|
157 | plane The orientation of the plane and distance from the origin
|
---|
158 | @param
|
---|
159 | width The width of the plane in world coordinates
|
---|
160 | @param
|
---|
161 | height The height of the plane in world coordinates
|
---|
162 | @param
|
---|
163 | curvature The curvature of the plane. Good values are
|
---|
164 | between 2 and 65. Higher values are more curved leading to
|
---|
165 | a smoother effect, lower values are less curved meaning
|
---|
166 | more distortion at the horizons but a better distance effect.
|
---|
167 | @param
|
---|
168 | xsegments The number of segements to the plane in the x direction
|
---|
169 | @param
|
---|
170 | ysegments The number of segements to the plane in the y direction
|
---|
171 | @param
|
---|
172 | normals If true, normals are created perpendicular to the plane
|
---|
173 | @param
|
---|
174 | numTexCoordSets The number of 2D texture coordinate sets created - by default the corners
|
---|
175 | are created to be the corner of the texture.
|
---|
176 | @param
|
---|
177 | uTile The number of times the texture should be repeated in the u direction
|
---|
178 | @param
|
---|
179 | vTile The number of times the texture should be repeated in the v direction
|
---|
180 | @param
|
---|
181 | upVector The 'Up' direction of the plane.
|
---|
182 | @param
|
---|
183 | orientation The orientation of the overall sphere that's used to create the illusion
|
---|
184 | @param
|
---|
185 | vertexBufferUsage The usage flag with which the vertex buffer for this plane will be created
|
---|
186 | @param
|
---|
187 | indexBufferUsage The usage flag with which the index buffer for this plane will be created
|
---|
188 | @param
|
---|
189 | vertexShadowBuffer If this flag is set to true, the vertex buffer will be created
|
---|
190 | with a system memory shadow buffer,
|
---|
191 | allowing you to read it back more efficiently than if it is in hardware
|
---|
192 | @param
|
---|
193 | indexShadowBuffer If this flag is set to true, the index buffer will be
|
---|
194 | created with a system memory shadow buffer,
|
---|
195 | allowing you to read it back more efficiently than if it is in hardware
|
---|
196 | @param ySegmentsToKeep The number of segments from the top of the dome
|
---|
197 | downwards to keep. -1 keeps all of them. This can save fillrate if
|
---|
198 | you cannot see much of the sky lower down.
|
---|
199 | */
|
---|
200 | MeshPtr createCurvedIllusionPlane(
|
---|
201 | const String& name, const String& groupName, const Plane& plane,
|
---|
202 | Real width, Real height, Real curvature,
|
---|
203 | int xsegments = 1, int ysegments = 1,
|
---|
204 | bool normals = true, int numTexCoordSets = 1,
|
---|
205 | Real uTile = 1.0f, Real vTile = 1.0f, const Vector3& upVector = Vector3::UNIT_Y,
|
---|
206 | const Quaternion& orientation = Quaternion::IDENTITY,
|
---|
207 | HardwareBuffer::Usage vertexBufferUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY,
|
---|
208 | HardwareBuffer::Usage indexBufferUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY,
|
---|
209 | bool vertexShadowBuffer = true, bool indexShadowBuffer = true,
|
---|
210 | int ySegmentsToKeep = -1);
|
---|
211 |
|
---|
212 | /** Creates a genuinely curved plane, by default majoring on the x/y axes facing positive Z.
|
---|
213 | @param
|
---|
214 | name The name to give the resulting mesh
|
---|
215 | @param
|
---|
216 | groupName The name of the resource group to assign the mesh to
|
---|
217 | @param
|
---|
218 | plane The orientation of the plane and distance from the origin
|
---|
219 | @param
|
---|
220 | width The width of the plane in world coordinates
|
---|
221 | @param
|
---|
222 | height The height of the plane in world coordinates
|
---|
223 | @param
|
---|
224 | bow The amount of 'bow' in the curved plane. (Could also be concidered the depth.)
|
---|
225 | @param
|
---|
226 | xsegments The number of segements to the plane in the x direction
|
---|
227 | @param
|
---|
228 | ysegments The number of segements to the plane in the y direction
|
---|
229 | @param
|
---|
230 | normals If true, normals are created perpendicular to the plane
|
---|
231 | @param
|
---|
232 | numTexCoordSets The number of 2D texture coordinate sets created - by default the corners
|
---|
233 | are created to be the corner of the texture.
|
---|
234 | @param
|
---|
235 | uTile The number of times the texture should be repeated in the u direction
|
---|
236 | @param
|
---|
237 | vTile The number of times the texture should be repeated in the v direction
|
---|
238 | @param
|
---|
239 | upVector The 'Up' direction of the plane.
|
---|
240 | @param
|
---|
241 | vertexBufferUsage The usage flag with which the vertex buffer for this plane will be created
|
---|
242 | @param
|
---|
243 | indexBufferUsage The usage flag with which the index buffer for this plane will be created
|
---|
244 | @param
|
---|
245 | vertexShadowBuffer If this flag is set to true, the vertex buffer will be created
|
---|
246 | with a system memory shadow buffer,
|
---|
247 | allowing you to read it back more efficiently than if it is in hardware
|
---|
248 | @param
|
---|
249 | indexShadowBuffer If this flag is set to true, the index buffer will be
|
---|
250 | created with a system memory shadow buffer,
|
---|
251 | allowing you to read it back more efficiently than if it is in hardware
|
---|
252 | */
|
---|
253 | MeshPtr createCurvedPlane(
|
---|
254 | const String& name, const String& groupName, const Plane& plane,
|
---|
255 | Real width, Real height, Real bow = 0.5f,
|
---|
256 | int xsegments = 1, int ysegments = 1,
|
---|
257 | bool normals = false, int numTexCoordSets = 1,
|
---|
258 | Real xTile = 1.0f, Real yTile = 1.0f, const Vector3& upVector = Vector3::UNIT_Y,
|
---|
259 | HardwareBuffer::Usage vertexBufferUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY,
|
---|
260 | HardwareBuffer::Usage indexBufferUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY,
|
---|
261 | bool vertexShadowBuffer = true, bool indexShadowBuffer = true);
|
---|
262 |
|
---|
263 | /** Creates a Bezier patch based on an array of control vertices.
|
---|
264 | @param
|
---|
265 | name The name to give the newly created mesh.
|
---|
266 | @param
|
---|
267 | groupName The name of the resource group to assign the mesh to
|
---|
268 | @param
|
---|
269 | controlPointBuffer A pointer to a buffer containing the vertex data which defines control points
|
---|
270 | of the curves rather than actual vertices. Note that you are expected to provide not
|
---|
271 | just position information, but potentially normals and texture coordinates too. The
|
---|
272 | format of the buffer is defined in the VertexDeclaration parameter
|
---|
273 | @param
|
---|
274 | decaration VertexDeclaration describing the contents of the buffer.
|
---|
275 | Note this declaration must _only_ draw on buffer source 0!
|
---|
276 | @param
|
---|
277 | width Specifies the width of the patch in control points.
|
---|
278 | @param
|
---|
279 | height Specifies the height of the patch in control points.
|
---|
280 | @param
|
---|
281 | uMaxSubdivisionLevel,vMaxSubdivisionLevel If you want to manually set the top level of subdivision,
|
---|
282 | do it here, otherwise let the system decide.
|
---|
283 | @param
|
---|
284 | visibleSide Determines which side of the patch (or both) triangles are generated for.
|
---|
285 | @param
|
---|
286 | vbUsage Vertex buffer usage flags. Recommend the default since vertex buffer should be static.
|
---|
287 | @param
|
---|
288 | ibUsage Index buffer usage flags. Recommend the default since index buffer should
|
---|
289 | be dynamic to change levels but not readable.
|
---|
290 | @param
|
---|
291 | vbUseShadow Flag to determine if a shadow buffer is generated for the vertex buffer. See
|
---|
292 | HardwareBuffer for full details.
|
---|
293 | @param
|
---|
294 | ibUseShadow Flag to determine if a shadow buffer is generated for the index buffer. See
|
---|
295 | HardwareBuffer for full details.
|
---|
296 | */
|
---|
297 | PatchMeshPtr createBezierPatch(
|
---|
298 | const String& name, const String& groupName, void* controlPointBuffer,
|
---|
299 | VertexDeclaration *declaration, size_t width, size_t height,
|
---|
300 | size_t uMaxSubdivisionLevel = PatchSurface::AUTO_LEVEL,
|
---|
301 | size_t vMaxSubdivisionLevel = PatchSurface::AUTO_LEVEL,
|
---|
302 | PatchSurface::VisibleSide visibleSide = PatchSurface::VS_FRONT,
|
---|
303 | HardwareBuffer::Usage vbUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY,
|
---|
304 | HardwareBuffer::Usage ibUsage = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY,
|
---|
305 | bool vbUseShadow = true, bool ibUseShadow = true);
|
---|
306 |
|
---|
307 | /** Tells the mesh manager that all future meshes should prepare themselves for
|
---|
308 | shadow volumes on loading.
|
---|
309 | */
|
---|
310 | void setPrepareAllMeshesForShadowVolumes(bool enable);
|
---|
311 | /** Retrieves whether all Meshes should prepare themselves for shadow volumes. */
|
---|
312 | bool getPrepareAllMeshesForShadowVolumes(void);
|
---|
313 |
|
---|
314 | /** Override standard Singleton retrieval.
|
---|
315 | @remarks
|
---|
316 | Why do we do this? Well, it's because the Singleton
|
---|
317 | implementation is in a .h file, which means it gets compiled
|
---|
318 | into anybody who includes it. This is needed for the
|
---|
319 | Singleton template to work, but we actually only want it
|
---|
320 | compiled into the implementation of the class based on the
|
---|
321 | Singleton, not all of them. If we don't change this, we get
|
---|
322 | link errors when trying to use the Singleton-based class from
|
---|
323 | an outside dll.
|
---|
324 | @par
|
---|
325 | This method just delegates to the template version anyway,
|
---|
326 | but the implementation stays in this single compilation unit,
|
---|
327 | preventing link errors.
|
---|
328 | */
|
---|
329 | static MeshManager& getSingleton(void);
|
---|
330 | /** Override standard Singleton retrieval.
|
---|
331 | @remarks
|
---|
332 | Why do we do this? Well, it's because the Singleton
|
---|
333 | implementation is in a .h file, which means it gets compiled
|
---|
334 | into anybody who includes it. This is needed for the
|
---|
335 | Singleton template to work, but we actually only want it
|
---|
336 | compiled into the implementation of the class based on the
|
---|
337 | Singleton, not all of them. If we don't change this, we get
|
---|
338 | link errors when trying to use the Singleton-based class from
|
---|
339 | an outside dll.
|
---|
340 | @par
|
---|
341 | This method just delegates to the template version anyway,
|
---|
342 | but the implementation stays in this single compilation unit,
|
---|
343 | preventing link errors.
|
---|
344 | */
|
---|
345 | static MeshManager* getSingletonPtr(void);
|
---|
346 |
|
---|
347 | /** Gets the factor by which the bounding box of an entity is padded.
|
---|
348 | Default is 0.01
|
---|
349 | */
|
---|
350 | Real getBoundsPaddingFactor(void);
|
---|
351 |
|
---|
352 | /** Sets the factor by which the bounding box of an entity is padded
|
---|
353 | */
|
---|
354 | void setBoundsPaddingFactor(Real paddingFactor);
|
---|
355 |
|
---|
356 | /** @see ManualResourceLoader::loadResource */
|
---|
357 | void loadResource(Resource* res);
|
---|
358 |
|
---|
359 | protected:
|
---|
360 | /// @copydoc ResourceManager::createImpl
|
---|
361 | Resource* createImpl(const String& name, ResourceHandle handle,
|
---|
362 | const String& group, bool isManual, ManualResourceLoader* loader,
|
---|
363 | const NameValuePairList* createParams);
|
---|
364 |
|
---|
365 | /** Utility method for tesselating 2D meshes.
|
---|
366 | */
|
---|
367 | void tesselate2DMesh(SubMesh* pSub, int meshWidth, int meshHeight,
|
---|
368 | bool doubleSided = false,
|
---|
369 | HardwareBuffer::Usage indexBufferUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY,
|
---|
370 | bool indexSysMem = false);
|
---|
371 |
|
---|
372 | void createPrefabPlane(void);
|
---|
373 |
|
---|
374 | /** Enum identifying the types of manual mesh built by this manager */
|
---|
375 | enum MeshBuildType
|
---|
376 | {
|
---|
377 | MBT_PLANE,
|
---|
378 | MBT_CURVED_ILLUSION_PLANE,
|
---|
379 | MBT_CURVED_PLANE
|
---|
380 | };
|
---|
381 | /** Saved parameters used to (re)build a manual mesh built by this class */
|
---|
382 | struct MeshBuildParams
|
---|
383 | {
|
---|
384 | MeshBuildType type;
|
---|
385 | Plane plane;
|
---|
386 | Real width;
|
---|
387 | Real height;
|
---|
388 | Real curvature;
|
---|
389 | int xsegments;
|
---|
390 | int ysegments;
|
---|
391 | bool normals;
|
---|
392 | int numTexCoordSets;
|
---|
393 | Real xTile;
|
---|
394 | Real yTile;
|
---|
395 | Vector3 upVector;
|
---|
396 | Quaternion orientation;
|
---|
397 | HardwareBuffer::Usage vertexBufferUsage;
|
---|
398 | HardwareBuffer::Usage indexBufferUsage;
|
---|
399 | bool vertexShadowBuffer;
|
---|
400 | bool indexShadowBuffer;
|
---|
401 | int ySegmentsToKeep;
|
---|
402 | };
|
---|
403 | /** Map from resource pointer to parameter set */
|
---|
404 | typedef std::map<Resource*, MeshBuildParams> MeshBuildParamsMap;
|
---|
405 | MeshBuildParamsMap mMeshBuildParams;
|
---|
406 |
|
---|
407 | /** Utility method for manual loading a plane */
|
---|
408 | void loadManualPlane(Mesh* pMesh, MeshBuildParams& params);
|
---|
409 | /** Utility method for manual loading a curved plane */
|
---|
410 | void loadManualCurvedPlane(Mesh* pMesh, MeshBuildParams& params);
|
---|
411 | /** Utility method for manual loading a curved illusion plane */
|
---|
412 | void loadManualCurvedIllusionPlane(Mesh* pMesh, MeshBuildParams& params);
|
---|
413 |
|
---|
414 | bool mPrepAllMeshesForShadowVolumes;
|
---|
415 |
|
---|
416 | //the factor by which the bounding box of an entity is padded
|
---|
417 | Real mBoundsPaddingFactor;
|
---|
418 | };
|
---|
419 |
|
---|
420 |
|
---|
421 | } //namespace
|
---|
422 |
|
---|
423 | #endif
|
---|