source: GTP/trunk/App/Demos/Geom/OgreStuff/include/OgreMeshSerializerImpl.h @ 1092

Revision 1092, 8.2 KB checked in by gumbau, 18 years ago (diff)

LodStrips? and LODTrees demos

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
26#ifndef __MeshSerializerImpl_H__
27#define __MeshSerializerImpl_H__
28
29#include "OgrePrerequisites.h"
30#include "OgreString.h"
31#include "OgreSerializer.h"
32#include "OgreMaterial.h"
33#include "OgreMesh.h"
34#include "OgreEdgeListBuilder.h"
35
36namespace Ogre {
37
38
39    /** Internal implementation of Mesh reading / writing for the latest version of the
40    .mesh format.
41    @remarks
42    In order to maintain compatibility with older versions of the .mesh format, there
43    will be alternative subclasses of this class to load older versions, whilst this class
44    will remain to load the latest version.
45    */
46    class _OgrePrivate MeshSerializerImpl : public Serializer
47    {
48    public:
49        MeshSerializerImpl();
50        virtual ~MeshSerializerImpl();
51        /** Exports a mesh to the file specified.
52        @remarks
53        This method takes an externally created Mesh object, and exports both it
54        and optionally the Materials it uses to a .mesh file.
55        @param pMesh Pointer to the Mesh to export
56        @param filename The destination filename
57        */
58        void exportMesh(const Mesh* pMesh, const String& filename);
59
60        /** Imports Mesh and (optionally) Material data from a .mesh file DataStream.
61        @remarks
62        This method imports data from a DataStream opened from a .mesh file and places it's
63        contents into the Mesh object which is passed in.
64        @param stream The DataStream holding the .mesh data. Must be initialised (pos at the start of the buffer).
65        @param pDest Pointer to the Mesh object which will receive the data. Should be blank already.
66        */
67        void importMesh(DataStreamPtr& stream, Mesh* pDest);
68
69    protected:
70
71        bool mIsSkeletallyAnimated;
72
73        // Internal methods
74        virtual void writeSubMeshNameTable(const Mesh* pMesh);
75        virtual void writeMesh(const Mesh* pMesh);
76        virtual void writeSubMesh(const SubMesh* s);
77        virtual void writeSubMeshOperation(const SubMesh* s);
78        virtual void writeGeometry(const VertexData* pGeom);
79        virtual void writeSkeletonLink(const String& skelName);
80        virtual void writeMeshBoneAssignment(const VertexBoneAssignment& assign);
81        virtual void writeSubMeshBoneAssignment(const VertexBoneAssignment& assign);
82        virtual void writeLodInfo(const Mesh* pMesh);
83        virtual void writeLodSummary(unsigned short numLevels, bool manual);
84        virtual void writeLodUsageManual(const MeshLodUsage& usage);
85        virtual void writeLodUsageGenerated(const Mesh* pMesh, const MeshLodUsage& usage, unsigned short lodNum);
86        virtual void writeBoundsInfo(const Mesh* pMesh);
87        virtual void writeEdgeList(const Mesh* pMesh);
88
89        virtual size_t calcMeshSize(const Mesh* pMesh);
90        virtual size_t calcSubMeshSize(const SubMesh* pSub);
91        virtual size_t calcGeometrySize(const VertexData* pGeom);
92        virtual size_t calcSkeletonLinkSize(const String& skelName);
93        virtual size_t calcBoneAssignmentSize(void);
94        virtual size_t calcSubMeshOperationSize(const SubMesh* pSub);
95        virtual size_t calcSubMeshNameTableSize(const Mesh* pMesh);
96        virtual size_t calcEdgeListSize(const Mesh* pMesh);
97        virtual size_t calcEdgeListLodSize(const EdgeData* data, bool isManual);
98        virtual size_t calcEdgeGroupSize(const EdgeData::EdgeGroup& group);
99
100        virtual void readTextureLayer(DataStreamPtr& stream, Mesh* pMesh, MaterialPtr& pMat);
101        virtual void readSubMeshNameTable(DataStreamPtr& stream, Mesh* pMesh);
102        virtual void readMesh(DataStreamPtr& stream, Mesh* pMesh);
103        virtual void readSubMesh(DataStreamPtr& stream, Mesh* pMesh);
104        virtual void readSubMeshOperation(DataStreamPtr& stream, Mesh* pMesh, SubMesh* sub);
105        virtual void readGeometry(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest);
106        virtual void readGeometryVertexDeclaration(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest);
107        virtual void readGeometryVertexElement(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest);
108        virtual void readGeometryVertexBuffer(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest);
109
110        virtual void readSkeletonLink(DataStreamPtr& stream, Mesh* pMesh);
111        virtual void readMeshBoneAssignment(DataStreamPtr& stream, Mesh* pMesh);
112        virtual void readSubMeshBoneAssignment(DataStreamPtr& stream, Mesh* pMesh,
113            SubMesh* sub);
114        virtual void readMeshLodInfo(DataStreamPtr& stream, Mesh* pMesh);
115        virtual void readMeshLodUsageManual(DataStreamPtr& stream, Mesh* pMesh,
116            unsigned short lodNum, MeshLodUsage& usage);
117        virtual void readMeshLodUsageGenerated(DataStreamPtr& stream, Mesh* pMesh,
118            unsigned short lodNum, MeshLodUsage& usage);
119        virtual void readBoundsInfo(DataStreamPtr& stream, Mesh* pMesh);
120        virtual void readEdgeList(DataStreamPtr& stream, Mesh* pMesh);
121
122
123
124        /// Flip an entire vertex buffer from little endian
125        virtual void flipFromLittleEndian(void* pData, size_t vertexCount, size_t vertexSize, const VertexDeclaration::VertexElementList& elems);
126        /// Flip an entire vertex buffer to little endian
127        virtual void flipToLittleEndian(void* pData, size_t vertexCount, size_t vertexSize, const VertexDeclaration::VertexElementList& elems);
128        /// Flip the endianness of an entire vertex buffer, passed in as a
129        /// pointer to locked or temporary memory
130        virtual void flipEndian(void* pData, size_t vertexCount, size_t vertexSize, const VertexDeclaration::VertexElementList& elems);
131
132
133
134    };
135
136    /** Class for providing backwards-compatibility for loading version 1.2 of the .mesh format. */
137    class _OgrePrivate MeshSerializerImpl_v1_2 : public MeshSerializerImpl
138    {
139    public:
140        MeshSerializerImpl_v1_2();
141        ~MeshSerializerImpl_v1_2();
142    protected:
143        virtual void readMesh(DataStreamPtr& stream, Mesh* pMesh);
144        virtual void readGeometry(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest);
145        virtual void readGeometryPositions(unsigned short bindIdx, DataStreamPtr& stream,
146            Mesh* pMesh, VertexData* dest);
147        virtual void readGeometryNormals(unsigned short bindIdx, DataStreamPtr& stream,
148            Mesh* pMesh, VertexData* dest);
149        virtual void readGeometryColours(unsigned short bindIdx, DataStreamPtr& stream,
150            Mesh* pMesh, VertexData* dest);
151        virtual void readGeometryTexCoords(unsigned short bindIdx, DataStreamPtr& stream,
152            Mesh* pMesh, VertexData* dest, unsigned short set);
153    };
154
155    /** Class for providing backwards-compatibility for loading version 1.1 of the .mesh format. */
156    class _OgrePrivate MeshSerializerImpl_v1_1 : public MeshSerializerImpl_v1_2
157    {
158    public:
159        MeshSerializerImpl_v1_1();
160        ~MeshSerializerImpl_v1_1();
161    protected:
162        void readGeometryTexCoords(unsigned short bindIdx, DataStreamPtr& stream,
163            Mesh* pMesh, VertexData* dest, unsigned short set);
164    };
165
166
167}
168
169#endif
Note: See TracBrowser for help on using the repository browser.