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-2013 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 __XMLSkeletonSerializer_H__
30 #define __XMLSkeletonSerializer_H__
31 
32 #include "OgreXMLPrerequisites.h"
33 #include "OgreMaterial.h"
34 #include "OgreSkeleton.h"
35 
36 
37 namespace Ogre {
38 
39     /** Class for serializing a Skeleton to/from XML.
40     @remarks
41         This class behaves the same way as SkeletonSerializer 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 Skeleton 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 XMLSkeletonSerializer
51     {
52     public:
53 
54         XMLSkeletonSerializer();
55         virtual ~XMLSkeletonSerializer();
56         /** Imports a Skeleton from the given XML file.
57         @param filename The name of the file to import, expected to be in XML format.
58         @param pSkeleton The pre-created Skeleton object to be populated.
59         */
60         void importSkeleton(const String& filename, Skeleton* pSkeleton);
61 
62         /** Exports a skeleton to the named XML file. */
63         void exportSkeleton(const Skeleton* pSkeleton, const String& filename);
64 
65     private:
66         // State for export
67         TiXmlDocument* mXMLDoc;
68 
69         void writeSkeleton(const Skeleton* pSkel);
70         void writeBone(TiXmlElement* bonesElement, const Bone* pBone);
71         void writeBoneParent(TiXmlElement* boneHierarchyNode, String boneName , String parentName);
72         void writeAnimation(TiXmlElement* animsNode, const Animation* anim);
73         void writeAnimationTrack(TiXmlElement* tracksNode,
74 			const NodeAnimationTrack* track);
75         void writeKeyFrame(TiXmlElement* keysNode, const TransformKeyFrame* key);
76 		void writeSkeletonAnimationLink(TiXmlElement* linksNode,
77 			const LinkedSkeletonAnimationSource& link);
78 
79 		void readBones(Skeleton* skel, TiXmlElement* mBonesNode);
80 		void readBones2(Skeleton* skel, TiXmlElement* mBonesNode);
81 		void createHierarchy(Skeleton* skel, TiXmlElement* mHierNode);
82 		void readKeyFrames(NodeAnimationTrack* track, TiXmlElement* mKeyfNode);
83 		void readAnimations(Skeleton* skel, TiXmlElement* mAnimNode) ;
84 		void readSkeletonAnimationLinks(Skeleton* skel, TiXmlElement* linksNode);
85 
86     };
87 
88 
89 }
90 
91 #endif
92 
93