AttributeAnimation.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // Copyright (c) 2008-2014 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 "Resource.h"
  24. #include "Variant.h"
  25. namespace Urho3D
  26. {
  27. class ObjectAnimation;
  28. class XMLElement;
  29. /// Attribute key frame
  30. struct AttributeKeyFrame
  31. {
  32. /// Time.
  33. float time_;
  34. /// Value.
  35. Variant value_;
  36. };
  37. /// Attribute event frame.
  38. struct AttributeEventFrame
  39. {
  40. /// Time.
  41. float time_;
  42. /// Event type.
  43. StringHash eventType_;
  44. /// Event data.
  45. VariantMap eventData_;
  46. };
  47. /// Base class for attribute animation.
  48. class URHO3D_API AttributeAnimation : public Resource
  49. {
  50. OBJECT(AttributeAnimation);
  51. public:
  52. /// Construct.
  53. AttributeAnimation(Context* context);
  54. /// Destruct.
  55. virtual ~AttributeAnimation();
  56. /// Register object factory.
  57. static void RegisterObject(Context* context);
  58. /// Load resource. Return true if successful.
  59. virtual bool Load(Deserializer& source);
  60. /// Save resource. Return true if successful.
  61. virtual bool Save(Serializer& dest) const;
  62. /// Load from XML data. Return true if successful.
  63. bool LoadXML(const XMLElement& source);
  64. /// Save as XML data. Return true if successful.
  65. bool SaveXML(XMLElement& dest) const;
  66. /// Set object animation.
  67. void SetObjectAnimation(ObjectAnimation* objectAnimation);
  68. /// Set value type.
  69. void SetValueType(VariantType valueType);
  70. /// Set key frame.
  71. bool SetKeyFrame(float time, const Variant& value);
  72. /// Set event frame.
  73. void SetEventFrame(float time, const StringHash& eventType, const VariantMap& eventData = VariantMap());
  74. /// Return object animation.
  75. ObjectAnimation* GetObjectAnimation() const;
  76. /// Return value type.
  77. VariantType GetValueType() const { return valueType_; }
  78. /// Is interpolatable.
  79. bool IsInterpolatable() const { return isInterpolatable_; }
  80. /// Return begin time.
  81. float GetBeginTime() const { return beginTime_; }
  82. /// Return end time.
  83. float GetEndTime() const { return endTime_; }
  84. /// Return all key frames.
  85. const Vector<AttributeKeyFrame>& GetKeyFrames() const { return keyFrames_; }
  86. /// Has event frames.
  87. bool HasEventFrames() const { return eventFrames_.Size() != 0; }
  88. /// Return all event frames between time.
  89. void GetEventFrames(float beginTime, float endTime, Vector<const AttributeEventFrame*>& eventFrames) const;
  90. protected:
  91. /// Object animation.
  92. WeakPtr<ObjectAnimation> objectAnimation_;
  93. /// Value type.
  94. VariantType valueType_;
  95. /// Is interpolatable.
  96. bool isInterpolatable_;
  97. /// Begin time.
  98. float beginTime_;
  99. /// End time.
  100. float endTime_;
  101. /// Key frames.
  102. Vector<AttributeKeyFrame> keyFrames_;
  103. /// Event frames.
  104. Vector<AttributeEventFrame> eventFrames_;
  105. };
  106. }