I have a few .skeleton files. Every skeleton file has one animation inside, because I can’t merge all animation in one file before I export it. I use LinkedSkeletonAnimationSource to load this animation. But I have a problem. Animations (in linked skeletons) use initial transformation from base skeleton and do not play correctly (because animations consist of relative to initial pose transformations). I tried to modify Entity skeleton before play my animation:
Code: Select all
Skeleton::BoneIterator boneIter = pBaseSkel->getBoneIterator();
while(boneIter.hasMoreElements())
{
Bone *oldBone = boneIter.getNext();
Bone *newBone = animSrc.pSkeleton->getBone(oldBone->getName());
oldBone->setPosition(newBone->getInitialPosition());
oldBone->setOrientation(newBone->getInitialOrientation());
oldBone->setScale(newBone->getInitialScale());
oldBone->setInitialState();
}
Then, I started to think about different way to solve this. I tried to modify animation, shift and rotate all keyframes to base initial transformation:
Code: Select all
Animation * pAnim = animSrc.pSkeleton->getAnimation("walk");
Animation::NodeTrackIterator trackIter = pAnim->getNodeTrackIterator();
while (trackIter.hasMoreElements())
{
NodeAnimationTrack* track = trackIter.getNext();
//bone from linked skeleton
Bone* bone = animSrc.pSkeleton->getBone(track->getHandle());
//bone from base skeleton
Bone* boneMain = pBaseSkel->getBone(bone->getName());
//we need to calculate different of this skeletons
Vector3 posDelta = boneMain->getInitialPosition() - bone->getInitialPosition();
Matrix3 m1, m2,delta,rot;
boneMain->getInitialOrientation().ToRotationMatrix(m1);
bone->getInitialOrientation().ToRotationMatrix(m2);
m2.Inverse();
delta = m1*m2;
short num = track->getNumKeyFrames();
for(short i = 0; i < num; i++)
{
TransformKeyFrame *key = track->getNodeKeyFrame(i);
key->getRotation().ToRotationMatrix(rot);
Vector3 v = key->getTranslate();
rot = rot*delta;
v = v + posDelta;
Quaternion q(rot);
key->setRotation(q);
key->setTranslate(v);
}
}