How to use external animations correctly ?

TaylorMouse

20-01-2010 09:47:55

Hi, I 've been searching for weeks to do this, an now that I am finally able to load skeleton files on the fly, now the problem I have is this :

The model is from Runic Games ( Torchlight )

It has these files
dog.mesh
dog.material
dog.png
dog.skeleton
dog_idle.skeleton
dog_bark.skeleton
dog_run.skeleton

in the dog.skeleton there is an animation with a track called "bind", but there are no node tracks, this is what is shown in image 1

Image 1 :


When I change to the Idle animation, it looks ok ( image 2 )

Image 2:


Whan I change to te Bark Animation, it looks ok to ( image 3 )
Image 3:


But then when I go to the "Run" animation" is screws up big time ( see image 4 )
Image 4:


Now when I use the script for importing dog.mesh.xml ( after I converted it with the ogre tools ) that I created together with some guys from the Torchlight forums, the dog initial stand is not the same as the one from the other ( previous ) animations I used.


So I thought it had to do with POSES, and whern I checked, no poses were anywhere to be found !! :(

So maybe I could set the bones from the skeleton first to the transformation matrix of the new skeleton if you see where I'm going, I just do not know how to do this ...

So major help would be appreciated !

If you want me to post the code on how I switch from one animation to another, I would gladly do that :)


Thnx in advance
T.

WarehouseJim

22-01-2010 10:27:36

Given nobody has replied, I'll put forward some ideas, but I don't really have a solution.

I have had problems in the past where the size or offset of the skeleton Vs the mesh is wrong (when exporting from Blender). This can cause weird distortions. To check the positions of the bones, use something like:

/// <summary>
/// Where skeletonNode is the node to which the skeleton & its mesh has been attached.
/// </summary>
void AttachMarkerToEachBone(Skeleton skeleton, SceneNode skeletonNode, string material, string namePrefix)
{
var bones = skeleton.GetBoneIterator();
Vector3 worldPositionOffset = skeletonNode._getDerivedPosition() + skeleton.RootBone._getDerivedPosition();
foreach(var bone in bones)
{
var marker = sceneManager.CreateEntity(namePrefix+bone.Name, "CMRCube.mesh");
var markerNode = skeletonNode.CreateChildSceneNode();
markerNode.AttachObject(marker);
marker.SetMaterialName(material);
markerNode.Scale(0.1f * Vector3.UNIT_SCALE);
markerNode.Position = skeleton.RootBone.GetScale() * skeletonNode.GetScale() * (bone._getDerivedPosition() + skeleton.RootBone._getDerivedPosition());
}
}


If your dog was a human and you use a wireframe material for your mesh, you should get something with markers at the joints like:
[attachment=0]skeletonwithmarkers.jpg[/attachment]

You could probably modify it to show them moving during the animation.

If the markers aren't where you expect them, then they will be distorting the mesh.


As another idea, how are you changing animations? Make sure you're not running two animations at the same time (which I think is possible). It may be that you're adding one to the other. If you look around, I think people have provided ways to allow smooth transitions between animations.

Going further, it is possible to read the XML version of the animation, which in my case is in the skeleton.xml file, (easy to look at, less easy to understand)... you might get a hint about what's going on there.


Can you explain more what you mean by So maybe I could set the bones from the skeleton first to the transformation matrix of the new skeleton if you see where I'm going, I just do not know how to do this ...

TaylorMouse

22-01-2010 12:15:42

Hey, thanks I will try that

The transition from one to another is pretty strait forward, I read the AnimationBlender code for smooth transition, but for now, I first want the animations to work than the smoothyness :)
I use the same as the AniamtionBlender but without any checking if the animation is still going on or not.

I'll keep you posted.


M.

Dusho

02-04-2010 09:04:24

Hi
I've been playing with Runic's skeleton animations also. I found out that import-export of Runic models changes BoneName to BoneIndex relation, so you are not able to use Runic's skeleton animations for your exported mesh.
I managed to fix it by adding sorting of BoneNames before BoneName and BoneIndex link are created in Ogre Blender exporter.
In file armatureexport.py it looks like this now:

# boneindices, needed for mesh's vertexboneassignments
# key = boneName, value = boneIndex

boneNameList = [bone.name for bone in self.bArmature.bones.values() if (Blender.Armature.NO_DEFORM not in bone.options)]
boneNameList.sort()
self.boneIndices = dict(zip(boneNameList, range(len(boneNameList))))

Now I can reuse all animations with my exported mesh, no more weird animations.