Ver código fonte

Add "repeatCount" to allowed properties on default clip in animation files. Clone default clip on animation cloning.

Jeremy Karlson 13 anos atrás
pai
commit
fdfcdbfe8c

+ 7 - 2
gameplay/src/Animation.cpp

@@ -7,7 +7,6 @@
 #include "Transform.h"
 #include "Properties.h"
 
-#define ANIMATION_INDEFINITE_STR "INDEFINITE"
 #define ANIMATION_DEFAULT_CLIP 0
 #define ANIMATION_ROTATE_OFFSET 0
 #define ANIMATION_SRT_OFFSET 3
@@ -256,7 +255,7 @@ void Animation::createClips(Properties* animationProperties, unsigned int frameC
 
         AnimationClip* clip = createClip(pClip->getId(), ((float) begin / frameCount) * _duration, ((float) end / frameCount) * _duration);
 
-        const char* repeat = pClip->getString("repeatCount");
+        const char* repeat = pClip->getString(ANIMATION_REPEAT_COUNT_STR);
         if (repeat)
         {
             if (strcmp(repeat, ANIMATION_INDEFINITE_STR) == 0)
@@ -453,6 +452,12 @@ Animation* Animation::clone(Channel* channel, AnimationTarget* target)
     GP_ASSERT(animation->getRefCount() == 1);
 
     // Clone the clips
+    
+    if (_defaultClip)
+    {
+        animation->_defaultClip = _defaultClip->clone(animation);
+    }
+    
     if (_clips)
     {
         for (std::vector<AnimationClip*>::iterator it = _clips->begin(); it != _clips->end(); ++it)

+ 3 - 0
gameplay/src/Animation.h

@@ -5,6 +5,9 @@
 #include "Properties.h"
 #include "Curve.h"
 
+#define ANIMATION_INDEFINITE_STR "INDEFINITE"
+#define ANIMATION_REPEAT_COUNT_STR "repeatCount"
+
 namespace gameplay
 {
 

+ 0 - 1
gameplay/src/AnimationClip.cpp

@@ -598,7 +598,6 @@ AnimationClip* AnimationClip::clone(Animation* animation) const
 {
     // Don't clone the elapsed time, listeners or crossfade information.
     AnimationClip* newClip = new AnimationClip(getId(), animation, getStartTime(), getEndTime());
-    newClip->setRepeatCount(getRepeatCount());
     newClip->setSpeed(getSpeed());
     newClip->setRepeatCount(getRepeatCount());
     newClip->setBlendWeight(getBlendWeight());

+ 16 - 1
gameplay/src/AnimationTarget.cpp

@@ -261,6 +261,21 @@ Animation* AnimationTarget::createAnimation(const char* id, Properties* animatio
         animation = createAnimation(id, propertyId, keyCount, keyTimes, keyValues, (Curve::InterpolationType) curve);
     }
 
+    const char* repeat = animationProperties->getString(ANIMATION_REPEAT_COUNT_STR);
+    if (repeat)
+    {
+        if (strcmp(repeat, ANIMATION_INDEFINITE_STR) == 0)
+        {
+            animation->getClip()->setRepeatCount(AnimationClip::REPEAT_INDEFINITE);
+        }
+        else
+        {
+            float value;
+            sscanf(repeat, "%f", &value);
+            animation->getClip()->setRepeatCount(value);
+        }
+    }
+    
     SAFE_DELETE_ARRAY(keyOut);
     SAFE_DELETE_ARRAY(keyIn);
     SAFE_DELETE_ARRAY(keyValues);
@@ -277,7 +292,7 @@ Animation* AnimationTarget::createAnimation(const char* id, Properties* animatio
         }
         animation->createClips(animationProperties, (unsigned int) frameCount);
     }
-
+    
     return animation;
 }