source: OGRE/trunk/ogrenew/OgreMain/include/OgreMeshManager.h @ 657

Revision 657, 20.5 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

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-2005 The OGRE Team
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-----------------------------------------------------------------------------
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
37namespace 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                Note this parameter must greater than or equal to 3.
279            @param
280                height Specifies the height of the patch in control points.
281                Note this parameter must greater than or equal to 3.
282            @param
283                uMaxSubdivisionLevel,vMaxSubdivisionLevel If you want to manually set the top level of subdivision,
284                do it here, otherwise let the system decide.
285            @param
286                visibleSide Determines which side of the patch (or both) triangles are generated for.
287            @param
288                vbUsage Vertex buffer usage flags. Recommend the default since vertex buffer should be static.
289            @param
290                ibUsage Index buffer usage flags. Recommend the default since index buffer should
291                be dynamic to change levels but not readable.
292            @param
293                vbUseShadow Flag to determine if a shadow buffer is generated for the vertex buffer. See
294                    HardwareBuffer for full details.
295            @param
296                ibUseShadow Flag to determine if a shadow buffer is generated for the index buffer. See
297                    HardwareBuffer for full details.
298        */
299        PatchMeshPtr createBezierPatch(
300            const String& name, const String& groupName, void* controlPointBuffer,
301            VertexDeclaration *declaration, size_t width, size_t height,
302            size_t uMaxSubdivisionLevel = PatchSurface::AUTO_LEVEL,
303            size_t vMaxSubdivisionLevel = PatchSurface::AUTO_LEVEL,
304            PatchSurface::VisibleSide visibleSide = PatchSurface::VS_FRONT,
305            HardwareBuffer::Usage vbUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY,
306            HardwareBuffer::Usage ibUsage = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY,
307            bool vbUseShadow = true, bool ibUseShadow = true);
308       
309        /** Tells the mesh manager that all future meshes should prepare themselves for
310            shadow volumes on loading.
311        */
312        void setPrepareAllMeshesForShadowVolumes(bool enable);
313        /** Retrieves whether all Meshes should prepare themselves for shadow volumes. */
314        bool getPrepareAllMeshesForShadowVolumes(void);
315
316        /** Override standard Singleton retrieval.
317        @remarks
318        Why do we do this? Well, it's because the Singleton
319        implementation is in a .h file, which means it gets compiled
320        into anybody who includes it. This is needed for the
321        Singleton template to work, but we actually only want it
322        compiled into the implementation of the class based on the
323        Singleton, not all of them. If we don't change this, we get
324        link errors when trying to use the Singleton-based class from
325        an outside dll.
326        @par
327        This method just delegates to the template version anyway,
328        but the implementation stays in this single compilation unit,
329        preventing link errors.
330        */
331        static MeshManager& getSingleton(void);
332        /** Override standard Singleton retrieval.
333        @remarks
334        Why do we do this? Well, it's because the Singleton
335        implementation is in a .h file, which means it gets compiled
336        into anybody who includes it. This is needed for the
337        Singleton template to work, but we actually only want it
338        compiled into the implementation of the class based on the
339        Singleton, not all of them. If we don't change this, we get
340        link errors when trying to use the Singleton-based class from
341        an outside dll.
342        @par
343        This method just delegates to the template version anyway,
344        but the implementation stays in this single compilation unit,
345        preventing link errors.
346        */
347        static MeshManager* getSingletonPtr(void);
348
349            /** Gets the factor by which the bounding box of an entity is padded.
350                Default is 0.01
351            */
352        Real getBoundsPaddingFactor(void);
353       
354            /** Sets the factor by which the bounding box of an entity is padded
355            */
356        void setBoundsPaddingFactor(Real paddingFactor);
357
358        /** @see ManualResourceLoader::loadResource */
359        void loadResource(Resource* res);
360
361    protected:
362        /// @copydoc ResourceManager::createImpl
363        Resource* createImpl(const String& name, ResourceHandle handle,
364            const String& group, bool isManual, ManualResourceLoader* loader,
365            const NameValuePairList* createParams);
366       
367        /** Utility method for tesselating 2D meshes.
368        */
369        void tesselate2DMesh(SubMesh* pSub, int meshWidth, int meshHeight,
370                        bool doubleSided = false,
371                        HardwareBuffer::Usage indexBufferUsage = HardwareBuffer::HBU_STATIC_WRITE_ONLY,
372                        bool indexSysMem = false);
373
374        void createPrefabPlane(void);
375   
376        /** Enum identifying the types of manual mesh built by this manager */
377        enum MeshBuildType
378        {
379            MBT_PLANE,
380            MBT_CURVED_ILLUSION_PLANE,
381            MBT_CURVED_PLANE
382        };
383        /** Saved parameters used to (re)build a manual mesh built by this class */
384        struct MeshBuildParams
385        {
386            MeshBuildType type;
387            Plane plane;
388            Real width;
389            Real height;
390            Real curvature;
391            int xsegments;
392            int ysegments;
393            bool normals;
394            int numTexCoordSets;
395            Real xTile;
396            Real yTile;
397            Vector3 upVector;
398            Quaternion orientation;
399            HardwareBuffer::Usage vertexBufferUsage;
400            HardwareBuffer::Usage indexBufferUsage;
401            bool vertexShadowBuffer;
402            bool indexShadowBuffer;
403            int ySegmentsToKeep;
404        };
405        /** Map from resource pointer to parameter set */
406        typedef std::map<Resource*, MeshBuildParams> MeshBuildParamsMap;
407        MeshBuildParamsMap mMeshBuildParams;
408
409        /** Utility method for manual loading a plane */
410        void loadManualPlane(Mesh* pMesh, MeshBuildParams& params);
411        /** Utility method for manual loading a curved plane */
412        void loadManualCurvedPlane(Mesh* pMesh, MeshBuildParams& params);
413        /** Utility method for manual loading a curved illusion plane */
414        void loadManualCurvedIllusionPlane(Mesh* pMesh, MeshBuildParams& params);
415
416        bool mPrepAllMeshesForShadowVolumes;
417       
418        //the factor by which the bounding box of an entity is padded   
419        Real mBoundsPaddingFactor;
420    };
421
422
423} //namespace
424
425#endif
Note: See TracBrowser for help on using the repository browser.