/src/ogre/OgreMain/include/OgreMeshManager.h
Line | Count | Source (jump to first uncovered line) |
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-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | #ifndef __MeshManager_H__ |
29 | | #define __MeshManager_H__ |
30 | | |
31 | | #include "OgrePrerequisites.h" |
32 | | |
33 | | #include "OgreResourceManager.h" |
34 | | #include "OgreSingleton.h" |
35 | | #include "OgreVector.h" |
36 | | #include "OgreHardwareBuffer.h" |
37 | | #include "OgreHardwareVertexBuffer.h" |
38 | | #include "OgrePatchSurface.h" |
39 | | #include "OgreHeaderPrefix.h" |
40 | | #include "OgrePlane.h" |
41 | | |
42 | | namespace Ogre { |
43 | | |
44 | | class MeshSerializerListener; |
45 | | |
46 | | /** \addtogroup Core |
47 | | * @{ |
48 | | */ |
49 | | /** \addtogroup Resources |
50 | | * @{ |
51 | | */ |
52 | | /** Handles the management of mesh resources. |
53 | | |
54 | | This class deals with the runtime management of |
55 | | mesh data; like other resource managers it handles |
56 | | the creation of resources (in this case mesh data), |
57 | | working within a fixed memory budget. |
58 | | |
59 | | Ogre loads model files from it's own proprietary |
60 | | format called .mesh. This is because having a single file |
61 | | format is better for runtime performance, and we also have |
62 | | control over pre-processed data (such as |
63 | | collision boxes, LOD reductions etc). |
64 | | */ |
65 | | class _OgreExport MeshManager: public ResourceManager, public Singleton<MeshManager> |
66 | | { |
67 | | public: |
68 | | MeshManager(); |
69 | | ~MeshManager(); |
70 | | |
71 | | /** Initialises the manager, only to be called by OGRE internally. */ |
72 | | void _initialise(void); |
73 | | |
74 | | /// @copydoc ResourceManager::getResourceByName |
75 | | MeshPtr getByName(const String& name, const String& groupName OGRE_RESOURCE_GROUP_INIT) const; |
76 | | |
77 | | /// Create a new mesh |
78 | | /// @copydetails ResourceManager::createResource |
79 | | MeshPtr create (const String& name, const String& group, |
80 | | bool isManual = false, ManualResourceLoader* loader = 0, |
81 | | const NameValuePairList* createParams = 0); |
82 | | |
83 | | using ResourceManager::createOrRetrieve; |
84 | | |
85 | | /** Create a new mesh, or retrieve an existing one with the same |
86 | | name if it already exists. |
87 | | @copydetails ResourceManager::createResource |
88 | | @param vertexBufferUsage The usage flags with which the vertex buffer(s) |
89 | | will be created |
90 | | @param indexBufferUsage The usage flags with which the index buffer(s) created for |
91 | | this mesh will be created with. |
92 | | @param vertexBufferShadowed If true, the vertex buffers will be shadowed by system memory |
93 | | copies for faster read access |
94 | | @param indexBufferShadowed If true, the index buffers will be shadowed by system memory |
95 | | copies for faster read access |
96 | | */ |
97 | | ResourceCreateOrRetrieveResult createOrRetrieve( |
98 | | const String& name, |
99 | | const String& group, |
100 | | bool isManual, ManualResourceLoader* loader, |
101 | | const NameValuePairList* createParams, |
102 | | HardwareBuffer::Usage vertexBufferUsage, |
103 | | HardwareBuffer::Usage indexBufferUsage = HBU_GPU_ONLY, |
104 | | bool vertexBufferShadowed = false, bool indexBufferShadowed = false); |
105 | | |
106 | | /** Prepares a mesh for loading from a file. This does the IO in advance of the call to load(). |
107 | | @note |
108 | | If the model has already been created (prepared or loaded), the existing instance |
109 | | will be returned. |
110 | | @param filename The name of the .mesh file |
111 | | @param groupName The name of the resource group to assign the mesh to |
112 | | @param vertexBufferUsage The usage flags with which the vertex buffer(s) |
113 | | will be created |
114 | | @param indexBufferUsage The usage flags with which the index buffer(s) created for |
115 | | this mesh will be created with. |
116 | | @param vertexBufferShadowed If true, the vertex buffers will be shadowed by system memory |
117 | | copies for faster read access |
118 | | @param indexBufferShadowed If true, the index buffers will be shadowed by system memory |
119 | | copies for faster read access |
120 | | */ |
121 | | MeshPtr prepare( const String& filename, const String& groupName, |
122 | | HardwareBuffer::Usage vertexBufferUsage = HBU_GPU_ONLY, |
123 | | HardwareBuffer::Usage indexBufferUsage = HBU_GPU_ONLY, |
124 | | bool vertexBufferShadowed = false, bool indexBufferShadowed = false); |
125 | | |
126 | | /** Loads a mesh from a file, making it immediately available for use. |
127 | | @copydetails MeshManager::prepare |
128 | | */ |
129 | | MeshPtr load( const String& filename, const String& groupName, |
130 | | HardwareBuffer::Usage vertexBufferUsage = HBU_GPU_ONLY, |
131 | | HardwareBuffer::Usage indexBufferUsage = HBU_GPU_ONLY, |
132 | | bool vertexBufferShadowed = false, bool indexBufferShadowed = false); |
133 | | |
134 | | |
135 | | /** Creates a new Mesh specifically for manual definition rather |
136 | | than loading from an object file. |
137 | | |
138 | | Note that once you've defined your mesh, you must call Mesh::_setBounds |
139 | | in order to define the bounds of your mesh. In previous |
140 | | versions of OGRE could auto-compute that, but OGRE's support of |
141 | | write-only vertex buffers makes this no longer appropriate. |
142 | | @param name The name to give the new mesh |
143 | | @param groupName The name of the resource group to assign the mesh to |
144 | | @param loader ManualResourceLoader which will be called to load this mesh |
145 | | when the time comes. It is recommended that you populate this field |
146 | | in order that the mesh can be rebuilt should the need arise |
147 | | */ |
148 | | MeshPtr createManual( const String& name, const String& groupName, |
149 | | ManualResourceLoader* loader = 0); |
150 | | |
151 | | /** Creates a basic plane, by default majoring on the x/y axes facing positive Z. |
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 | | xsegments The number of segments to the plane in the x direction |
164 | | @param |
165 | | ysegments The number of segments to the plane in the y direction |
166 | | @param |
167 | | normals If true, normals are created perpendicular to the plane |
168 | | @param |
169 | | numTexCoordSets The number of 2D texture coordinate sets created - by default the corners |
170 | | are created to be the corner of the texture. |
171 | | @param |
172 | | uTile The number of times the texture should be repeated in the u direction |
173 | | @param |
174 | | vTile The number of times the texture should be repeated in the v direction |
175 | | @param |
176 | | upVector The 'Up' direction of the plane texture coordinates. |
177 | | @param |
178 | | vertexBufferUsage The usage flag with which the vertex buffer for this plane will be created |
179 | | @param |
180 | | indexBufferUsage The usage flag with which the index buffer for this plane will be created |
181 | | @param |
182 | | vertexShadowBuffer If this flag is set to true, the vertex buffer will be created |
183 | | with a system memory shadow buffer, |
184 | | allowing you to read it back more efficiently than if it is in hardware |
185 | | @param |
186 | | indexShadowBuffer If this flag is set to true, the index buffer will be |
187 | | created with a system memory shadow buffer, |
188 | | allowing you to read it back more efficiently than if it is in hardware |
189 | | */ |
190 | | MeshPtr createPlane( |
191 | | const String& name, const String& groupName, const Plane& plane, |
192 | | Real width, Real height, |
193 | | int xsegments = 1, int ysegments = 1, |
194 | | bool normals = true, unsigned short numTexCoordSets = 1, |
195 | | Real uTile = 1.0f, Real vTile = 1.0f, const Vector3& upVector = Vector3::UNIT_Y, |
196 | | HardwareBuffer::Usage vertexBufferUsage = HBU_GPU_ONLY, |
197 | | HardwareBuffer::Usage indexBufferUsage = HBU_GPU_ONLY, |
198 | | bool vertexShadowBuffer = false, bool indexShadowBuffer = false); |
199 | | |
200 | | |
201 | | /** Creates a plane, which because of it's texture coordinates looks like a curved |
202 | | surface, useful for skies in a skybox. |
203 | | @param name |
204 | | The name to give the resulting mesh |
205 | | @param groupName |
206 | | The name of the resource group to assign the mesh to |
207 | | @param plane |
208 | | The orientation of the plane and distance from the origin |
209 | | @param width |
210 | | The width of the plane in world coordinates |
211 | | @param height |
212 | | The height of the plane in world coordinates |
213 | | @param curvature |
214 | | The curvature of the plane. Good values are |
215 | | between 2 and 65. Higher values are more curved leading to |
216 | | a smoother effect, lower values are less curved meaning |
217 | | more distortion at the horizons but a better distance effect. |
218 | | @param xsegments |
219 | | The number of segments to the plane in the x direction |
220 | | @param ysegments |
221 | | The number of segments to the plane in the y direction |
222 | | @param normals |
223 | | If true, normals are created perpendicular to the plane |
224 | | @param numTexCoordSets |
225 | | The number of 2D texture coordinate sets created - by default the corners |
226 | | are created to be the corner of the texture. |
227 | | @param uTile |
228 | | The number of times the texture should be repeated in the u direction |
229 | | @param vTile |
230 | | The number of times the texture should be repeated in the v direction |
231 | | @param upVector |
232 | | The 'Up' direction of the plane. |
233 | | @param orientation |
234 | | The orientation of the overall sphere that's used to create the illusion |
235 | | @param vertexBufferUsage |
236 | | The usage flag with which the vertex buffer for this plane will be created |
237 | | @param indexBufferUsage |
238 | | The usage flag with which the index buffer for this plane will be created |
239 | | @param vertexShadowBuffer |
240 | | If this flag is set to true, the vertex buffer will be created |
241 | | with a system memory shadow buffer, |
242 | | allowing you to read it back more efficiently than if it is in hardware |
243 | | @param indexShadowBuffer |
244 | | If this flag is set to true, the index buffer will be |
245 | | created with a system memory shadow buffer, |
246 | | allowing you to read it back more efficiently than if it is in hardware |
247 | | @param ySegmentsToKeep The number of segments from the top of the dome |
248 | | downwards to keep. -1 keeps all of them. This can save fillrate if |
249 | | you cannot see much of the sky lower down. |
250 | | */ |
251 | | MeshPtr createCurvedIllusionPlane( |
252 | | const String& name, const String& groupName, const Plane& plane, |
253 | | Real width, Real height, Real curvature, |
254 | | int xsegments = 1, int ysegments = 1, |
255 | | bool normals = true, unsigned short numTexCoordSets = 1, |
256 | | Real uTile = 1.0f, Real vTile = 1.0f, const Vector3& upVector = Vector3::UNIT_Y, |
257 | | const Quaternion& orientation = Quaternion::IDENTITY, |
258 | | HardwareBuffer::Usage vertexBufferUsage = HBU_GPU_ONLY, |
259 | | HardwareBuffer::Usage indexBufferUsage = HBU_GPU_ONLY, |
260 | | bool vertexShadowBuffer = false, bool indexShadowBuffer = false, |
261 | | int ySegmentsToKeep = -1); |
262 | | |
263 | | /** Creates a genuinely curved plane, by default majoring on the x/y axes facing positive Z. |
264 | | @param name |
265 | | The name to give the resulting mesh |
266 | | @param groupName |
267 | | The name of the resource group to assign the mesh to |
268 | | @param plane |
269 | | The orientation of the plane and distance from the origin |
270 | | @param width |
271 | | The width of the plane in world coordinates |
272 | | @param height |
273 | | The height of the plane in world coordinates |
274 | | @param bow |
275 | | The amount of 'bow' in the curved plane. (Could also be considered the depth.) |
276 | | @param xsegments |
277 | | The number of segments to the plane in the x direction |
278 | | @param ysegments |
279 | | The number of segments to the plane in the y direction |
280 | | @param normals |
281 | | If true, normals are created perpendicular to the plane |
282 | | @param numTexCoordSets |
283 | | The number of 2D texture coordinate sets created - by default the corners |
284 | | are created to be the corner of the texture. |
285 | | @param uTile |
286 | | The number of times the texture should be repeated in the u direction |
287 | | @param vTile |
288 | | The number of times the texture should be repeated in the v direction |
289 | | @param upVector |
290 | | The 'Up' direction of the plane. |
291 | | @param vertexBufferUsage |
292 | | The usage flag with which the vertex buffer for this plane will be created |
293 | | @param indexBufferUsage |
294 | | The usage flag with which the index buffer for this plane will be created |
295 | | @param vertexShadowBuffer |
296 | | If this flag is set to true, the vertex buffer will be created |
297 | | with a system memory shadow buffer, |
298 | | allowing you to read it back more efficiently than if it is in hardware |
299 | | @param indexShadowBuffer |
300 | | If this flag is set to true, the index buffer will be |
301 | | created with a system memory shadow buffer, |
302 | | allowing you to read it back more efficiently than if it is in hardware |
303 | | */ |
304 | | MeshPtr createCurvedPlane( |
305 | | const String& name, const String& groupName, const Plane& plane, |
306 | | Real width, Real height, Real bow = 0.5f, |
307 | | int xsegments = 1, int ysegments = 1, |
308 | | bool normals = false, unsigned short numTexCoordSets = 1, |
309 | | Real uTile = 1.0f, Real vTile = 1.0f, const Vector3& upVector = Vector3::UNIT_Y, |
310 | | HardwareBuffer::Usage vertexBufferUsage = HBU_GPU_ONLY, |
311 | | HardwareBuffer::Usage indexBufferUsage = HBU_GPU_ONLY, |
312 | | bool vertexShadowBuffer = false, bool indexShadowBuffer = false); |
313 | | |
314 | | /** Creates a Bezier patch based on an array of control vertices. |
315 | | @param name |
316 | | The name to give the newly created mesh. |
317 | | @param groupName |
318 | | The name of the resource group to assign the mesh to |
319 | | @param controlPointBuffer |
320 | | A pointer to a buffer containing the vertex data which defines control points |
321 | | of the curves rather than actual vertices. Note that you are expected to provide not |
322 | | just position information, but potentially normals and texture coordinates too. The |
323 | | format of the buffer is defined in the VertexDeclaration parameter |
324 | | @param declaration |
325 | | VertexDeclaration describing the contents of the buffer. |
326 | | Note this declaration must _only_ draw on buffer source 0! |
327 | | @param width |
328 | | Specifies the width of the patch in control points. |
329 | | Note this parameter must greater than or equal to 3. |
330 | | @param height |
331 | | Specifies the height of the patch in control points. |
332 | | Note this parameter must greater than or equal to 3. |
333 | | @param uMaxSubdivisionLevel, vMaxSubdivisionLevel |
334 | | If you want to manually set the top level of subdivision, |
335 | | do it here, otherwise let the system decide. |
336 | | @param visibleSide |
337 | | Determines which side of the patch (or both) triangles are generated for. |
338 | | @param vbUsage |
339 | | Vertex buffer usage flags. Recommend the default since vertex buffer should be static. |
340 | | @param ibUsage |
341 | | Index buffer usage flags. Recommend the default since index buffer should |
342 | | be dynamic to change levels but not readable. |
343 | | @param vbUseShadow |
344 | | Flag to determine if a shadow buffer is generated for the vertex buffer. See |
345 | | HardwareBuffer for full details. |
346 | | @param ibUseShadow |
347 | | Flag to determine if a shadow buffer is generated for the index buffer. See |
348 | | HardwareBuffer for full details. |
349 | | */ |
350 | | PatchMeshPtr createBezierPatch( |
351 | | const String& name, const String& groupName, void* controlPointBuffer, |
352 | | VertexDeclaration *declaration, size_t width, size_t height, |
353 | | size_t uMaxSubdivisionLevel = PatchSurface::AUTO_LEVEL, |
354 | | size_t vMaxSubdivisionLevel = PatchSurface::AUTO_LEVEL, |
355 | | PatchSurface::VisibleSide visibleSide = PatchSurface::VS_FRONT, |
356 | | HardwareBuffer::Usage vbUsage = HBU_GPU_ONLY, |
357 | | HardwareBuffer::Usage ibUsage = HBU_CPU_TO_GPU, |
358 | | bool vbUseShadow = true, bool ibUseShadow = true); |
359 | | |
360 | | /** Tells the mesh manager that all future meshes should prepare themselves for |
361 | | shadow volumes on loading. |
362 | | */ |
363 | | void setPrepareAllMeshesForShadowVolumes(bool enable); |
364 | | /** Retrieves whether all Meshes should prepare themselves for shadow volumes. */ |
365 | | bool getPrepareAllMeshesForShadowVolumes(void); |
366 | | |
367 | | /// @copydoc Singleton::getSingleton() |
368 | | static MeshManager& getSingleton(void); |
369 | | /// @copydoc Singleton::getSingleton() |
370 | | static MeshManager* getSingletonPtr(void); |
371 | | |
372 | | /** Gets the base element type used for blend weights in vertex buffers. |
373 | | |
374 | | See the remarks below for SetBlendWeightsBaseElementType(). |
375 | | */ |
376 | | VertexElementType getBlendWeightsBaseElementType() const; |
377 | | |
378 | | /** sets the base element type used for blend weights in vertex buffers. |
379 | | |
380 | | This takes effect when meshes are loaded. Default is VET_FLOAT1. |
381 | | Valid values are: |
382 | | VET_UBYTE4_NORM: 8-bit blend weights. Lowest memory cost but may have precision issues. Requires SM2.0+ vertex shader. No software skinning. |
383 | | VET_USHORT2_NORM: 16-bit blend weights. Requires SM2.0+ vertex shader. No software skinning. |
384 | | VET_FLOAT1: 32-bit blend weights. Highest memory cost. Supports hardware and software skinning. |
385 | | */ |
386 | | void setBlendWeightsBaseElementType( VertexElementType vet ); |
387 | | |
388 | | /** Set whether to keep the bone matrices in object space or transform them to world space. |
389 | | * |
390 | | * Transforming to world space happens on the CPU and is the legacy behavior. Using object space bones |
391 | | * is more efficient as it allows to do the transformation in the vertex shader. |
392 | | */ |
393 | 0 | static void setBonesUseObjectSpace(bool enable) { mBonesUseObjectSpace = enable; } |
394 | | /// whether the bone matrices are in object space or world space |
395 | 0 | static bool getBonesUseObjectSpace() { return mBonesUseObjectSpace; } |
396 | | |
397 | | /** Gets the factor by which the bounding box of an entity is padded. |
398 | | Default is 0.01 |
399 | | */ |
400 | | Real getBoundsPaddingFactor(void); |
401 | | |
402 | | /** Sets the factor by which the bounding box of an entity is padded |
403 | | */ |
404 | | void setBoundsPaddingFactor(Real paddingFactor); |
405 | | |
406 | | /** Sets the listener used to control mesh loading through the serializer. |
407 | | */ |
408 | | void setListener(MeshSerializerListener *listener); |
409 | | |
410 | | /** Gets the listener used to control mesh loading through the serializer. |
411 | | */ |
412 | | MeshSerializerListener *getListener(); |
413 | | |
414 | | private: |
415 | | |
416 | | /// @copydoc ResourceManager::createImpl |
417 | | Resource* createImpl(const String& name, ResourceHandle handle, |
418 | | const String& group, bool isManual, ManualResourceLoader* loader, |
419 | | const NameValuePairList* createParams) override; |
420 | | |
421 | | std::unique_ptr<ManualResourceLoader> mPrefabLoader; |
422 | | |
423 | | // element type for blend weights in vertex buffer (VET_UBYTE4, VET_USHORT1, or VET_FLOAT1) |
424 | | VertexElementType mBlendWeightsBaseElementType; |
425 | | |
426 | | bool mPrepAllMeshesForShadowVolumes; |
427 | | static bool mBonesUseObjectSpace; |
428 | | |
429 | | //the factor by which the bounding box of an entity is padded |
430 | | Real mBoundsPaddingFactor; |
431 | | |
432 | | // The listener to pass to serializers |
433 | | MeshSerializerListener *mListener; |
434 | | |
435 | | private: |
436 | | std::unique_ptr<Codec> mMeshCodec; |
437 | | }; |
438 | | |
439 | | /** @} */ |
440 | | /** @} */ |
441 | | |
442 | | } //namespace |
443 | | |
444 | | #include "OgreHeaderSuffix.h" |
445 | | |
446 | | #endif |