| [148] | 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 __SkeletonSerializer_H__ |
|---|
| 30 | #define __SkeletonSerializer_H__ |
|---|
| 31 | |
|---|
| 32 | #include "OgrePrerequisites.h" |
|---|
| 33 | #include "OgreSkeleton.h" |
|---|
| 34 | #include "OgreSerializer.h" |
|---|
| 35 | |
|---|
| 36 | namespace Ogre { |
|---|
| 37 | |
|---|
| 38 | /// Skeleton compatibility versions |
|---|
| 39 | enum SkeletonVersion |
|---|
| 40 | { |
|---|
| 41 | /// OGRE version v1.0+ |
|---|
| 42 | SKELETON_VERSION_1_0, |
|---|
| 43 | /// OGRE version v1.8+ |
|---|
| 44 | SKELETON_VERSION_1_8, |
|---|
| 45 | |
|---|
| 46 | /// Latest version available |
|---|
| 47 | SKELETON_VERSION_LATEST = 100 |
|---|
| 48 | }; |
|---|
| 49 | |
|---|
| 50 | /** \addtogroup Core |
|---|
| 51 | * @{ |
|---|
| 52 | */ |
|---|
| 53 | /** \addtogroup Animation |
|---|
| 54 | * @{ |
|---|
| 55 | */ |
|---|
| 56 | /** Class for serialising skeleton data to/from an OGRE .skeleton file. |
|---|
| 57 | @remarks |
|---|
| 58 | This class allows exporters to write OGRE .skeleton files easily, and allows the |
|---|
| 59 | OGRE engine to import .skeleton files into instantiated OGRE Skeleton objects. |
|---|
| 60 | Note that a .skeleton file includes not only the Skeleton, but also definitions of |
|---|
| 61 | any Animations it uses. |
|---|
| 62 | @par |
|---|
| 63 | To export a Skeleton:<OL> |
|---|
| 64 | <LI>Create a Skeleton object and populate it using it's methods.</LI> |
|---|
| 65 | <LI>Call the exportSkeleton method</LI> |
|---|
| 66 | </OL> |
|---|
| 67 | */ |
|---|
| 68 | class _OgreExport SkeletonSerializer : public Serializer |
|---|
| 69 | { |
|---|
| 70 | |
|---|
| 71 | public: |
|---|
| 72 | SkeletonSerializer(); |
|---|
| 73 | virtual ~SkeletonSerializer(); |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | /** Exports a skeleton to the file specified. |
|---|
| 77 | @remarks |
|---|
| 78 | This method takes an externally created Skeleton object, and exports both it |
|---|
| 79 | and animations it uses to a .skeleton file. |
|---|
| 80 | @param pSkeleton Weak reference to the Skeleton to export |
|---|
| 81 | @param filename The destination filename |
|---|
| 82 | @param endianMode The endian mode to write in |
|---|
| 83 | */ |
|---|
| 84 | void exportSkeleton(const Skeleton* pSkeleton, const String& filename, |
|---|
| 85 | SkeletonVersion ver = SKELETON_VERSION_LATEST, Endian endianMode = ENDIAN_NATIVE); |
|---|
| 86 | |
|---|
| 87 | /** Exports a skeleton to the stream specified. |
|---|
| 88 | @remarks |
|---|
| 89 | This method takes an externally created Skeleton object, and exports both it |
|---|
| 90 | and animations it uses to a .skeleton file. |
|---|
| 91 | @param pSkeleton Weak reference to the Skeleton to export |
|---|
| 92 | @param stream The destination stream |
|---|
| 93 | @param endianMode The endian mode to write in |
|---|
| 94 | */ |
|---|
| 95 | void exportSkeleton(const Skeleton* pSkeleton, DataStreamPtr stream, |
|---|
| 96 | SkeletonVersion ver = SKELETON_VERSION_LATEST, Endian endianMode = ENDIAN_NATIVE); |
|---|
| 97 | /** Imports Skeleton and animation data from a .skeleton file DataStream. |
|---|
| 98 | @remarks |
|---|
| 99 | This method imports data from a DataStream opened from a .skeleton file and places it's |
|---|
| 100 | contents into the Skeleton object which is passed in. |
|---|
| 101 | @param stream The DataStream holding the .skeleton data. Must be initialised (pos at the start of the buffer). |
|---|
| 102 | @param pDest Weak reference to the Skeleton object which will receive the data. Should be blank already. |
|---|
| 103 | */ |
|---|
| 104 | void importSkeleton(DataStreamPtr& stream, Skeleton* pDest); |
|---|
| 105 | |
|---|
| 106 | // TODO: provide Cal3D importer? |
|---|
| 107 | |
|---|
| 108 | protected: |
|---|
| 109 | |
|---|
| 110 | void setWorkingVersion(SkeletonVersion ver); |
|---|
| 111 | |
|---|
| 112 | // Internal export methods |
|---|
| 113 | void writeSkeleton(const Skeleton* pSkel, SkeletonVersion ver); |
|---|
| 114 | void writeBone(const Skeleton* pSkel, const Bone* pBone); |
|---|
| 115 | void writeBoneParent(const Skeleton* pSkel, unsigned short boneId, unsigned short parentId); |
|---|
| 116 | void writeAnimation(const Skeleton* pSkel, const Animation* anim, SkeletonVersion ver); |
|---|
| 117 | void writeAnimationTrack(const Skeleton* pSkel, const NodeAnimationTrack* track); |
|---|
| 118 | void writeKeyFrame(const Skeleton* pSkel, const TransformKeyFrame* key); |
|---|
| 119 | void writeSkeletonAnimationLink(const Skeleton* pSkel, |
|---|
| 120 | const LinkedSkeletonAnimationSource& link); |
|---|
| 121 | |
|---|
| 122 | // Internal import methods |
|---|
| 123 | void readFileHeader(DataStreamPtr& stream); |
|---|
| 124 | void readBone(DataStreamPtr& stream, Skeleton* pSkel); |
|---|
| 125 | void readBoneParent(DataStreamPtr& stream, Skeleton* pSkel); |
|---|
| 126 | void readAnimation(DataStreamPtr& stream, Skeleton* pSkel); |
|---|
| 127 | void readAnimationTrack(DataStreamPtr& stream, Animation* anim, Skeleton* pSkel); |
|---|
| 128 | void readKeyFrame(DataStreamPtr& stream, NodeAnimationTrack* track, Skeleton* pSkel); |
|---|
| 129 | void readSkeletonAnimationLink(DataStreamPtr& stream, Skeleton* pSkel); |
|---|
| 130 | |
|---|
| 131 | size_t calcBoneSize(const Skeleton* pSkel, const Bone* pBone); |
|---|
| 132 | size_t calcBoneSizeWithoutScale(const Skeleton* pSkel, const Bone* pBone); |
|---|
| 133 | size_t calcBoneParentSize(const Skeleton* pSkel); |
|---|
| 134 | size_t calcAnimationSize(const Skeleton* pSkel, const Animation* pAnim); |
|---|
| 135 | size_t calcAnimationTrackSize(const Skeleton* pSkel, const NodeAnimationTrack* pTrack); |
|---|
| 136 | size_t calcKeyFrameSize(const Skeleton* pSkel, const TransformKeyFrame* pKey); |
|---|
| 137 | size_t calcKeyFrameSizeWithoutScale(const Skeleton* pSkel, const TransformKeyFrame* pKey); |
|---|
| 138 | size_t calcSkeletonAnimationLinkSize(const Skeleton* pSkel, |
|---|
| 139 | const LinkedSkeletonAnimationSource& link); |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | }; |
|---|
| 145 | /** @} */ |
|---|
| 146 | /** @} */ |
|---|
| 147 | |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | #endif |
|---|