Author Topic: AnimatedGroup.CrossFade?  (Read 17154 times)

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
AnimatedGroup.CrossFade?
« on: August 18, 2014, 10:30:28 pm »
Is there a way to transition gradually between one animation and another? Something along the lines of Unity's Animator.CrossFade (http://docs.unity3d.com/ScriptReference/Animator.CrossFade.html)? Because that's one of the main things that a rigged object can do that a vertex-animated one can't.

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: AnimatedGroup.CrossFade?
« Reply #1 on: August 19, 2014, 09:18:26 am »
no, not officially. you can blend pose animations with each other and with a skeletal animation but you cannot blend skeletal animations.

but of course you can try to implement it yourself. chase's skeleton helper does skeleton pose interpolation, you can also try that.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: AnimatedGroup.CrossFade?
« Reply #2 on: August 19, 2014, 03:18:56 pm »
Cool, I'll test this one and report back. Thanks.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: AnimatedGroup.CrossFade?
« Reply #3 on: August 22, 2014, 04:34:28 pm »
I'm trying to interpolate between different animations, not SkeletonPoses. I don't even know how SkeletonHelper could help me with this, because all it sees is SkeletonPoses.

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: AnimatedGroup.CrossFade?
« Reply #4 on: August 22, 2014, 04:54:36 pm »
each time you apply a skin animation, first a skeleton pose is calculated then it's applied to mesh

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: AnimatedGroup.CrossFade?
« Reply #5 on: August 23, 2014, 01:03:04 am »
OK. In this case, I need two SkeletonPoses, and I need them before the character is animated. Where would I call animatedGroup.get(0).getSkeletonPose()?

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: AnimatedGroup.CrossFade?
« Reply #6 on: August 23, 2014, 07:14:10 pm »
get two clones of SkeletonPose of the group. position each one according to your need. then interpolate them and apply the result to the original SkeletonPose.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: AnimatedGroup.CrossFade?
« Reply #7 on: August 24, 2014, 12:10:12 am »
The following isn't working.

   animatedGroup.animateSkin(0.04f, IDLE);
   animatedGroup.applyAnimation();
   idlePose = animatedGroup.get(0).getSkeletonPose().clone();
   idlePose.setToBindPose();//NOT SURE IF THIS IS NEEDED. JUST TRYING
   idlePose.updateTransforms();//NOT SURE IF THIS IS NEEDED. JUST TRYING
   animatedGroup.animateSkin(0.04f, WALKS);
   animatedGroup.applyAnimation();
   walkingPose = animatedGroup.get(0).getSkeletonPose().clone();
   walkingPose.setToBindPose();//NOT SURE IF THIS IS NEEDED. JUST TRYING
   walkingPose.updateTransforms();//NOT SURE IF THIS IS NEEDED. JUST TRYING

Then, in the game loop:

        SkeletonPose pose = SkeletonHelper.interpolateSkeletonPose(idlePose, walkingPose, skinFrame+=deltaTime);
        animatedGroup.setSkeletonPose(pose);
        pose.updateTransforms();
        animatedGroup.applySkeletonPose();
        if (skinFrame >= 1.00f)
      //SWITCH TO SECOND ANIMATION

What I get is the character in his static pose during the entire interpolation time (at the end of which, obviously, he switches to the second animation successfully). So, what should I be doing differently?

Offline raft

  • Moderator
  • quad
  • *****
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: AnimatedGroup.CrossFade?
« Reply #8 on: August 24, 2014, 03:55:45 am »
SkeletonPose.clone does not copy the current pose (animation). it just creates a new SkeletonPose attached to same Skeleton. try somthing like:

Code: [Select]
SkeletonPose pose1 = animatedGroup.get(0).getSkeletonPose().clone();
SkeletonPose pose2 = animatedGroup.get(0).getSkeletonPose().clone();

SkinClipSequence clip = animatedGroup.getSkinClipSequence();
clip.getClip(someIndex).applyTo(time, pose1);
clip.getClip(someOtherIndex).applyTo(time, pose2);

SkeletonPose newPose = SkeletonHelper.interpolateSkeletonPose(pose1, pose2, weight);       
animatedGroup.setSkeletonPose(pose);

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: AnimatedGroup.CrossFade?
« Reply #9 on: August 24, 2014, 04:13:28 am »
I had to add

Code: [Select]
pose.updateTransforms();
after setSkeletonPose() before it worked, but it finally did. Thanks a whole lot.