Browse Source

Added GetModel() & GetNode() to AnimationState.
Avoid double update in animation test, if an AnimationController is also playing the same animation.

Lasse Öörni 12 years ago
parent
commit
ad8b44d478

+ 21 - 4
Bin/Data/Scripts/Editor/AttributeEditor.as

@@ -1072,10 +1072,7 @@ void TestAnimation(UIElement@ attrEdit)
         testAnimState = model.GetAnimationState(animStateIndex);
         AnimationState@ animState = testAnimState.Get();
         if (animState !is null)
-        {
             animState.time = 0; // Start from beginning
-            UpdateAttributeInspector(false);
-        }
     }
     else
         testAnimState = null;
@@ -1086,8 +1083,28 @@ void UpdateTestAnimation(float timeStep)
     AnimationState@ animState = testAnimState.Get();
     if (animState !is null)
     {
+        // If has also an AnimationController, and scene update is enabled, check if it is also driving the animation
+        // and skip in that case (avoid double speed animation)
+        if (runUpdate)
+        {
+            AnimatedModel@ model = animState.model;
+            if (model !is null)
+            {
+                Node@ node = model.node;
+                if (node !is null)
+                {
+                    AnimationController@ ctrl = node.GetComponent("AnimationController");
+                    Animation@ anim = animState.animation;
+                    if (ctrl !is null && anim !is null)
+                    {
+                        if (ctrl.IsPlaying(anim.name))
+                            return;
+                    }
+                }
+            }
+        }
+
         animState.AddTime(timeStep);
-        UpdateAttributeInspector(false);
     }
 }
 

+ 2 - 0
Docs/ScriptAPI.dox

@@ -2439,6 +2439,8 @@ Properties:<br>
 - float time
 - uint8 layer
 - Animation@ animation (readonly)
+- AnimatedModel@ model (readonly)
+- Node@ node (readonly)
 - bool enabled (readonly)
 - float length (readonly)
 

+ 10 - 0
Engine/Graphics/AnimationState.cpp

@@ -257,6 +257,16 @@ void AnimationState::SetLayer(unsigned char layer)
     }
 }
 
+AnimatedModel* AnimationState::GetModel() const
+{
+    return model_;
+}
+
+Node* AnimationState::GetNode() const
+{
+    return node_;
+}
+
 Bone* AnimationState::GetStartBone() const
 {
     return model_ ? startBone_ : 0;

+ 4 - 0
Engine/Graphics/AnimationState.h

@@ -64,6 +64,10 @@ public:
     
     /// Return animation.
     Animation* GetAnimation() const { return animation_; }
+    /// Return animated model this state belongs to (model mode.)
+    AnimatedModel* GetModel() const;
+    /// Return root scene node this state controls (node hierarchy mode.)
+    Node* GetNode() const;
     /// Return start bone.
     Bone* GetStartBone() const;
     /// Return whether weight is nonzero.

+ 4 - 1
Engine/Script/GraphicsAPI.cpp

@@ -776,6 +776,8 @@ static AnimationState* ConstructAnimationState(Node* node, Animation* animation)
 static void RegisterAnimatedModel(asIScriptEngine* engine)
 {
     RegisterRefCounted<AnimationState>(engine, "AnimationState");
+    RegisterStaticModel<AnimatedModel>(engine, "AnimatedModel", false);
+    
     engine->RegisterObjectBehaviour("AnimationState", asBEHAVE_FACTORY, "AnimationState@+ f(Node@+, Animation@+)", asFUNCTION(ConstructAnimationState), asCALL_CDECL);
     engine->RegisterObjectMethod("AnimationState", "void AddWeight(float)", asMETHOD(AnimationState, AddWeight), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationState", "void AddTime(float)", asMETHOD(AnimationState, AddTime), asCALL_THISCALL);
@@ -791,10 +793,11 @@ static void RegisterAnimatedModel(asIScriptEngine* engine)
     engine->RegisterObjectMethod("AnimationState", "void set_layer(uint8)", asMETHOD(AnimationState, SetLayer), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationState", "uint8 get_layer() const", asMETHOD(AnimationState, GetLayer), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationState", "Animation@+ get_animation() const", asMETHOD(AnimationState, GetAnimation), asCALL_THISCALL);
+    engine->RegisterObjectMethod("AnimationState", "AnimatedModel@+ get_model() const", asMETHOD(AnimationState, GetModel), asCALL_THISCALL);
+    engine->RegisterObjectMethod("AnimationState", "Node@+ get_node() const", asMETHOD(AnimationState, GetNode), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationState", "bool get_enabled() const", asMETHOD(AnimationState, IsEnabled), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimationState", "float get_length() const", asMETHOD(AnimationState, GetLength), asCALL_THISCALL);
     
-    RegisterStaticModel<AnimatedModel>(engine, "AnimatedModel", false);
     engine->RegisterObjectMethod("AnimatedModel", "AnimationState@+ AddAnimationState(Animation@+)", asMETHOD(AnimatedModel, AddAnimationState), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimatedModel", "void RemoveAnimationState(Animation@+)", asMETHODPR(AnimatedModel, RemoveAnimationState, (Animation*), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("AnimatedModel", "void RemoveAnimationState(const String&in)", asMETHODPR(AnimatedModel, RemoveAnimationState, (const String&), void), asCALL_THISCALL);