AnimationState.h 3.3 KB

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