Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/include/OgreMeshManager.h @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

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