about the ogre-Irrlicht animation mapping

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
superpop
Posts: 21
Joined: Mon May 14, 2007 1:17 pm

about the ogre-Irrlicht animation mapping

Post by superpop »

i want to play some ogre mesh animation by name.but in irrlicht not support currently.so try like below code.I know the code is not right,I show the code to look for someone could help me.
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;
		};
and when

Code: Select all

void COgreMeshFileLoader::composeObject(void)
I count all the Keyframes size,and calculate the ogre keyframe percent by name.the code below:

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;
				}
			}
		}
when to playe the animation by name ,search the correspond frame start and frame end

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;
		}
	}
}
The means above,can play some animation by name ,but the animation name not correspond to frame start and frame end correctly.so some animation play wrong.

Is there any one have good idea?
Post Reply