| 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-2006 Torus Knot Software Ltd | 
|---|
| 8 | Also see acknowledgements in Readme.html | 
|---|
| 9 |  | 
|---|
| 10 | This program is free software; you can redistribute it and/or modify it under | 
|---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software | 
|---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later | 
|---|
| 13 | version. | 
|---|
| 14 |  | 
|---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT | 
|---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 
|---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | 
|---|
| 18 |  | 
|---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with | 
|---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple | 
|---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to | 
|---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. | 
|---|
| 23 |  | 
|---|
| 24 | You may alternatively use this source under the terms of a specific version of | 
|---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from | 
|---|
| 26 | Torus Knot Software Ltd. | 
|---|
| 27 | ----------------------------------------------------------------------------- | 
|---|
| 28 | */ | 
|---|
| 29 |  | 
|---|
| 30 | #ifndef __MeshSerializerImpl_H__ | 
|---|
| 31 | #define __MeshSerializerImpl_H__ | 
|---|
| 32 |  | 
|---|
| 33 | #include "OgrePrerequisites.h" | 
|---|
| 34 | #include "OgreString.h" | 
|---|
| 35 | #include "OgreSerializer.h" | 
|---|
| 36 | #include "OgreMaterial.h" | 
|---|
| 37 | #include "OgreMesh.h" | 
|---|
| 38 | #include "OgreEdgeListBuilder.h" | 
|---|
| 39 |  | 
|---|
| 40 | namespace Ogre { | 
|---|
| 41 |  | 
|---|
| 42 |  | 
|---|
| 43 |     /** Internal implementation of Mesh reading / writing for the latest version of the | 
|---|
| 44 |     .mesh format. | 
|---|
| 45 |     @remarks | 
|---|
| 46 |     In order to maintain compatibility with older versions of the .mesh format, there | 
|---|
| 47 |     will be alternative subclasses of this class to load older versions, whilst this class | 
|---|
| 48 |     will remain to load the latest version. | 
|---|
| 49 |     */ | 
|---|
| 50 |     class _OgrePrivate MeshSerializerImpl : public Serializer | 
|---|
| 51 |     { | 
|---|
| 52 |     public: | 
|---|
| 53 |         MeshSerializerImpl(); | 
|---|
| 54 |         virtual ~MeshSerializerImpl(); | 
|---|
| 55 |         /** Exports a mesh to the file specified.  | 
|---|
| 56 |         @remarks | 
|---|
| 57 |         This method takes an externally created Mesh object, and exports both it | 
|---|
| 58 |         and optionally the Materials it uses to a .mesh file. | 
|---|
| 59 |         @param pMesh Pointer to the Mesh to export | 
|---|
| 60 |         @param filename The destination filename | 
|---|
| 61 |                 @param endianMode The endian mode for the written file | 
|---|
| 62 |         */ | 
|---|
| 63 |         void exportMesh(const Mesh* pMesh, const String& filename, | 
|---|
| 64 |                         Endian endianMode = ENDIAN_NATIVE); | 
|---|
| 65 |  | 
|---|
| 66 |         /** Imports Mesh and (optionally) Material data from a .mesh file DataStream. | 
|---|
| 67 |         @remarks | 
|---|
| 68 |         This method imports data from a DataStream opened from a .mesh file and places it's | 
|---|
| 69 |         contents into the Mesh object which is passed in.  | 
|---|
| 70 |         @param stream The DataStream holding the .mesh data. Must be initialised (pos at the start of the buffer). | 
|---|
| 71 |         @param pDest Pointer to the Mesh object which will receive the data. Should be blank already. | 
|---|
| 72 |         */ | 
|---|
| 73 |         void importMesh(DataStreamPtr& stream, Mesh* pDest); | 
|---|
| 74 |  | 
|---|
| 75 |     protected: | 
|---|
| 76 |  | 
|---|
| 77 |         // Internal methods | 
|---|
| 78 |         virtual void writeSubMeshNameTable(const Mesh* pMesh); | 
|---|
| 79 |         virtual void writeMesh(const Mesh* pMesh); | 
|---|
| 80 |         virtual void writeSubMesh(const SubMesh* s); | 
|---|
| 81 |         virtual void writeSubMeshOperation(const SubMesh* s); | 
|---|
| 82 |         virtual void writeSubMeshTextureAliases(const SubMesh* s); | 
|---|
| 83 |         virtual void writeGeometry(const VertexData* pGeom); | 
|---|
| 84 |         virtual void writeSkeletonLink(const String& skelName); | 
|---|
| 85 |         virtual void writeMeshBoneAssignment(const VertexBoneAssignment& assign); | 
|---|
| 86 |         virtual void writeSubMeshBoneAssignment(const VertexBoneAssignment& assign); | 
|---|
| 87 |         virtual void writeLodInfo(const Mesh* pMesh); | 
|---|
| 88 |         virtual void writeLodSummary(unsigned short numLevels, bool manual); | 
|---|
| 89 |         virtual void writeLodUsageManual(const MeshLodUsage& usage); | 
|---|
| 90 |         virtual void writeLodUsageGenerated(const Mesh* pMesh, const MeshLodUsage& usage, unsigned short lodNum); | 
|---|
| 91 |         virtual void writeBoundsInfo(const Mesh* pMesh); | 
|---|
| 92 |         virtual void writeEdgeList(const Mesh* pMesh); | 
|---|
| 93 |                 virtual void writeAnimations(const Mesh* pMesh); | 
|---|
| 94 |                 virtual void writeAnimation(const Animation* anim); | 
|---|
| 95 |                 virtual void writePoses(const Mesh* pMesh); | 
|---|
| 96 |                 virtual void writePose(const Pose* pose); | 
|---|
| 97 |                 virtual void writeAnimationTrack(const VertexAnimationTrack* track); | 
|---|
| 98 |                 virtual void writeMorphKeyframe(const VertexMorphKeyFrame* kf, size_t vertexCount); | 
|---|
| 99 |                 virtual void writePoseKeyframe(const VertexPoseKeyFrame* kf); | 
|---|
| 100 |                 virtual void writePoseKeyframePoseRef(const VertexPoseKeyFrame::PoseRef& poseRef); | 
|---|
| 101 |         virtual void writeExtremes(const Mesh *pMesh); | 
|---|
| 102 |         virtual void writeSubMeshExtremes(unsigned short idx, const SubMesh* s); | 
|---|
| 103 |  | 
|---|
| 104 |         virtual size_t calcMeshSize(const Mesh* pMesh); | 
|---|
| 105 |         virtual size_t calcSubMeshSize(const SubMesh* pSub); | 
|---|
| 106 |         virtual size_t calcGeometrySize(const VertexData* pGeom); | 
|---|
| 107 |         virtual size_t calcSkeletonLinkSize(const String& skelName); | 
|---|
| 108 |         virtual size_t calcBoneAssignmentSize(void); | 
|---|
| 109 |         virtual size_t calcSubMeshOperationSize(const SubMesh* pSub); | 
|---|
| 110 |         virtual size_t calcSubMeshNameTableSize(const Mesh* pMesh); | 
|---|
| 111 |         virtual size_t calcEdgeListSize(const Mesh* pMesh); | 
|---|
| 112 |         virtual size_t calcEdgeListLodSize(const EdgeData* data, bool isManual); | 
|---|
| 113 |         virtual size_t calcEdgeGroupSize(const EdgeData::EdgeGroup& group); | 
|---|
| 114 |                 virtual size_t calcPosesSize(const Mesh* pMesh); | 
|---|
| 115 |                 virtual size_t calcPoseSize(const Pose* pose); | 
|---|
| 116 |                 virtual size_t calcAnimationsSize(const Mesh* pMesh); | 
|---|
| 117 |                 virtual size_t calcAnimationSize(const Animation* anim); | 
|---|
| 118 |                 virtual size_t calcAnimationTrackSize(const VertexAnimationTrack* track); | 
|---|
| 119 |                 virtual size_t calcMorphKeyframeSize(const VertexMorphKeyFrame* kf, size_t vertexCount); | 
|---|
| 120 |                 virtual size_t calcPoseKeyframeSize(const VertexPoseKeyFrame* kf); | 
|---|
| 121 |                 virtual size_t calcPoseKeyframePoseRefSize(void); | 
|---|
| 122 |                 virtual size_t calcPoseVertexSize(void); | 
|---|
| 123 |         virtual size_t calcSubMeshTextureAliasesSize(const SubMesh* pSub); | 
|---|
| 124 |  | 
|---|
| 125 |  | 
|---|
| 126 |         virtual void readTextureLayer(DataStreamPtr& stream, Mesh* pMesh, MaterialPtr& pMat); | 
|---|
| 127 |         virtual void readSubMeshNameTable(DataStreamPtr& stream, Mesh* pMesh); | 
|---|
| 128 |         virtual void readMesh(DataStreamPtr& stream, Mesh* pMesh); | 
|---|
| 129 |         virtual void readSubMesh(DataStreamPtr& stream, Mesh* pMesh); | 
|---|
| 130 |         virtual void readSubMeshOperation(DataStreamPtr& stream, Mesh* pMesh, SubMesh* sub); | 
|---|
| 131 |         virtual void readSubMeshTextureAlias(DataStreamPtr& stream, Mesh* pMesh, SubMesh* sub); | 
|---|
| 132 |         virtual void readGeometry(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest); | 
|---|
| 133 |         virtual void readGeometryVertexDeclaration(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest); | 
|---|
| 134 |         virtual void readGeometryVertexElement(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest); | 
|---|
| 135 |         virtual void readGeometryVertexBuffer(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest); | 
|---|
| 136 |  | 
|---|
| 137 |         virtual void readSkeletonLink(DataStreamPtr& stream, Mesh* pMesh); | 
|---|
| 138 |         virtual void readMeshBoneAssignment(DataStreamPtr& stream, Mesh* pMesh); | 
|---|
| 139 |         virtual void readSubMeshBoneAssignment(DataStreamPtr& stream, Mesh* pMesh,  | 
|---|
| 140 |             SubMesh* sub); | 
|---|
| 141 |         virtual void readMeshLodInfo(DataStreamPtr& stream, Mesh* pMesh); | 
|---|
| 142 |         virtual void readMeshLodUsageManual(DataStreamPtr& stream, Mesh* pMesh,  | 
|---|
| 143 |             unsigned short lodNum, MeshLodUsage& usage); | 
|---|
| 144 |         virtual void readMeshLodUsageGenerated(DataStreamPtr& stream, Mesh* pMesh,  | 
|---|
| 145 |             unsigned short lodNum, MeshLodUsage& usage); | 
|---|
| 146 |         virtual void readBoundsInfo(DataStreamPtr& stream, Mesh* pMesh); | 
|---|
| 147 |         virtual void readEdgeList(DataStreamPtr& stream, Mesh* pMesh); | 
|---|
| 148 |         virtual void readEdgeListLodInfo(DataStreamPtr& stream, EdgeData* edgeData); | 
|---|
| 149 |                 virtual void readPoses(DataStreamPtr& stream, Mesh* pMesh); | 
|---|
| 150 |                 virtual void readPose(DataStreamPtr& stream, Mesh* pMesh); | 
|---|
| 151 |                 virtual void readAnimations(DataStreamPtr& stream, Mesh* pMesh); | 
|---|
| 152 |                 virtual void readAnimation(DataStreamPtr& stream, Mesh* pMesh); | 
|---|
| 153 |                 virtual void readAnimationTrack(DataStreamPtr& stream, Animation* anim,  | 
|---|
| 154 |                         Mesh* pMesh); | 
|---|
| 155 |                 virtual void readMorphKeyFrame(DataStreamPtr& stream, VertexAnimationTrack* track); | 
|---|
| 156 |                 virtual void readPoseKeyFrame(DataStreamPtr& stream, VertexAnimationTrack* track); | 
|---|
| 157 |                 virtual void readExtremes(DataStreamPtr& stream, Mesh *pMesh); | 
|---|
| 158 |  | 
|---|
| 159 |  | 
|---|
| 160 |         /// Flip an entire vertex buffer from little endian | 
|---|
| 161 |         virtual void flipFromLittleEndian(void* pData, size_t vertexCount, size_t vertexSize, const VertexDeclaration::VertexElementList& elems); | 
|---|
| 162 |         /// Flip an entire vertex buffer to little endian | 
|---|
| 163 |         virtual void flipToLittleEndian(void* pData, size_t vertexCount, size_t vertexSize, const VertexDeclaration::VertexElementList& elems); | 
|---|
| 164 |         /// Flip the endianness of an entire vertex buffer, passed in as a  | 
|---|
| 165 |         /// pointer to locked or temporary memory  | 
|---|
| 166 |         virtual void flipEndian(void* pData, size_t vertexCount, size_t vertexSize, const VertexDeclaration::VertexElementList& elems); | 
|---|
| 167 |  | 
|---|
| 168 |  | 
|---|
| 169 |  | 
|---|
| 170 |     }; | 
|---|
| 171 |  | 
|---|
| 172 |     /** Class for providing backwards-compatibility for loading version 1.3 of the .mesh format. */ | 
|---|
| 173 |     class _OgrePrivate MeshSerializerImpl_v1_3 : public MeshSerializerImpl | 
|---|
| 174 |     { | 
|---|
| 175 |     public: | 
|---|
| 176 |         MeshSerializerImpl_v1_3(); | 
|---|
| 177 |         ~MeshSerializerImpl_v1_3(); | 
|---|
| 178 |     protected: | 
|---|
| 179 |         virtual void readEdgeListLodInfo(DataStreamPtr& stream, EdgeData* edgeData); | 
|---|
| 180 |  | 
|---|
| 181 |         /// Reorganise triangles of the edge list to group by vertex set | 
|---|
| 182 |         virtual void reorganiseTriangles(EdgeData* edgeData); | 
|---|
| 183 |     }; | 
|---|
| 184 |  | 
|---|
| 185 |     /** Class for providing backwards-compatibility for loading version 1.2 of the .mesh format. */ | 
|---|
| 186 |     class _OgrePrivate MeshSerializerImpl_v1_2 : public MeshSerializerImpl_v1_3 | 
|---|
| 187 |     { | 
|---|
| 188 |     public: | 
|---|
| 189 |         MeshSerializerImpl_v1_2(); | 
|---|
| 190 |         ~MeshSerializerImpl_v1_2(); | 
|---|
| 191 |     protected: | 
|---|
| 192 |         virtual void readMesh(DataStreamPtr& stream, Mesh* pMesh); | 
|---|
| 193 |         virtual void readGeometry(DataStreamPtr& stream, Mesh* pMesh, VertexData* dest); | 
|---|
| 194 |         virtual void readGeometryPositions(unsigned short bindIdx, DataStreamPtr& stream,  | 
|---|
| 195 |             Mesh* pMesh, VertexData* dest); | 
|---|
| 196 |         virtual void readGeometryNormals(unsigned short bindIdx, DataStreamPtr& stream,  | 
|---|
| 197 |             Mesh* pMesh, VertexData* dest); | 
|---|
| 198 |         virtual void readGeometryColours(unsigned short bindIdx, DataStreamPtr& stream,  | 
|---|
| 199 |             Mesh* pMesh, VertexData* dest); | 
|---|
| 200 |         virtual void readGeometryTexCoords(unsigned short bindIdx, DataStreamPtr& stream,  | 
|---|
| 201 |             Mesh* pMesh, VertexData* dest, unsigned short set); | 
|---|
| 202 |     }; | 
|---|
| 203 |  | 
|---|
| 204 |     /** Class for providing backwards-compatibility for loading version 1.1 of the .mesh format. */ | 
|---|
| 205 |     class _OgrePrivate MeshSerializerImpl_v1_1 : public MeshSerializerImpl_v1_2 | 
|---|
| 206 |     { | 
|---|
| 207 |     public: | 
|---|
| 208 |         MeshSerializerImpl_v1_1(); | 
|---|
| 209 |         ~MeshSerializerImpl_v1_1(); | 
|---|
| 210 |     protected: | 
|---|
| 211 |         void readGeometryTexCoords(unsigned short bindIdx, DataStreamPtr& stream,  | 
|---|
| 212 |             Mesh* pMesh, VertexData* dest, unsigned short set); | 
|---|
| 213 |     }; | 
|---|
| 214 |  | 
|---|
| 215 |  | 
|---|
| 216 | } | 
|---|
| 217 |  | 
|---|
| 218 | #endif | 
|---|