The import thing i must explain:why dont you to play the ogre mesh animation by ogre engine? because I like irrlicht not ogre and I have some 3d resource relate to ogre format.I only want to use these resource.
first define a struct for store ogre animation.
Code: Select all
struct OgreAnimationKeyframes
{
core::stringc Name;
f32 Length;
u16 KeyframeStart;
u16 KeyframeEnd;
};
Code: Select all
void COgreMeshFileLoader::composeObject(void)
Code: Select all
core::stringc lastName = "";
u32 AllKeyFramesSize = 0;
f32 AllFrameNum = 0;
for (u32 i=0; i<Skeleton.Animations.size(); ++i)
{
for (u32 j=0; j<Skeleton.Animations[i].Keyframes.size(); ++j)
{
OgreKeyframe& frame = Skeleton.Animations[i].Keyframes[j];
ISkinnedMesh::SJoint* keyjoint = m->getAllJoints()[frame.BoneID];
ISkinnedMesh::SPositionKey* poskey = m->addPositionKey(keyjoint);
poskey->frame=frame.Time*25;
poskey->position=keyjoint->LocalMatrix.getTranslation()+frame.Position;
ISkinnedMesh::SRotationKey* rotkey = m->addRotationKey(keyjoint);
rotkey->frame=frame.Time*25;
rotkey->rotation=core::quaternion(keyjoint->LocalMatrix)*frame.Orientation;
ISkinnedMesh::SScaleKey* scalekey = m->addScaleKey(keyjoint);
scalekey->frame=frame.Time*25;
scalekey->scale=frame.Scale;
if (lastName != Skeleton.Animations[i].Name)
{
//count all AllFrame size
AllFrameNum = frame.Time * 25;
AllKeyFramesSize += Skeleton.Animations[i].Keyframes.size();
lastName = Skeleton.Animations[i].Name;
}
}
}
lastName = "";
u32 tmpIndex = 0;
//count percent by name
for (u32 i=0; i<Skeleton.Animations.size(); ++i)
{
for (u32 j=0; j<Skeleton.Animations[i].Keyframes.size(); ++j)
{
if (lastName != Skeleton.Animations[i].Name)
{
ISkinnedMesh::OgreAnimationKeyframes *AnimationKeyframes = m->addAnimationKeyframes();
AnimationKeyframes->Name = Skeleton.Animations[i].Name;
AnimationKeyframes->Length = Skeleton.Animations[i].Length;
AnimationKeyframes->KeyframeStart = tmpIndex;
f32 percent = ((f32)Skeleton.Animations[i].Keyframes.size() / (f32)AllKeyFramesSize );
tmpIndex += (u32)(AllFrameNum * percent);
AnimationKeyframes->KeyframeEnd = (tmpIndex);
lastName = Skeleton.Animations[i].Name;
}
}
}
Code: Select all
void CAnimatedMeshSceneNode::setAnimationPlay(const core::stringc &AnimationName)
{
if (!Mesh)
{
os::Printer::log("No mesh, could not Play the Animation", ELL_WARNING);
return;
}
CSkinnedMesh *skinnedMesh=(CSkinnedMesh*)Mesh;
for (u32 j=0; j < skinnedMesh->getAllAnimationKeyframes().size(); ++j)
{
if (skinnedMesh->getAllAnimationKeyframes()[j]->Name == AnimationName)
{
setFrameLoop(skinnedMesh->getAllAnimationKeyframes()[j]->KeyframeStart
,skinnedMesh->getAllAnimationKeyframes()[j]->KeyframeEnd);
break;
}
}
}
Is there any one have good idea?