use of org.rajawali3d.animation.mesh.SkeletalAnimationObject3D.SkeletalAnimationException in project Rajawali by Rajawali.
the class SkeletalAnimationSequence method blendWith.
/**
* Blend this {@link SkeletalAnimationSequence} with another {@link SkeletalAnimationSequence}.
* The blendFactor parameter is a value between 0 and 1.
*
* @param otherSequence
* @param blendFactor
* @throws SkeletalAnimationException
*/
public void blendWith(SkeletalAnimationSequence otherSequence, double blendFactor) throws SkeletalAnimationException {
int numFrames = Math.max(mNumFrames, otherSequence.getNumFrames());
List<SkeletalAnimationFrame> newFrames = new ArrayList<SkeletalAnimationFrame>();
for (int i = 0; i < numFrames; i++) {
if (i >= otherSequence.getNumFrames())
break;
else if (i >= mNumFrames) {
newFrames.add(otherSequence.getFrame(i));
continue;
}
SkeletalAnimationFrame thisFrame = getFrame(i);
SkeletalAnimationFrame otherFrame = otherSequence.getFrame(i);
SkeletalAnimationFrame newFrame = new SkeletalAnimationFrame();
int numJoints = thisFrame.getSkeleton().getJoints().length;
if (numJoints != otherFrame.getSkeleton().getJoints().length)
throw new SkeletalAnimationObject3D.SkeletalAnimationException("The animation sequences you want to blend have different skeletons.");
SkeletonJoint[] newJoints = new SkeletonJoint[numJoints];
for (int j = 0; j < numJoints; ++j) {
SkeletonJoint thisJoint = thisFrame.getSkeleton().getJoint(j);
SkeletonJoint otherJoint = otherFrame.getSkeleton().getJoint(j);
SkeletonJoint newJoint = new SkeletonJoint();
newJoint.copyAllFrom(thisJoint);
newJoint.getPosition().lerpAndSet(thisJoint.getPosition(), otherJoint.getPosition(), blendFactor);
newJoint.getOrientation().slerp(thisJoint.getOrientation(), otherJoint.getOrientation(), blendFactor);
newJoints[j] = newJoint;
}
newFrame.getSkeleton().setJoints(newJoints);
newFrames.add(newFrame);
}
mFrames = newFrames.toArray(new SkeletalAnimationFrame[0]);
mNumFrames = newFrames.size();
newFrames.clear();
}
Aggregations