OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreMeshSerializerImpl.h
Go to the documentation of this file.
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 
29 #ifndef __MeshSerializerImpl_H__
30 #define __MeshSerializerImpl_H__
31 
32 #include "OgrePrerequisites.h"
33 #include "OgreSerializer.h"
34 #include "OgreEdgeListBuilder.h"
35 #include "OgreKeyFrame.h"
37 
38 namespace Ogre {
39 
40  class MeshSerializerListener;
41  struct MeshLodUsage;
42 
61  {
62  public:
64  virtual ~MeshSerializerImpl();
73  void exportMesh(const Mesh* pMesh, DataStreamPtr stream,
74  Endian endianMode = ENDIAN_NATIVE);
75 
83  void importMesh(DataStreamPtr& stream, Mesh* pDest, MeshSerializerListener *listener);
84 
85  protected:
86 
87  // Internal methods
88  virtual void writeSubMeshNameTable(const Mesh* pMesh);
89  virtual void writeMesh(const Mesh* pMesh);
90  virtual void writeSubMesh(const SubMesh* s);
91  virtual void writeSubMeshOperation(const SubMesh* s);
92  virtual void writeSubMeshTextureAliases(const SubMesh* s);
93  virtual void writeGeometry(const VertexData* pGeom);
94  virtual void writeSkeletonLink(const String& skelName);
95  virtual void writeMeshBoneAssignment(const VertexBoneAssignment& assign);
96  virtual void writeSubMeshBoneAssignment(const VertexBoneAssignment& assign);
97 
98  virtual void writeLodLevel(const Mesh* pMesh);
99  virtual void writeLodUsageManual(const MeshLodUsage& usage);
100  virtual void writeLodUsageGenerated(const Mesh* pMesh, const MeshLodUsage& usage, unsigned short lodNum);
101  virtual void writeLodUsageGeneratedSubmesh(const SubMesh* submesh, unsigned short lodNum);
102 
103  virtual void writeBoundsInfo(const Mesh* pMesh);
104  virtual void writeEdgeList(const Mesh* pMesh);
105  virtual void writeAnimations(const Mesh* pMesh);
106  virtual void writeAnimation(const Animation* anim);
107  virtual void writePoses(const Mesh* pMesh);
108  virtual void writePose(const Pose* pose);
109  virtual void writeAnimationTrack(const VertexAnimationTrack* track);
110  virtual void writeMorphKeyframe(const VertexMorphKeyFrame* kf, size_t vertexCount);
111  virtual void writePoseKeyframe(const VertexPoseKeyFrame* kf);
112  virtual void writePoseKeyframePoseRef(const VertexPoseKeyFrame::PoseRef& poseRef);
113  virtual void writeExtremes(const Mesh *pMesh);
114  virtual void writeSubMeshExtremes(unsigned short idx, const SubMesh* s);
115 
116  virtual size_t calcMeshSize(const Mesh* pMesh);
117  virtual size_t calcSubMeshSize(const SubMesh* pSub);
118  virtual size_t calcGeometrySize(const VertexData* pGeom);
119  virtual size_t calcSkeletonLinkSize(const String& skelName);
120  virtual size_t calcBoneAssignmentSize(void);
121  virtual size_t calcSubMeshOperationSize(const SubMesh* pSub);
122  virtual size_t calcSubMeshNameTableSize(const Mesh* pMesh);
123  virtual size_t calcLodLevelSize(const Mesh* pMesh);
124  virtual size_t calcLodUsageManualSize(const MeshLodUsage& usage);
125  virtual size_t calcLodUsageGeneratedSize(const Mesh* pMesh, const MeshLodUsage& usage, unsigned short lodNum);
126  virtual size_t calcLodUsageGeneratedSubmeshSize(const SubMesh* submesh, unsigned short lodNum);
127  virtual size_t calcEdgeListSize(const Mesh* pMesh);
128  virtual size_t calcEdgeListLodSize(const EdgeData* data, bool isManual);
129  virtual size_t calcEdgeGroupSize(const EdgeData::EdgeGroup& group);
130  virtual size_t calcPosesSize(const Mesh* pMesh);
131  virtual size_t calcPoseSize(const Pose* pose);
132  virtual size_t calcAnimationsSize(const Mesh* pMesh);
133  virtual size_t calcAnimationSize(const Animation* anim);
134  virtual size_t calcAnimationTrackSize(const VertexAnimationTrack* track);
135  virtual size_t calcMorphKeyframeSize(const VertexMorphKeyFrame* kf, size_t vertexCount);
136  virtual size_t calcPoseKeyframeSize(const VertexPoseKeyFrame* kf);
137  virtual size_t calcPoseKeyframePoseRefSize(void);
138  virtual size_t calcPoseVertexSize(const Pose* pose);
139  virtual size_t calcSubMeshTextureAliasesSize(const SubMesh* pSub);
140  virtual size_t calcBoundsInfoSize(const Mesh* pMesh);
141  virtual size_t calcExtremesSize(const Mesh* pMesh);
142  virtual size_t calcSubMeshExtremesSize(unsigned short idx, const SubMesh* s);
143 
144  virtual void readTextureLayer(DataStreamPtr& stream, Mesh* pMesh, MaterialPtr& pMat);
145  virtual void readSubMeshNameTable(DataStreamPtr& stream, Mesh* pMesh);
146  virtual void readMesh(DataStreamPtr& stream, Mesh* pMesh, MeshSerializerListener *listener);
147  virtual void readSubMesh(DataStreamPtr& stream, Mesh* pMesh, MeshSerializerListener *listener);
148  virtual void readSubMeshOperation(DataStreamPtr& stream, Mesh* pMesh, SubMesh* sub);
149  virtual void readSubMeshTextureAlias(DataStreamPtr& stream, Mesh* pMesh, SubMesh* sub);
150  virtual void readGeometry(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest);
151  virtual void readGeometryVertexDeclaration(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest);
152  virtual void readGeometryVertexElement(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest);
153  virtual void readGeometryVertexBuffer(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest);
154 
155  virtual void readSkeletonLink(DataStreamPtr& stream, Mesh* pMesh, MeshSerializerListener *listener);
156  virtual void readMeshBoneAssignment(DataStreamPtr& stream, Mesh* pMesh);
157  virtual void readSubMeshBoneAssignment(DataStreamPtr& stream, Mesh* pMesh,
158  SubMesh* sub);
159  virtual void readMeshLodLevel(DataStreamPtr& stream, Mesh* pMesh);
160 #if !OGRE_NO_MESHLOD
161  virtual void readMeshLodUsageManual(DataStreamPtr& stream, Mesh* pMesh, unsigned short lodNum, MeshLodUsage& usage);
162  virtual void readMeshLodUsageGenerated(DataStreamPtr& stream, Mesh* pMesh, unsigned short lodNum, MeshLodUsage& usage);
163 #endif
164  virtual void readBoundsInfo(DataStreamPtr& stream, Mesh* pMesh);
165  virtual void readEdgeList(DataStreamPtr& stream, Mesh* pMesh);
166  virtual void readEdgeListLodInfo(DataStreamPtr& stream, EdgeData* edgeData);
167  virtual void readPoses(DataStreamPtr& stream, Mesh* pMesh);
168  virtual void readPose(DataStreamPtr& stream, Mesh* pMesh);
169  virtual void readAnimations(DataStreamPtr& stream, Mesh* pMesh);
170  virtual void readAnimation(DataStreamPtr& stream, Mesh* pMesh);
171  virtual void readAnimationTrack(DataStreamPtr& stream, Animation* anim,
172  Mesh* pMesh);
173  virtual void readMorphKeyFrame(DataStreamPtr& stream, VertexAnimationTrack* track);
174  virtual void readPoseKeyFrame(DataStreamPtr& stream, VertexAnimationTrack* track);
175  virtual void readExtremes(DataStreamPtr& stream, Mesh *pMesh);
176 
177 
179  virtual void flipFromLittleEndian(void* pData, size_t vertexCount, size_t vertexSize, const VertexDeclaration::VertexElementList& elems);
181  virtual void flipToLittleEndian(void* pData, size_t vertexCount, size_t vertexSize, const VertexDeclaration::VertexElementList& elems);
184  virtual void flipEndian(void* pData, size_t vertexCount, size_t vertexSize, const VertexDeclaration::VertexElementList& elems);
185 
187  virtual void enableValidation();
188 
189  ushort exportedLodCount; // Needed to limit exported Edge data, when exporting
190  };
191 
192 
197  {
198  public:
201  protected:
202  // In the past we could select to use manual or automatic generated Lod levels,
203  // but now we can mix them. If it is mixed, we can't export it to older mesh formats.
204  virtual bool isLodMixed(const Mesh* pMesh);
205  virtual size_t calcLodLevelSize(const Mesh* pMesh);
206  virtual size_t calcLodUsageManualSize(const MeshLodUsage& usage);
207  virtual size_t calcLodUsageGeneratedSize(const Mesh* pMesh, const MeshLodUsage& usage, unsigned short lodNum);
208  virtual size_t calcLodUsageGeneratedSubmeshSize(const SubMesh* submesh, unsigned short lodNum);
209 #if !OGRE_NO_MESHLOD
210  virtual void writeLodLevel(const Mesh* pMesh);
211  virtual void writeLodUsageGenerated(const Mesh* pMesh, const MeshLodUsage& usage, unsigned short lodNum);
212  virtual void writeLodUsageGeneratedSubmesh(const SubMesh* submesh, unsigned short lodNum);
213  virtual void writeLodUsageManual(const MeshLodUsage& usage);
214 
215  virtual void readMeshLodUsageGenerated(DataStreamPtr& stream, Mesh* pMesh,
216  unsigned short lodNum, MeshLodUsage& usage);
217  virtual void readMeshLodUsageManual(DataStreamPtr& stream, Mesh* pMesh, unsigned short lodNum, MeshLodUsage& usage);
218 #endif
219  virtual void readMeshLodLevel(DataStreamPtr& stream, Mesh* pMesh);
220  virtual void enableValidation();
221  };
222 
227  {
228  public:
231  protected:
232  void writeMorphKeyframe(const VertexMorphKeyFrame* kf, size_t vertexCount);
233  void readMorphKeyFrame(DataStreamPtr& stream, VertexAnimationTrack* track);
234  void writePose(const Pose* pose);
235  void readPose(DataStreamPtr& stream, Mesh* pMesh);
236  size_t calcMorphKeyframeSize(const VertexMorphKeyFrame* kf, size_t vertexCount);
237  size_t calcPoseSize(const Pose* pose);
238  size_t calcPoseVertexSize(void);
239  };
240 
245  {
246  public:
249  protected:
250  virtual size_t calcLodLevelSize(const Mesh* pMesh);
251  virtual void readMeshLodLevel(DataStreamPtr& stream, Mesh* pMesh);
252 #if !OGRE_NO_MESHLOD
253  virtual void writeLodLevel(const Mesh* pMesh);
254  virtual void writeLodUsageGenerated(const Mesh* pMesh, const MeshLodUsage& usage, unsigned short lodNum);
255 #endif
256  };
257 
262  {
263  public:
266  protected:
267  virtual void readEdgeListLodInfo(DataStreamPtr& stream, EdgeData* edgeData);
268 
270  virtual void reorganiseTriangles(EdgeData* edgeData);
271 
272  virtual void writeEdgeList(const Mesh* pMesh);
273  virtual size_t calcEdgeListLodSize(const EdgeData* edgeData, bool isManual);
274  virtual size_t calcEdgeGroupSize(const EdgeData::EdgeGroup& group);
275  };
276 
281  {
282  public:
285  protected:
286  virtual void readMesh(DataStreamPtr& stream, Mesh* pMesh, MeshSerializerListener *listener);
287  virtual void readGeometry(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest);
288  virtual void readGeometryPositions(unsigned short bindIdx, DataStreamPtr& stream,
289  Mesh* pMesh, VertexData* dest);
290  virtual void readGeometryNormals(unsigned short bindIdx, DataStreamPtr& stream,
291  Mesh* pMesh, VertexData* dest);
292  virtual void readGeometryColours(unsigned short bindIdx, DataStreamPtr& stream,
293  Mesh* pMesh, VertexData* dest);
294  virtual void readGeometryTexCoords(unsigned short bindIdx, DataStreamPtr& stream,
295  Mesh* pMesh, VertexData* dest, unsigned short set);
296  };
297 
302  {
303  public:
306  protected:
307  void readGeometryTexCoords(unsigned short bindIdx, DataStreamPtr& stream,
308  Mesh* pMesh, VertexData* dest, unsigned short set);
309  };
310 
314 }
315 
316 #endif
Specialised KeyFrame which stores absolute vertex positions for a complete buffer, designed to be interpolated with other keys in the same track.
Definition: OgreKeyFrame.h:153
Reference to a pose at a given influence level.
Definition: OgreKeyFrame.h:194
Generic class for serialising data to / from binary stream-based files.
A way of recording the way each LODs is recorded this Mesh.
Definition: OgreMesh.h:961
A pose is a linked set of vertex offsets applying to one set of vertex data.
Definition: OgrePose.h:54
A group of edges sharing the same vertex data.
#define _OgrePrivate
Definition: OgrePlatform.h:256
Endian
The endianness of written files.
Internal implementation of Mesh reading / writing for the latest version of the .mesh format...
Specialised AnimationTrack for dealing with changing vertex position information. ...
Defines a part of a complete mesh.
Definition: OgreSubMesh.h:60
unsigned short ushort
Summary class collecting together vertex source information.
list< VertexElement >::type VertexElementList
Defines the list of vertex elements that makes up this declaration.
Class for providing backwards-compatibility for loading version 1.2 of the .mesh format.
Class for providing backwards-compatibility for loading version 1.4 of the .mesh format.
This class contains the information required to describe the edge connectivity of a given set of vert...
Specialised KeyFrame which references a Mesh::Pose at a certain influence level, which stores offsets...
Definition: OgreKeyFrame.h:183
_StringBase String
Definition: OgreCommon.h:53
Resource holding data about 3D mesh.
Definition: OgreMesh.h:86
Class for providing backwards-compatibility for loading version 1.41 of the .mesh format...
Class for providing backwards-compatibility for loading version 1.8 of the .mesh format.
An animation sequence.
Definition: OgreAnimation.h:90
Records the assignment of a single vertex to a single bone with the corresponding weight...
Class for providing backwards-compatibility for loading version 1.1 of the .mesh format.
Class for providing backwards-compatibility for loading version 1.3 of the .mesh format.