www.jpct.net

Bones - Skeletal and Pose Animations for jPCT/jPCT-AE => Bones => Topic started by: AGP on August 18, 2014, 10:30:28 pm

Title: AnimatedGroup.CrossFade?
Post by: AGP 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 (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.
Title: Re: AnimatedGroup.CrossFade?
Post by: raft 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 (http://www.jpct.net/forum2/index.php/topic,3300.0.html) does skeleton pose interpolation, you can also try that.
Title: Re: AnimatedGroup.CrossFade?
Post by: AGP on August 19, 2014, 03:18:56 pm
Cool, I'll test this one and report back. Thanks.
Title: Re: AnimatedGroup.CrossFade?
Post by: AGP 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.
Title: Re: AnimatedGroup.CrossFade?
Post by: raft 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
Title: Re: AnimatedGroup.CrossFade?
Post by: AGP 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()?
Title: Re: AnimatedGroup.CrossFade?
Post by: raft 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.
Title: Re: AnimatedGroup.CrossFade?
Post by: AGP 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?
Title: Re: AnimatedGroup.CrossFade?
Post by: raft 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);
Title: Re: AnimatedGroup.CrossFade?
Post by: AGP 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.