[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 __Animation_H__ |
---|
| 30 | #define __Animation_H__ |
---|
| 31 | |
---|
| 32 | #include "OgrePrerequisites.h" |
---|
| 33 | #include "OgreString.h" |
---|
| 34 | #include "OgreIteratorWrappers.h" |
---|
| 35 | #include "OgreAnimable.h" |
---|
| 36 | #include "OgreAnimationTrack.h" |
---|
| 37 | #include "OgreAnimationState.h" |
---|
| 38 | #include "OgreHeaderPrefix.h" |
---|
| 39 | |
---|
| 40 | namespace Ogre { |
---|
| 41 | /** \addtogroup Core |
---|
| 42 | * @{ |
---|
| 43 | */ |
---|
| 44 | |
---|
| 45 | /** \addtogroup Animation |
---|
| 46 | * @{ |
---|
| 47 | */ |
---|
| 48 | |
---|
| 49 | class Animation; |
---|
| 50 | |
---|
| 51 | /** An animation container interface, which allows generic access to sibling animations. |
---|
| 52 | @remarks |
---|
| 53 | Because Animation instances can be held by different kinds of classes, and |
---|
| 54 | there are sometimes instances when you need to reference other Animation |
---|
| 55 | instances within the same container, this class allows generic access to |
---|
| 56 | named animations within that container, whatever it may be. |
---|
| 57 | */ |
---|
| 58 | class _OgreExport AnimationContainer |
---|
| 59 | { |
---|
| 60 | public: |
---|
| 61 | virtual ~AnimationContainer() {} |
---|
| 62 | |
---|
| 63 | /** Gets the number of animations in this container. */ |
---|
| 64 | virtual unsigned short getNumAnimations(void) const = 0; |
---|
| 65 | |
---|
| 66 | /** Retrieve an animation by index. */ |
---|
| 67 | virtual Animation* getAnimation(unsigned short index) const = 0; |
---|
| 68 | |
---|
| 69 | /** Retrieve an animation by name. */ |
---|
| 70 | virtual Animation* getAnimation(const String& name) const = 0; |
---|
| 71 | |
---|
| 72 | /** Create a new animation with a given length owned by this container. */ |
---|
| 73 | virtual Animation* createAnimation(const String& name, Real length) = 0; |
---|
| 74 | |
---|
| 75 | /** Returns whether this object contains the named animation. */ |
---|
| 76 | virtual bool hasAnimation(const String& name) const = 0; |
---|
| 77 | |
---|
| 78 | /** Removes an Animation from this container. */ |
---|
| 79 | virtual void removeAnimation(const String& name) = 0; |
---|
| 80 | |
---|
| 81 | }; |
---|
| 82 | /** An animation sequence. |
---|
| 83 | @remarks |
---|
| 84 | This class defines the interface for a sequence of animation, whether that |
---|
| 85 | be animation of a mesh, a path along a spline, or possibly more than one |
---|
| 86 | type of animation in one. An animation is made up of many 'tracks', which are |
---|
| 87 | the more specific types of animation. |
---|
| 88 | @par |
---|
| 89 | You should not create these animations directly. They will be created via a parent |
---|
| 90 | object which owns the animation, e.g. Skeleton. |
---|
| 91 | */ |
---|
| 92 | class _OgreExport Animation : public AnimationAlloc |
---|
| 93 | { |
---|
| 94 | |
---|
| 95 | public: |
---|
| 96 | /** The types of animation interpolation available. */ |
---|
| 97 | enum InterpolationMode |
---|
| 98 | { |
---|
| 99 | /** Values are interpolated along straight lines. */ |
---|
| 100 | IM_LINEAR, |
---|
| 101 | /** Values are interpolated along a spline, resulting in smoother changes in direction. */ |
---|
| 102 | IM_SPLINE |
---|
| 103 | }; |
---|
| 104 | |
---|
| 105 | /** The types of rotational interpolation available. */ |
---|
| 106 | enum RotationInterpolationMode |
---|
| 107 | { |
---|
| 108 | /** Values are interpolated linearly. This is faster but does not |
---|
| 109 | necessarily give a completely accurate result. |
---|
| 110 | */ |
---|
| 111 | RIM_LINEAR, |
---|
| 112 | /** Values are interpolated spherically. This is more accurate but |
---|
| 113 | has a higher cost. |
---|
| 114 | */ |
---|
| 115 | RIM_SPHERICAL |
---|
| 116 | }; |
---|
| 117 | /** You should not use this constructor directly, use the parent object such as Skeleton instead. |
---|
| 118 | @param name The name of the animation, should be unique within it's parent (e.g. Skeleton) |
---|
| 119 | @param length The length of the animation in seconds. |
---|
| 120 | */ |
---|
| 121 | Animation(const String& name, Real length); |
---|
| 122 | virtual ~Animation(); |
---|
| 123 | |
---|
| 124 | /** Gets the name of this animation. */ |
---|
| 125 | const String& getName(void) const; |
---|
| 126 | |
---|
| 127 | /** Gets the total length of the animation. */ |
---|
| 128 | Real getLength(void) const; |
---|
| 129 | |
---|
| 130 | /** Sets the length of the animation. |
---|
| 131 | @note Changing the length of an animation may invalidate existing AnimationState |
---|
| 132 | instances which will need to be recreated. |
---|
| 133 | */ |
---|
| 134 | void setLength(Real len); |
---|
| 135 | |
---|
| 136 | /** Creates a NodeAnimationTrack for animating a Node. |
---|
| 137 | @param handle Handle to give the track, used for accessing the track later. |
---|
| 138 | Must be unique within this Animation. |
---|
| 139 | */ |
---|
| 140 | NodeAnimationTrack* createNodeTrack(unsigned short handle); |
---|
| 141 | |
---|
| 142 | /** Creates a NumericAnimationTrack for animating any numeric value. |
---|
| 143 | @param handle Handle to give the track, used for accessing the track later. |
---|
| 144 | Must be unique within this Animation. |
---|
| 145 | */ |
---|
| 146 | NumericAnimationTrack* createNumericTrack(unsigned short handle); |
---|
| 147 | |
---|
| 148 | /** Creates a VertexAnimationTrack for animating vertex position data. |
---|
| 149 | @param handle Handle to give the track, used for accessing the track later. |
---|
| 150 | Must be unique within this Animation, and is used to identify the target. For example |
---|
| 151 | when applied to a Mesh, the handle must reference the index of the geometry being |
---|
| 152 | modified; 0 for the shared geometry, and 1+ for SubMesh geometry with the same index-1. |
---|
| 153 | @param animType Either morph or pose animation, |
---|
| 154 | */ |
---|
| 155 | VertexAnimationTrack* createVertexTrack(unsigned short handle, VertexAnimationType animType); |
---|
| 156 | |
---|
| 157 | /** Creates a new AnimationTrack automatically associated with a Node. |
---|
| 158 | @remarks |
---|
| 159 | This method creates a standard AnimationTrack, but also associates it with a |
---|
| 160 | target Node which will receive all keyframe effects. |
---|
| 161 | @param handle Numeric handle to give the track, used for accessing the track later. |
---|
| 162 | Must be unique within this Animation. |
---|
| 163 | @param node A pointer to the Node object which will be affected by this track |
---|
| 164 | */ |
---|
| 165 | NodeAnimationTrack* createNodeTrack(unsigned short handle, Node* node); |
---|
| 166 | |
---|
| 167 | /** Creates a NumericAnimationTrack and associates it with an animable. |
---|
| 168 | @param handle Handle to give the track, used for accessing the track later. |
---|
| 169 | @param anim Animable object link |
---|
| 170 | Must be unique within this Animation. |
---|
| 171 | */ |
---|
| 172 | NumericAnimationTrack* createNumericTrack(unsigned short handle, |
---|
| 173 | const AnimableValuePtr& anim); |
---|
| 174 | |
---|
| 175 | /** Creates a VertexAnimationTrack and associates it with VertexData. |
---|
| 176 | @param handle Handle to give the track, used for accessing the track later. |
---|
| 177 | @param data VertexData object link |
---|
| 178 | @param animType The animation type |
---|
| 179 | Must be unique within this Animation. |
---|
| 180 | */ |
---|
| 181 | VertexAnimationTrack* createVertexTrack(unsigned short handle, |
---|
| 182 | VertexData* data, VertexAnimationType animType); |
---|
| 183 | |
---|
| 184 | /** Gets the number of NodeAnimationTrack objects contained in this animation. */ |
---|
| 185 | unsigned short getNumNodeTracks(void) const; |
---|
| 186 | |
---|
| 187 | /** Gets a node track by it's handle. */ |
---|
| 188 | NodeAnimationTrack* getNodeTrack(unsigned short handle) const; |
---|
| 189 | |
---|
| 190 | /** Does a track exist with the given handle? */ |
---|
| 191 | bool hasNodeTrack(unsigned short handle) const; |
---|
| 192 | |
---|
| 193 | /** Gets the number of NumericAnimationTrack objects contained in this animation. */ |
---|
| 194 | unsigned short getNumNumericTracks(void) const; |
---|
| 195 | |
---|
| 196 | /** Gets a numeric track by it's handle. */ |
---|
| 197 | NumericAnimationTrack* getNumericTrack(unsigned short handle) const; |
---|
| 198 | |
---|
| 199 | /** Does a track exist with the given handle? */ |
---|
| 200 | bool hasNumericTrack(unsigned short handle) const; |
---|
| 201 | |
---|
| 202 | /** Gets the number of VertexAnimationTrack objects contained in this animation. */ |
---|
| 203 | unsigned short getNumVertexTracks(void) const; |
---|
| 204 | |
---|
| 205 | /** Gets a Vertex track by it's handle. */ |
---|
| 206 | VertexAnimationTrack* getVertexTrack(unsigned short handle) const; |
---|
| 207 | |
---|
| 208 | /** Does a track exist with the given handle? */ |
---|
| 209 | bool hasVertexTrack(unsigned short handle) const; |
---|
| 210 | |
---|
| 211 | /** Destroys the node track with the given handle. */ |
---|
| 212 | void destroyNodeTrack(unsigned short handle); |
---|
| 213 | |
---|
| 214 | /** Destroys the numeric track with the given handle. */ |
---|
| 215 | void destroyNumericTrack(unsigned short handle); |
---|
| 216 | |
---|
| 217 | /** Destroys the Vertex track with the given handle. */ |
---|
| 218 | void destroyVertexTrack(unsigned short handle); |
---|
| 219 | |
---|
| 220 | /** Removes and destroys all tracks making up this animation. */ |
---|
| 221 | void destroyAllTracks(void); |
---|
| 222 | |
---|
| 223 | /** Removes and destroys all tracks making up this animation. */ |
---|
| 224 | void destroyAllNodeTracks(void); |
---|
| 225 | /** Removes and destroys all tracks making up this animation. */ |
---|
| 226 | void destroyAllNumericTracks(void); |
---|
| 227 | /** Removes and destroys all tracks making up this animation. */ |
---|
| 228 | void destroyAllVertexTracks(void); |
---|
| 229 | |
---|
| 230 | /** Applies an animation given a specific time point and weight. |
---|
| 231 | @remarks |
---|
| 232 | Where you have associated animation tracks with objects, you can easily apply |
---|
| 233 | an animation to those objects by calling this method. |
---|
| 234 | @param timePos The time position in the animation to apply. |
---|
| 235 | @param weight The influence to give to this track, 1.0 for full influence, less to blend with |
---|
| 236 | other animations. |
---|
| 237 | @param scale The scale to apply to translations and scalings, useful for |
---|
| 238 | adapting an animation to a different size target. |
---|
| 239 | */ |
---|
| 240 | void apply(Real timePos, Real weight = 1.0, Real scale = 1.0f); |
---|
| 241 | |
---|
| 242 | /** Applies all node tracks given a specific time point and weight to the specified node. |
---|
| 243 | @remarks |
---|
| 244 | It does not consider the actual node tracks are attached to. |
---|
| 245 | As such, it resembles the apply method for a given skeleton (see below). |
---|
| 246 | @param timePos The time position in the animation to apply. |
---|
| 247 | @param weight The influence to give to this track, 1.0 for full influence, less to blend with |
---|
| 248 | other animations. |
---|
| 249 | @param scale The scale to apply to translations and scalings, useful for |
---|
| 250 | adapting an animation to a different size target. |
---|
| 251 | */ |
---|
| 252 | void applyToNode(Node* node, Real timePos, Real weight = 1.0, Real scale = 1.0f); |
---|
| 253 | |
---|
| 254 | /** Applies all node tracks given a specific time point and weight to a given skeleton. |
---|
| 255 | @remarks |
---|
| 256 | Where you have associated animation tracks with Node objects, you can easily apply |
---|
| 257 | an animation to those nodes by calling this method. |
---|
| 258 | @param timePos The time position in the animation to apply. |
---|
| 259 | @param weight The influence to give to this track, 1.0 for full influence, less to blend with |
---|
| 260 | other animations. |
---|
| 261 | @param scale The scale to apply to translations and scalings, useful for |
---|
| 262 | adapting an animation to a different size target. |
---|
| 263 | */ |
---|
| 264 | void apply(Skeleton* skeleton, Real timePos, Real weight = 1.0, Real scale = 1.0f); |
---|
| 265 | |
---|
| 266 | /** Applies all node tracks given a specific time point and weight to a given skeleton. |
---|
| 267 | @remarks |
---|
| 268 | Where you have associated animation tracks with Node objects, you can easily apply |
---|
| 269 | an animation to those nodes by calling this method. |
---|
| 270 | @param timePos The time position in the animation to apply. |
---|
| 271 | @param weight The influence to give to this track, 1.0 for full influence, less to blend with |
---|
| 272 | other animations. |
---|
| 273 | @param blendMask The influence array defining additional per bone weights. These will |
---|
| 274 | be modulated with the weight factor. |
---|
| 275 | @param scale The scale to apply to translations and scalings, useful for |
---|
| 276 | adapting an animation to a different size target. |
---|
| 277 | */ |
---|
| 278 | void apply(Skeleton* skeleton, Real timePos, float weight, |
---|
| 279 | const AnimationState::BoneBlendMask* blendMask, Real scale); |
---|
| 280 | |
---|
| 281 | /** Applies all vertex tracks given a specific time point and weight to a given entity. |
---|
| 282 | @param entity The Entity to which this animation should be applied |
---|
| 283 | @param timePos The time position in the animation to apply. |
---|
| 284 | @param weight The weight at which the animation should be applied |
---|
| 285 | (only affects pose animation) |
---|
| 286 | @param software Whether to populate the software morph vertex data |
---|
| 287 | @param hardware Whether to populate the hardware morph vertex data |
---|
| 288 | */ |
---|
| 289 | void apply(Entity* entity, Real timePos, Real weight, bool software, |
---|
| 290 | bool hardware); |
---|
| 291 | |
---|
| 292 | /** Applies all numeric tracks given a specific time point and weight to the specified animable value. |
---|
| 293 | @remarks |
---|
| 294 | It does not applies to actual attached animable values but rather uses all tracks for a single animable value. |
---|
| 295 | @param timePos The time position in the animation to apply. |
---|
| 296 | @param weight The influence to give to this track, 1.0 for full influence, less to blend with |
---|
| 297 | other animations. |
---|
| 298 | @param scale The scale to apply to translations and scalings, useful for |
---|
| 299 | adapting an animation to a different size target. |
---|
| 300 | */ |
---|
| 301 | void applyToAnimable(const AnimableValuePtr& anim, Real timePos, Real weight = 1.0, Real scale = 1.0f); |
---|
| 302 | |
---|
| 303 | /** Applies all vertex tracks given a specific time point and weight to the specified vertex data. |
---|
| 304 | @remarks |
---|
| 305 | It does not apply to the actual attached vertex data but rather uses all tracks for a given vertex data. |
---|
| 306 | @param timePos The time position in the animation to apply. |
---|
| 307 | @param weight The influence to give to this track, 1.0 for full influence, less to blend with |
---|
| 308 | other animations. |
---|
| 309 | */ |
---|
| 310 | void applyToVertexData(VertexData* data, Real timePos, Real weight = 1.0); |
---|
| 311 | |
---|
| 312 | /** Tells the animation how to interpolate between keyframes. |
---|
| 313 | @remarks |
---|
| 314 | By default, animations normally interpolate linearly between keyframes. This is |
---|
| 315 | fast, but when animations include quick changes in direction it can look a little |
---|
| 316 | unnatural because directions change instantly at keyframes. An alternative is to |
---|
| 317 | tell the animation to interpolate along a spline, which is more expensive in terms |
---|
| 318 | of calculation time, but looks smoother because major changes in direction are |
---|
| 319 | distributed around the keyframes rather than just at the keyframe. |
---|
| 320 | @par |
---|
| 321 | You can also change the default animation behaviour by calling |
---|
| 322 | Animation::setDefaultInterpolationMode. |
---|
| 323 | */ |
---|
| 324 | void setInterpolationMode(InterpolationMode im); |
---|
| 325 | |
---|
| 326 | /** Gets the current interpolation mode of this animation. |
---|
| 327 | @remarks |
---|
| 328 | See setInterpolationMode for more info. |
---|
| 329 | */ |
---|
| 330 | InterpolationMode getInterpolationMode(void) const; |
---|
| 331 | /** Tells the animation how to interpolate rotations. |
---|
| 332 | @remarks |
---|
| 333 | By default, animations interpolate linearly between rotations. This |
---|
| 334 | is fast but not necessarily completely accurate. If you want more |
---|
| 335 | accurate interpolation, use spherical interpolation, but be aware |
---|
| 336 | that it will incur a higher cost. |
---|
| 337 | @par |
---|
| 338 | You can also change the default rotation behaviour by calling |
---|
| 339 | Animation::setDefaultRotationInterpolationMode. |
---|
| 340 | */ |
---|
| 341 | void setRotationInterpolationMode(RotationInterpolationMode im); |
---|
| 342 | |
---|
| 343 | /** Gets the current rotation interpolation mode of this animation. |
---|
| 344 | @remarks |
---|
| 345 | See setRotationInterpolationMode for more info. |
---|
| 346 | */ |
---|
| 347 | RotationInterpolationMode getRotationInterpolationMode(void) const; |
---|
| 348 | |
---|
| 349 | // Methods for setting the defaults |
---|
| 350 | /** Sets the default animation interpolation mode. |
---|
| 351 | @remarks |
---|
| 352 | Every animation created after this option is set will have the new interpolation |
---|
| 353 | mode specified. You can also change the mode per animation by calling the |
---|
| 354 | setInterpolationMode method on the instance in question. |
---|
| 355 | */ |
---|
| 356 | static void setDefaultInterpolationMode(InterpolationMode im); |
---|
| 357 | |
---|
| 358 | /** Gets the default interpolation mode for all animations. */ |
---|
| 359 | static InterpolationMode getDefaultInterpolationMode(void); |
---|
| 360 | |
---|
| 361 | /** Sets the default rotation interpolation mode. |
---|
| 362 | @remarks |
---|
| 363 | Every animation created after this option is set will have the new interpolation |
---|
| 364 | mode specified. You can also change the mode per animation by calling the |
---|
| 365 | setInterpolationMode method on the instance in question. |
---|
| 366 | */ |
---|
| 367 | static void setDefaultRotationInterpolationMode(RotationInterpolationMode im); |
---|
| 368 | |
---|
| 369 | /** Gets the default rotation interpolation mode for all animations. */ |
---|
| 370 | static RotationInterpolationMode getDefaultRotationInterpolationMode(void); |
---|
| 371 | |
---|
| 372 | typedef map<unsigned short, NodeAnimationTrack*>::type NodeTrackList; |
---|
| 373 | typedef ConstMapIterator<NodeTrackList> NodeTrackIterator; |
---|
| 374 | |
---|
| 375 | typedef map<unsigned short, NumericAnimationTrack*>::type NumericTrackList; |
---|
| 376 | typedef ConstMapIterator<NumericTrackList> NumericTrackIterator; |
---|
| 377 | |
---|
| 378 | typedef map<unsigned short, VertexAnimationTrack*>::type VertexTrackList; |
---|
| 379 | typedef ConstMapIterator<VertexTrackList> VertexTrackIterator; |
---|
| 380 | |
---|
| 381 | /// Fast access to NON-UPDATEABLE node track list |
---|
| 382 | const NodeTrackList& _getNodeTrackList(void) const; |
---|
| 383 | |
---|
| 384 | /// Get non-updateable iterator over node tracks |
---|
| 385 | NodeTrackIterator getNodeTrackIterator(void) const |
---|
| 386 | { return NodeTrackIterator(mNodeTrackList.begin(), mNodeTrackList.end()); } |
---|
| 387 | |
---|
| 388 | /// Fast access to NON-UPDATEABLE numeric track list |
---|
| 389 | const NumericTrackList& _getNumericTrackList(void) const; |
---|
| 390 | |
---|
| 391 | /// Get non-updateable iterator over node tracks |
---|
| 392 | NumericTrackIterator getNumericTrackIterator(void) const |
---|
| 393 | { return NumericTrackIterator(mNumericTrackList.begin(), mNumericTrackList.end()); } |
---|
| 394 | |
---|
| 395 | /// Fast access to NON-UPDATEABLE Vertex track list |
---|
| 396 | const VertexTrackList& _getVertexTrackList(void) const; |
---|
| 397 | |
---|
| 398 | /// Get non-updateable iterator over node tracks |
---|
| 399 | VertexTrackIterator getVertexTrackIterator(void) const |
---|
| 400 | { return VertexTrackIterator(mVertexTrackList.begin(), mVertexTrackList.end()); } |
---|
| 401 | |
---|
| 402 | /** Optimise an animation by removing unnecessary tracks and keyframes. |
---|
| 403 | @remarks |
---|
| 404 | When you export an animation, it is possible that certain tracks |
---|
| 405 | have been keyframed but actually don't include anything useful - the |
---|
| 406 | keyframes include no transformation. These tracks can be completely |
---|
| 407 | eliminated from the animation and thus speed up the animation. |
---|
| 408 | In addition, if several keyframes in a row have the same value, |
---|
| 409 | then they are just adding overhead and can be removed. |
---|
| 410 | @note |
---|
| 411 | Since track-less and identity track has difference behavior for |
---|
| 412 | accumulate animation blending if corresponding track presenting at |
---|
| 413 | other animation that is non-identity, and in normally this method |
---|
| 414 | didn't known about the situation of other animation, it can't deciding |
---|
| 415 | whether or not discards identity tracks. So there have a parameter |
---|
| 416 | allow you choose what you want, in case you aren't sure how to do that, |
---|
| 417 | you should use Skeleton::optimiseAllAnimations instead. |
---|
| 418 | @param |
---|
| 419 | discardIdentityNodeTracks If true, discard identity node tracks. |
---|
| 420 | */ |
---|
| 421 | void optimise(bool discardIdentityNodeTracks = true); |
---|
| 422 | |
---|
| 423 | /// A list of track handles |
---|
| 424 | typedef set<ushort>::type TrackHandleList; |
---|
| 425 | |
---|
| 426 | /** Internal method for collecting identity node tracks. |
---|
| 427 | @remarks |
---|
| 428 | This method remove non-identity node tracks form the track handle list. |
---|
| 429 | @param |
---|
| 430 | tracks A list of track handle of non-identity node tracks, where this |
---|
| 431 | method will remove non-identity node track handles. |
---|
| 432 | */ |
---|
| 433 | void _collectIdentityNodeTracks(TrackHandleList& tracks) const; |
---|
| 434 | |
---|
| 435 | /** Internal method for destroy given node tracks. |
---|
| 436 | */ |
---|
| 437 | void _destroyNodeTracks(const TrackHandleList& tracks); |
---|
| 438 | |
---|
| 439 | /** Clone this animation. |
---|
| 440 | @note |
---|
| 441 | The pointer returned from this method is the only one recorded, |
---|
| 442 | thus it is up to the caller to arrange for the deletion of this |
---|
| 443 | object. |
---|
| 444 | */ |
---|
| 445 | Animation* clone(const String& newName) const; |
---|
| 446 | |
---|
| 447 | /** Internal method used to tell the animation that keyframe list has been |
---|
| 448 | changed, which may cause it to rebuild some internal data */ |
---|
| 449 | void _keyFrameListChanged(void) { mKeyFrameTimesDirty = true; } |
---|
| 450 | |
---|
| 451 | /** Internal method used to convert time position to time index object. |
---|
| 452 | @note |
---|
| 453 | The time index returns by this function are associated with state of |
---|
| 454 | the animation object, if the animation object altered (e.g. create/remove |
---|
| 455 | keyframe or track), all related time index will invalidated. |
---|
| 456 | @param timePos The time position. |
---|
| 457 | @return The time index object which contains wrapped time position (in |
---|
| 458 | relation to the whole animation sequence) and lower bound index of |
---|
| 459 | global keyframe time list. |
---|
| 460 | */ |
---|
| 461 | TimeIndex _getTimeIndex(Real timePos) const; |
---|
| 462 | |
---|
| 463 | /** Sets a base keyframe which for the skeletal / pose keyframes |
---|
| 464 | in this animation. |
---|
| 465 | @remarks |
---|
| 466 | Skeletal and pose animation keyframes are expressed as deltas from a |
---|
| 467 | given base state. By default, that is the binding setup of the skeleton, |
---|
| 468 | or the object space mesh positions for pose animation. However, sometimes |
---|
| 469 | it is useful for animators to create animations with a different starting |
---|
| 470 | pose, because that's more convenient, and the animation is designed to |
---|
| 471 | simply be added to the existing animation state and not globally averaged |
---|
| 472 | with other animations (this is always the case with pose animations, but |
---|
| 473 | is activated for skeletal animations via ANIMBLEND_CUMULATIVE). |
---|
| 474 | @par |
---|
| 475 | In order for this to work, the keyframes need to be 're-based' against |
---|
| 476 | this new starting state, for example by treating the first keyframe as |
---|
| 477 | the reference point (and therefore representing no change). This can |
---|
| 478 | be achieved by applying the inverse of this reference keyframe against |
---|
| 479 | all other keyframes. Since this fundamentally changes the animation, |
---|
| 480 | this method just marks the animation as requiring this rebase, which |
---|
| 481 | is performed at the next Animation 'apply' call. This is to allow the |
---|
| 482 | Animation to be re-saved with this flag set, but without having altered |
---|
| 483 | the keyframes yet, so no data is lost unintentionally. If you wish to |
---|
| 484 | save the animation after the adjustment has taken place, you can |
---|
| 485 | (@see _applyBaseKeyFrame) |
---|
| 486 | @param useBaseKeyFrame Whether a base keyframe should be used |
---|
| 487 | @param keyframeTime The time corresponding to the base keyframe, if any |
---|
| 488 | @param baseAnimName Optionally a different base animation (must contain the same tracks) |
---|
| 489 | */ |
---|
| 490 | void setUseBaseKeyFrame(bool useBaseKeyFrame, Real keyframeTime = 0.0f, const String& baseAnimName = StringUtil::BLANK); |
---|
| 491 | /** Whether a base keyframe is being used for this Animation. */ |
---|
| 492 | bool getUseBaseKeyFrame() const; |
---|
| 493 | /** If a base keyframe is being used, the time of that keyframe. */ |
---|
| 494 | Real getBaseKeyFrameTime() const; |
---|
| 495 | /** If a base keyframe is being used, the Animation that provides that keyframe. */ |
---|
| 496 | const String& getBaseKeyFrameAnimationName() const; |
---|
| 497 | |
---|
| 498 | /// Internal method to adjust keyframes relative to a base keyframe (@see setUseBaseKeyFrame) */ |
---|
| 499 | void _applyBaseKeyFrame(); |
---|
| 500 | |
---|
| 501 | void _notifyContainer(AnimationContainer* c); |
---|
| 502 | /** Retrieve the container of this animation. */ |
---|
| 503 | AnimationContainer* getContainer(); |
---|
| 504 | |
---|
| 505 | protected: |
---|
| 506 | /// Node tracks, indexed by handle |
---|
| 507 | NodeTrackList mNodeTrackList; |
---|
| 508 | /// Numeric tracks, indexed by handle |
---|
| 509 | NumericTrackList mNumericTrackList; |
---|
| 510 | /// Vertex tracks, indexed by handle |
---|
| 511 | VertexTrackList mVertexTrackList; |
---|
| 512 | String mName; |
---|
| 513 | |
---|
| 514 | Real mLength; |
---|
| 515 | |
---|
| 516 | InterpolationMode mInterpolationMode; |
---|
| 517 | RotationInterpolationMode mRotationInterpolationMode; |
---|
| 518 | |
---|
| 519 | static InterpolationMode msDefaultInterpolationMode; |
---|
| 520 | static RotationInterpolationMode msDefaultRotationInterpolationMode; |
---|
| 521 | |
---|
| 522 | /// Global keyframe time list used to search global keyframe index. |
---|
| 523 | typedef vector<Real>::type KeyFrameTimeList; |
---|
| 524 | mutable KeyFrameTimeList mKeyFrameTimes; |
---|
| 525 | /// Dirty flag indicate that keyframe time list need to rebuild |
---|
| 526 | mutable bool mKeyFrameTimesDirty; |
---|
| 527 | |
---|
| 528 | bool mUseBaseKeyFrame; |
---|
| 529 | Real mBaseKeyFrameTime; |
---|
| 530 | String mBaseKeyFrameAnimationName; |
---|
| 531 | AnimationContainer* mContainer; |
---|
| 532 | |
---|
| 533 | void optimiseNodeTracks(bool discardIdentityTracks); |
---|
| 534 | void optimiseVertexTracks(void); |
---|
| 535 | |
---|
| 536 | /// Internal method to build global keyframe time list |
---|
| 537 | void buildKeyFrameTimeList(void) const; |
---|
| 538 | }; |
---|
| 539 | |
---|
| 540 | /** @} */ |
---|
| 541 | /** @} */ |
---|
| 542 | } // namespace Ogre |
---|
| 543 | |
---|
| 544 | #include "OgreHeaderSuffix.h" |
---|
| 545 | |
---|
| 546 | #endif // __Animation_H__ |
---|
| 547 | |
---|