source: GTP/trunk/Lib/Geom/OgreStuff/include/OgreMeshSerializerImpl.h @ 1809

Revision 1809, 10.0 KB checked in by gumbau, 18 years ago (diff)
RevLine 
[1809]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                @param endianMode The endian mode for the written file
58        */
59        void exportMesh(const Mesh* pMesh, const String& filename,
60                        Endian endianMode = ENDIAN_NATIVE);
61
62        /** Imports Mesh and (optionally) Material data from a .mesh file DataStream.
63        @remarks
64        This method imports data from a DataStream opened from a .mesh file and places it's
65        contents into the Mesh object which is passed in.
66        @param stream The DataStream holding the .mesh data. Must be initialised (pos at the start of the buffer).
67        @param pDest Pointer to the Mesh object which will receive the data. Should be blank already.
68        */
69        void importMesh(DataStreamPtr& stream, Mesh* pDest);
70
71    protected:
72
73        bool mIsSkeletallyAnimated;
74
75        // Internal methods
76        virtual void writeSubMeshNameTable(const Mesh* pMesh);
77        virtual void writeMesh(const Mesh* pMesh);
78        virtual void writeSubMesh(const SubMesh* s);
79        virtual void writeSubMeshOperation(const SubMesh* s);
80        virtual void writeSubMeshTextureAliases(const SubMesh* s);
81        virtual void writeGeometry(const VertexData* pGeom);
82        virtual void writeSkeletonLink(const String& skelName);
83        virtual void writeMeshBoneAssignment(const VertexBoneAssignment& assign);
84        virtual void writeSubMeshBoneAssignment(const VertexBoneAssignment& assign);
85        virtual void writeLodInfo(const Mesh* pMesh);
86        virtual void writeLodSummary(unsigned short numLevels, bool manual);
87        virtual void writeLodUsageManual(const MeshLodUsage& usage);
88        virtual void writeLodUsageGenerated(const Mesh* pMesh, const MeshLodUsage& usage, unsigned short lodNum);
89        virtual void writeBoundsInfo(const Mesh* pMesh);
90        virtual void writeEdgeList(const Mesh* pMesh);
91                virtual void writeAnimations(const Mesh* pMesh);
92                virtual void writeAnimation(const Animation* anim);
93                virtual void writePoses(const Mesh* pMesh);
94                virtual void writePose(const Pose* pose);
95                virtual void writeAnimationTrack(const VertexAnimationTrack* track);
96                virtual void writeMorphKeyframe(const VertexMorphKeyFrame* kf, size_t vertexCount);
97                virtual void writePoseKeyframe(const VertexPoseKeyFrame* kf);
98                virtual void writePoseKeyframePoseRef(const VertexPoseKeyFrame::PoseRef& poseRef);
99
100        virtual size_t calcMeshSize(const Mesh* pMesh);
101        virtual size_t calcSubMeshSize(const SubMesh* pSub);
102        virtual size_t calcGeometrySize(const VertexData* pGeom);
103        virtual size_t calcSkeletonLinkSize(const String& skelName);
104        virtual size_t calcBoneAssignmentSize(void);
105        virtual size_t calcSubMeshOperationSize(const SubMesh* pSub);
106        virtual size_t calcSubMeshNameTableSize(const Mesh* pMesh);
107        virtual size_t calcEdgeListSize(const Mesh* pMesh);
108        virtual size_t calcEdgeListLodSize(const EdgeData* data, bool isManual);
109        virtual size_t calcEdgeGroupSize(const EdgeData::EdgeGroup& group);
110                virtual size_t calcPosesSize(const Mesh* pMesh);
111                virtual size_t calcPoseSize(const Pose* pose);
112                virtual size_t calcAnimationsSize(const Mesh* pMesh);
113                virtual size_t calcAnimationSize(const Animation* anim);
114                virtual size_t calcAnimationTrackSize(const VertexAnimationTrack* track);
115                virtual size_t calcMorphKeyframeSize(const VertexMorphKeyFrame* kf, size_t vertexCount);
116                virtual size_t calcPoseKeyframeSize(const VertexPoseKeyFrame* kf);
117                virtual size_t calcPoseKeyframePoseRefSize(void);
118                virtual size_t calcPoseVertexSize(void);
119        virtual size_t calcSubMeshTextureAliasesSize(const SubMesh* pSub);
120
121
122        virtual void readTextureLayer(DataStreamPtr& stream, Mesh* pMesh, MaterialPtr& pMat);
123        virtual void readSubMeshNameTable(DataStreamPtr& stream, Mesh* pMesh);
124        virtual void readMesh(DataStreamPtr& stream, Mesh* pMesh);
125        virtual void readSubMesh(DataStreamPtr& stream, Mesh* pMesh);
126        virtual void readSubMeshOperation(DataStreamPtr& stream, Mesh* pMesh, SubMesh* sub);
127        virtual void readSubMeshTextureAlias(DataStreamPtr& stream, Mesh* pMesh, SubMesh* sub);
128        virtual void readGeometry(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest);
129        virtual void readGeometryVertexDeclaration(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest);
130        virtual void readGeometryVertexElement(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest);
131        virtual void readGeometryVertexBuffer(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest);
132
133        virtual void readSkeletonLink(DataStreamPtr& stream, Mesh* pMesh);
134        virtual void readMeshBoneAssignment(DataStreamPtr& stream, Mesh* pMesh);
135        virtual void readSubMeshBoneAssignment(DataStreamPtr& stream, Mesh* pMesh,
136            SubMesh* sub);
137        virtual void readMeshLodInfo(DataStreamPtr& stream, Mesh* pMesh);
138        virtual void readMeshLodUsageManual(DataStreamPtr& stream, Mesh* pMesh,
139            unsigned short lodNum, MeshLodUsage& usage);
140        virtual void readMeshLodUsageGenerated(DataStreamPtr& stream, Mesh* pMesh,
141            unsigned short lodNum, MeshLodUsage& usage);
142        virtual void readBoundsInfo(DataStreamPtr& stream, Mesh* pMesh);
143        virtual void readEdgeList(DataStreamPtr& stream, Mesh* pMesh);
144                virtual void readPoses(DataStreamPtr& stream, Mesh* pMesh);
145                virtual void readPose(DataStreamPtr& stream, Mesh* pMesh);
146                virtual void readAnimations(DataStreamPtr& stream, Mesh* pMesh);
147                virtual void readAnimation(DataStreamPtr& stream, Mesh* pMesh);
148                virtual void readAnimationTrack(DataStreamPtr& stream, Animation* anim,
149                        Mesh* pMesh);
150                virtual void readMorphKeyFrame(DataStreamPtr& stream, VertexAnimationTrack* track);
151                virtual void readPoseKeyFrame(DataStreamPtr& stream, VertexAnimationTrack* track);
152
153
154        /// Flip an entire vertex buffer from little endian
155        virtual void flipFromLittleEndian(void* pData, size_t vertexCount, size_t vertexSize, const VertexDeclaration::VertexElementList& elems);
156        /// Flip an entire vertex buffer to little endian
157        virtual void flipToLittleEndian(void* pData, size_t vertexCount, size_t vertexSize, const VertexDeclaration::VertexElementList& elems);
158        /// Flip the endianness of an entire vertex buffer, passed in as a
159        /// pointer to locked or temporary memory
160        virtual void flipEndian(void* pData, size_t vertexCount, size_t vertexSize, const VertexDeclaration::VertexElementList& elems);
161
162
163
164    };
165
166    /** Class for providing backwards-compatibility for loading version 1.2 of the .mesh format. */
167    class _OgrePrivate MeshSerializerImpl_v1_2 : public MeshSerializerImpl
168    {
169    public:
170        MeshSerializerImpl_v1_2();
171        ~MeshSerializerImpl_v1_2();
172    protected:
173        virtual void readMesh(DataStreamPtr& stream, Mesh* pMesh);
174        virtual void readGeometry(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest);
175        virtual void readGeometryPositions(unsigned short bindIdx, DataStreamPtr& stream,
176            Mesh* pMesh, VertexData* dest);
177        virtual void readGeometryNormals(unsigned short bindIdx, DataStreamPtr& stream,
178            Mesh* pMesh, VertexData* dest);
179        virtual void readGeometryColours(unsigned short bindIdx, DataStreamPtr& stream,
180            Mesh* pMesh, VertexData* dest);
181        virtual void readGeometryTexCoords(unsigned short bindIdx, DataStreamPtr& stream,
182            Mesh* pMesh, VertexData* dest, unsigned short set);
183    };
184
185    /** Class for providing backwards-compatibility for loading version 1.1 of the .mesh format. */
186    class _OgrePrivate MeshSerializerImpl_v1_1 : public MeshSerializerImpl_v1_2
187    {
188    public:
189        MeshSerializerImpl_v1_1();
190        ~MeshSerializerImpl_v1_1();
191    protected:
192        void readGeometryTexCoords(unsigned short bindIdx, DataStreamPtr& stream,
193            Mesh* pMesh, VertexData* dest, unsigned short set);
194    };
195
196
197}
198
199#endif
Note: See TracBrowser for help on using the repository browser.