AnimationState.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // Copyright (c) 2008-2013 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "HashMap.h"
  24. #include "Ptr.h"
  25. namespace Urho3D
  26. {
  27. class Animation;
  28. class AnimatedModel;
  29. class Deserializer;
  30. class Serializer;
  31. class Skeleton;
  32. struct AnimationTrack;
  33. struct Bone;
  34. /// %Animation instance in an animated model.
  35. class AnimationState : public RefCounted
  36. {
  37. public:
  38. /// Construct with animated model and animation pointers.
  39. AnimationState(AnimatedModel* model, Animation* animation);
  40. /// Destruct.
  41. ~AnimationState();
  42. /// Set start bone.
  43. void SetStartBone(Bone* bone);
  44. /// Set looping enabled/disabled.
  45. void SetLooped(bool looped);
  46. /// Set blending weight.
  47. void SetWeight(float weight);
  48. /// Set time position. Does not fire animation triggers.
  49. void SetTime(float time);
  50. /// Modify blending weight.
  51. void AddWeight(float delta);
  52. /// Modify time position. %Animation triggers will be fired.
  53. void AddTime(float delta);
  54. /// Set blending layer.
  55. void SetLayer(unsigned char layer);
  56. /// Return animation.
  57. Animation* GetAnimation() const { return animation_; }
  58. /// Return start bone.
  59. Bone* GetStartBone() const;
  60. /// Return whether weight is nonzero.
  61. bool IsEnabled() const { return weight_ > 0.0f; }
  62. /// Return whether looped.
  63. bool IsLooped() const { return looped_; }
  64. /// Return blending weight.
  65. float GetWeight() const { return weight_; }
  66. /// Return time position.
  67. float GetTime() const { return time_; }
  68. /// Return animation length.
  69. float GetLength() const;
  70. /// Return blending layer.
  71. unsigned char GetLayer() const { return layer_; }
  72. /// Apply to the animated model's skeleton. Called by AnimatedModel.
  73. void Apply();
  74. private:
  75. /// Animated model.
  76. WeakPtr<AnimatedModel> model_;
  77. /// Animation.
  78. SharedPtr<Animation> animation_;
  79. /// Start bone.
  80. Bone* startBone_;
  81. /// Mapping of animation track indices to bones.
  82. HashMap<unsigned, Bone*> trackToBoneMap_;
  83. /// Last keyframe on each animation track for optimized keyframe search.
  84. PODVector<unsigned> lastKeyFrame_;
  85. /// Looped flag.
  86. bool looped_;
  87. /// Blending weight.
  88. float weight_;
  89. /// Time position.
  90. float time_;
  91. /// Blending layer.
  92. unsigned char layer_;
  93. };
  94. }