| 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 __XMLMeshSerializer_H__ | 
|---|
| 31 | #define __XMLMeshSerializer_H__ | 
|---|
| 32 |  | 
|---|
| 33 | #include "OgreXMLPrerequisites.h" | 
|---|
| 34 | #include "OgreMesh.h" | 
|---|
| 35 |  | 
|---|
| 36 |  | 
|---|
| 37 | namespace Ogre { | 
|---|
| 38 |  | 
|---|
| 39 |     /** Class for serializing a Mesh to/from XML. | 
|---|
| 40 |     @remarks | 
|---|
| 41 |         This class behaves the same way as MeshSerializer in the main project, | 
|---|
| 42 |         but is here to allow conversions to / from XML. This class is  | 
|---|
| 43 |         deliberately not included in the main project because <UL> | 
|---|
| 44 |         <LI>Dependence on Xerces would unnecessarily bloat the main library</LI> | 
|---|
| 45 |         <LI>Runtime use of XML is discouraged because of the parsing overhead</LI></UL> | 
|---|
| 46 |         This class gives people the option of saving out a Mesh as XML for examination | 
|---|
| 47 |         and possible editing. It can then be converted back to the native format | 
|---|
| 48 |         for maximum runtime efficiency. | 
|---|
| 49 |     */ | 
|---|
| 50 |     class XMLMeshSerializer | 
|---|
| 51 |     { | 
|---|
| 52 |     public: | 
|---|
| 53 |  | 
|---|
| 54 |         XMLMeshSerializer(); | 
|---|
| 55 |         virtual ~XMLMeshSerializer(); | 
|---|
| 56 |         /** Imports a Mesh from the given XML file. | 
|---|
| 57 |         @param filename The name of the file to import, expected to be in XML format. | 
|---|
| 58 |                 @param colourElementType The vertex element to use for packed colours | 
|---|
| 59 |         @param pMesh The pre-created Mesh object to be populated. | 
|---|
| 60 |         */ | 
|---|
| 61 |         void importMesh(const String& filename, VertexElementType colourElementType, Mesh* pMesh); | 
|---|
| 62 |  | 
|---|
| 63 |         /** Exports a mesh to the named XML file. */ | 
|---|
| 64 |         void exportMesh(const Mesh* pMesh, const String& filename); | 
|---|
| 65 |  | 
|---|
| 66 |     protected: | 
|---|
| 67 |         // State for export | 
|---|
| 68 |         TiXmlDocument* mXMLDoc; | 
|---|
| 69 |         // State for import | 
|---|
| 70 |         Mesh* mpMesh; | 
|---|
| 71 |                 VertexElementType mColourElementType; | 
|---|
| 72 |  | 
|---|
| 73 |         // Internal methods | 
|---|
| 74 |         void writeMesh(const Mesh* pMesh); | 
|---|
| 75 |         void writeSubMesh(TiXmlElement* mSubmeshesNode, const SubMesh* s); | 
|---|
| 76 |         void writeGeometry(TiXmlElement* mParentNode, const VertexData* pData); | 
|---|
| 77 |         void writeSkeletonLink(TiXmlElement* mMeshNode, const String& skelName); | 
|---|
| 78 |         void writeBoneAssignment(TiXmlElement* mBoneAssignNode, const VertexBoneAssignment* assign); | 
|---|
| 79 |         void writeTextureAliases(TiXmlElement* mSubmeshesNode, const SubMesh* s); | 
|---|
| 80 |                 void writeLodInfo(TiXmlElement* mMeshNode, const Mesh* pMesh); | 
|---|
| 81 |                 void writeLodUsageManual(TiXmlElement* usageNode, unsigned short levelNum,  | 
|---|
| 82 |                         const MeshLodUsage& usage); | 
|---|
| 83 |                 void writeLodUsageGenerated(TiXmlElement* usageNode, unsigned short levelNum,   | 
|---|
| 84 |                         const MeshLodUsage& usage, const Mesh* pMesh); | 
|---|
| 85 |         void writeSubMeshNames(TiXmlElement* mMeshNode, const Mesh* m); | 
|---|
| 86 |                 void writePoses(TiXmlElement* meshNode, const Mesh* m); | 
|---|
| 87 |                 void writeAnimations(TiXmlElement* meshNode, const Mesh* m); | 
|---|
| 88 |                 void writeMorphKeyFrames(TiXmlElement* trackNode, const VertexAnimationTrack* track); | 
|---|
| 89 |                 void writePoseKeyFrames(TiXmlElement* trackNode, const VertexAnimationTrack* track); | 
|---|
| 90 |         void writeExtremes(TiXmlElement* mMeshNode, const Mesh* m); | 
|---|
| 91 |  | 
|---|
| 92 |         void readSubMeshes(TiXmlElement* mSubmeshesNode); | 
|---|
| 93 |         void readGeometry(TiXmlElement* mGeometryNode, VertexData* pData); | 
|---|
| 94 |         void readSkeletonLink(TiXmlElement* mSkelNode); | 
|---|
| 95 |         void readBoneAssignments(TiXmlElement* mBoneAssignmentsNode); | 
|---|
| 96 |         void readBoneAssignments(TiXmlElement* mBoneAssignmentsNode, SubMesh* sm); | 
|---|
| 97 |         void readTextureAliases(TiXmlElement* mTextureAliasesNode, SubMesh* sm); | 
|---|
| 98 |                 void readLodInfo(TiXmlElement*  lodNode); | 
|---|
| 99 |                 void readLodUsageManual(TiXmlElement* manualNode, unsigned short index); | 
|---|
| 100 |                 void readLodUsageGenerated(TiXmlElement* genNode, unsigned short index); | 
|---|
| 101 |                 void readSubMeshNames(TiXmlElement* mMeshNamesNode, Mesh* sm); | 
|---|
| 102 |                 void readPoses(TiXmlElement* posesNode, Mesh *m); | 
|---|
| 103 |                 void readAnimations(TiXmlElement* mAnimationsNode, Mesh *m); | 
|---|
| 104 |                 void readTracks(TiXmlElement* tracksNode, Mesh *m, Animation* anim); | 
|---|
| 105 |                 void readMorphKeyFrames(TiXmlElement* keyframesNode, VertexAnimationTrack* track,  | 
|---|
| 106 |                         size_t vertexCount); | 
|---|
| 107 |                 void readPoseKeyFrames(TiXmlElement* keyframesNode, VertexAnimationTrack* track); | 
|---|
| 108 |         void readExtremes(TiXmlElement* extremesNode, Mesh *m); | 
|---|
| 109 |     }; | 
|---|
| 110 | } | 
|---|
| 111 |  | 
|---|
| 112 | #endif | 
|---|