Ogre: Animation Bug fixed (they seem to work now)
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1204 67173fc5-114c-0410-ac8e-9d2fd5bffc1fpull/5/head
parent
861974f05c
commit
d9b8db78cd
|
@ -175,7 +175,7 @@ void OgreImporter::LoadSkeleton(std::string FileName, vector<Bone> &Bones, vecto
|
||||||
|
|
||||||
|
|
||||||
//--------- Calculate the WorldToBoneSpace Matrix recursivly for all bones: ------------------
|
//--------- Calculate the WorldToBoneSpace Matrix recursivly for all bones: ------------------
|
||||||
BOOST_FOREACH(Bone theBone, Bones)
|
BOOST_FOREACH(Bone &theBone, Bones)
|
||||||
{
|
{
|
||||||
if(-1==theBone.ParentId) //the bone is a root bone
|
if(-1==theBone.ParentId) //the bone is a root bone
|
||||||
{
|
{
|
||||||
|
@ -294,14 +294,13 @@ void OgreImporter::CreateAssimpSkeleton(const std::vector<Bone> &Bones, const st
|
||||||
|
|
||||||
|
|
||||||
//Createt the assimp bone hierarchy
|
//Createt the assimp bone hierarchy
|
||||||
DefaultLogger::get()->debug("Root Bones");
|
|
||||||
vector<aiNode*> RootBoneNodes;
|
vector<aiNode*> RootBoneNodes;
|
||||||
BOOST_FOREACH(Bone theBone, Bones)
|
BOOST_FOREACH(Bone theBone, Bones)
|
||||||
{
|
{
|
||||||
if(-1==theBone.ParentId) //the bone is a root bone
|
if(-1==theBone.ParentId) //the bone is a root bone
|
||||||
{
|
{
|
||||||
DefaultLogger::get()->debug(theBone.Name);
|
//which will recursily add all other nodes
|
||||||
RootBoneNodes.push_back(CreateAiNodeFromBone(theBone.Id, Bones, m_CurrentScene->mRootNode));//which will recursily add all other nodes
|
RootBoneNodes.push_back(CreateAiNodeFromBone(theBone.Id, Bones, m_CurrentScene->mRootNode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,7 +334,7 @@ void OgreImporter::PutAnimationsInScene(const std::vector<Bone> &Bones, const st
|
||||||
aiNodeAnim* NewNodeAnim=new aiNodeAnim();
|
aiNodeAnim* NewNodeAnim=new aiNodeAnim();
|
||||||
NewNodeAnim->mNodeName=Animations[i].Tracks[j].BoneName;
|
NewNodeAnim->mNodeName=Animations[i].Tracks[j].BoneName;
|
||||||
|
|
||||||
//we need this, to acces the bones default pose, which we need to make keys absolute
|
//we need this, to acces the bones default pose, which we need to make keys absolute to the default bone pose
|
||||||
vector<Bone>::const_iterator CurBone=find(Bones.begin(), Bones.end(), NewNodeAnim->mNodeName);
|
vector<Bone>::const_iterator CurBone=find(Bones.begin(), Bones.end(), NewNodeAnim->mNodeName);
|
||||||
aiMatrix4x4 t0, t1;
|
aiMatrix4x4 t0, t1;
|
||||||
aiMatrix4x4 DefBonePose=aiMatrix4x4::Translation(CurBone->Position, t1)
|
aiMatrix4x4 DefBonePose=aiMatrix4x4::Translation(CurBone->Position, t1)
|
||||||
|
@ -345,10 +344,10 @@ void OgreImporter::PutAnimationsInScene(const std::vector<Bone> &Bones, const st
|
||||||
//Create the keyframe arrays...
|
//Create the keyframe arrays...
|
||||||
unsigned int KeyframeCount=Animations[i].Tracks[j].Keyframes.size();
|
unsigned int KeyframeCount=Animations[i].Tracks[j].Keyframes.size();
|
||||||
NewNodeAnim->mNumPositionKeys=KeyframeCount;
|
NewNodeAnim->mNumPositionKeys=KeyframeCount;
|
||||||
NewNodeAnim->mPositionKeys=new aiVectorKey[KeyframeCount];
|
|
||||||
NewNodeAnim->mNumRotationKeys=KeyframeCount;
|
NewNodeAnim->mNumRotationKeys=KeyframeCount;
|
||||||
NewNodeAnim->mRotationKeys=new aiQuatKey[KeyframeCount];
|
|
||||||
NewNodeAnim->mNumScalingKeys =KeyframeCount;
|
NewNodeAnim->mNumScalingKeys =KeyframeCount;
|
||||||
|
NewNodeAnim->mPositionKeys=new aiVectorKey[KeyframeCount];
|
||||||
|
NewNodeAnim->mRotationKeys=new aiQuatKey[KeyframeCount];
|
||||||
NewNodeAnim->mScalingKeys =new aiVectorKey[KeyframeCount];
|
NewNodeAnim->mScalingKeys =new aiVectorKey[KeyframeCount];
|
||||||
|
|
||||||
//...and fill them
|
//...and fill them
|
||||||
|
@ -357,9 +356,10 @@ void OgreImporter::PutAnimationsInScene(const std::vector<Bone> &Bones, const st
|
||||||
aiMatrix4x4 t2, t3;
|
aiMatrix4x4 t2, t3;
|
||||||
|
|
||||||
//Create a matrix to transfrom a vector from the bones default pose to the bone bones in this animation key
|
//Create a matrix to transfrom a vector from the bones default pose to the bone bones in this animation key
|
||||||
aiMatrix4x4 PoseToKey=aiMatrix4x4::Scaling(Animations[i].Tracks[j].Keyframes[k].Scaling, t2) //scale
|
aiMatrix4x4 PoseToKey=
|
||||||
|
aiMatrix4x4::Translation(Animations[i].Tracks[j].Keyframes[k].Position, t3) //pos
|
||||||
* aiMatrix4x4(Animations[i].Tracks[j].Keyframes[k].Rotation.GetMatrix()) //rot
|
* aiMatrix4x4(Animations[i].Tracks[j].Keyframes[k].Rotation.GetMatrix()) //rot
|
||||||
* aiMatrix4x4::Translation(Animations[i].Tracks[j].Keyframes[k].Position, t3); //pos
|
* aiMatrix4x4::Scaling(Animations[i].Tracks[j].Keyframes[k].Scaling, t2); //scale
|
||||||
|
|
||||||
|
|
||||||
//calculate the complete transformation from world space to bone space
|
//calculate the complete transformation from world space to bone space
|
||||||
|
@ -371,14 +371,15 @@ void OgreImporter::PutAnimationsInScene(const std::vector<Bone> &Bones, const st
|
||||||
|
|
||||||
CompleteTransform.Decompose(Scale, Rot, Pos);
|
CompleteTransform.Decompose(Scale, Rot, Pos);
|
||||||
|
|
||||||
|
double Time=Animations[i].Tracks[j].Keyframes[k].Time;
|
||||||
|
|
||||||
NewNodeAnim->mPositionKeys[k].mTime=Animations[i].Tracks[j].Keyframes[k].Time;
|
NewNodeAnim->mPositionKeys[k].mTime=Time;
|
||||||
NewNodeAnim->mPositionKeys[k].mValue=Pos;
|
NewNodeAnim->mPositionKeys[k].mValue=Pos;
|
||||||
|
|
||||||
NewNodeAnim->mRotationKeys[k].mTime=Animations[i].Tracks[j].Keyframes[k].Time;
|
NewNodeAnim->mRotationKeys[k].mTime=Time;
|
||||||
NewNodeAnim->mRotationKeys[k].mValue=Rot;
|
NewNodeAnim->mRotationKeys[k].mValue=Rot;
|
||||||
|
|
||||||
NewNodeAnim->mScalingKeys[k].mTime=Animations[i].Tracks[j].Keyframes[k].Time;
|
NewNodeAnim->mScalingKeys[k].mTime=Time;
|
||||||
NewNodeAnim->mScalingKeys[k].mValue=Scale;
|
NewNodeAnim->mScalingKeys[k].mValue=Scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,9 +437,10 @@ void Bone::CalculateBoneToWorldSpaceMatrix(vector<Bone> &Bones)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BoneToWorldSpace=Bones[ParentId].BoneToWorldSpace*Transf;
|
BoneToWorldSpace=Transf*Bones[ParentId].BoneToWorldSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//and recursivly for all children:
|
//and recursivly for all children:
|
||||||
BOOST_FOREACH(int theChildren, Children)
|
BOOST_FOREACH(int theChildren, Children)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue