Browse Source

Update AttributeAnimation.h

aster2013 11 years ago
parent
commit
e1a2c7a2bf
1 changed files with 137 additions and 0 deletions
  1. 137 0
      Source/Engine/Scene/AttributeAnimation.h

+ 137 - 0
Source/Engine/Scene/AttributeAnimation.h

@@ -0,0 +1,137 @@
+//
+// Copyright (c) 2008-2014 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#pragma once
+
+#include "Resource.h"
+#include "Variant.h"
+
+namespace Urho3D
+{
+
+class ObjectAnimation;
+class XMLElement;
+
+/// Cycle mode.
+enum CycleMode
+{
+    /// Loop mode.
+    CM_LOOP = 0,
+    /// Clamp mode.
+    CM_CLAMP,
+    /// Pingpong Mode.
+    CM_PINGPONG,
+};
+
+/// Attribute key frame
+struct AttributeKeyFrame
+{
+    /// Time.
+    float time_;
+    /// Value.
+    Variant value_;
+};
+
+/// Attribute event frame.
+struct AttributeEventFrame
+{
+    /// Time.
+    float time_;
+    /// Event type.
+    StringHash eventType_;
+    /// Event data.
+    VariantMap eventData_;
+};
+
+/// Base class for attribute animation.
+class URHO3D_API AttributeAnimation : public Resource
+{
+    OBJECT(AttributeAnimation);
+
+public:
+    /// Construct.
+    AttributeAnimation(Context* context);
+    /// Destruct.
+    virtual ~AttributeAnimation();
+    /// Register object factory.
+    static void RegisterObject(Context* context);
+    
+    /// Load resource. Return true if successful.
+    virtual bool Load(Deserializer& source);
+    /// Save resource. Return true if successful.
+    virtual bool Save(Serializer& dest) const;
+    /// Load from XML data. Return true if successful.
+    bool LoadXML(const XMLElement& source);
+    /// Save as XML data. Return true if successful.
+    bool SaveXML(XMLElement& dest) const;
+
+    /// Set object animation.
+    void SetObjectAnimation(ObjectAnimation* objectAnimation);
+    /// Set cycle mode.
+    void SetCycleMode(CycleMode cycleMode);
+    /// Set value type.
+    void SetValueType(VariantType valueType);
+    /// Set key frame.
+    bool SetKeyFrame(float time, const Variant& value);
+    /// Set event frame.
+    void SetEventFrame(float time, const StringHash& eventType, const VariantMap& eventData = VariantMap());
+
+    /// Return object animation.
+    ObjectAnimation* GetObjectAnimation() const;
+    /// Return cycle mode.
+    CycleMode GetCycleMode() const { return cycleMode_; }
+    /// Return value type.
+    VariantType GetValueType() const { return valueType_; }
+    /// Is interpolatable.
+    bool IsInterpolatable() const { return isInterpolatable_; }
+    /// Return begin time.
+    float GetBeginTime() const { return beginTime_; }
+    /// Return end time.
+    float GetEndTime() const { return endTime_; }
+    /// Calculate scaled time.
+    float CalculateScaledTime(float currentTime) const;
+    /// Return all key frames.
+    const Vector<AttributeKeyFrame>& GetKeyFrames() const { return keyframes_; }
+    /// Return all event frames between time.
+    void GetEventFrames(float beginTime, float endTime, Vector<const AttributeEventFrame*>& eventFrames) const;
+
+protected:
+
+    /// Object animation.
+    WeakPtr<ObjectAnimation> objectAnimation_;
+    /// Cycle mode.
+    CycleMode cycleMode_;
+    /// Value type.
+    VariantType valueType_;
+    /// Is interpolatable.
+    bool isInterpolatable_;
+    /// Begin time.
+    float beginTime_;
+    /// End time.
+    float endTime_;
+    /// Key frames.
+    Vector<AttributeKeyFrame> keyframes_;
+    /// Event frames.
+    Vector<AttributeEventFrame> eventFrames_;
+};
+
+}