Search in sources :

Example 1 with SkeletalAnimationException

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();
}
Also used : SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint) SkeletalAnimationException(org.rajawali3d.animation.mesh.SkeletalAnimationObject3D.SkeletalAnimationException) ArrayList(java.util.ArrayList) SkeletonJoint(org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint)

Aggregations

ArrayList (java.util.ArrayList)1 SkeletonJoint (org.rajawali3d.animation.mesh.SkeletalAnimationFrame.SkeletonJoint)1 SkeletalAnimationException (org.rajawali3d.animation.mesh.SkeletalAnimationObject3D.SkeletalAnimationException)1