AnimationState.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 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 "Map.h"
  25. #include "SharedPtr.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(int layer);
  55. /// Set whether to use nlerp instead of slerp for rotation, default false
  56. void SetUseNlerp(bool enable);
  57. /// Return animation
  58. Animation* GetAnimation() const { return animation_; }
  59. /// Return start bone
  60. Bone* GetStartBone() const;
  61. /// Return whether weight is nonzero
  62. bool IsEnabled() const { return weight_ > 0.0f; }
  63. /// Return whether looped
  64. bool IsLooped() const { return looped_; }
  65. /// Return blending weight
  66. float GetWeight() const { return weight_; }
  67. /// Return time position
  68. float GetTime() const { return time_; }
  69. /// Return animation length
  70. float GetLength() const;
  71. /// Return blending layer
  72. int GetLayer() const { return layer_; }
  73. /// Return whether using nlerp for rotation
  74. bool GetUseNlerp() const { return useNlerp_; }
  75. /// Apply to the animated model's skeleton. Called by AnimatedModel
  76. void Apply();
  77. private:
  78. /// Animated model
  79. WeakPtr<AnimatedModel> model_;
  80. /// Animation
  81. SharedPtr<Animation> animation_;
  82. /// Start bone
  83. Bone* startBone_;
  84. /// Mapping of animation track indices to bones
  85. Map<unsigned, Bone*> trackToBoneMap_;
  86. /// Last keyframe on each animation track for optimized keyframe search
  87. Vector<unsigned> lastKeyFrame_;
  88. /// Looped flag
  89. bool looped_;
  90. /// Blending weight
  91. float weight_;
  92. /// Time position
  93. float time_;
  94. /// Blending layer
  95. int layer_;
  96. /// Nlerp flag
  97. bool useNlerp_;
  98. };