trying to import an animation file from a game format

Heres the story: my friend made an importer for a game 3d format. It contains meshes, bones, weights.
The bone data is stored in it as “transform matrices”. Hes script does a good job in converting them to bones.

Now my script tries to load an animation file from the game. it also contains “transform matrices”.

In the game, the character_model_transform_matrix * animation_file_transform matrix is used for animating. I tried doing the same in Blender, but the bones ended up too far away from each other when animating, but there are smooth IPO curves created, so I suspect my script does most of it correctly. I would like to know, is there a ‘special’ way Blender does bone animation? Is there maybe something posebones handle differently than editbones? because my friends script generates the editbones correctly. And someone else I know loaded the animation files in his OpenGL program and multiplied the character bone matrices with the animation matrices and everything ended up correctly.

I dont upload the scripts and sample files, because they are explicit. Im guessing its against the rules of the forum and i dont want to offend anyone. But if you pm me, i can send them to you individually.

I find bones to be tricky so I’m not able to be much help. I would probably look at the values in the Graph Editor and ensure they are correct.
bpy.context.active_object.pose.bones[n].matrix = resting position of the bone
bpy.context.active_object.data.bones[n].matrix = bone position at current key
Keep in mind that in Blender a bone’s identity pose matrix won’t point at +Z as far as I know.
That’s the extent of my knowledge.

Im pretty sure you didnt understand it all.
Ill try again:

The character file contains the 1st set of matrices that describe each bone’s location (relative to the root) in the “zero” position. The animation file contains the 2nd set of matrices that describe the transformation applied to each bone to get from the zero position to the new position. So the character file contains the inverses (to reduce run-time calculation) of the first set, the animation file contains the second set, and together they determine where vertices should move based on the bones they’re attached to in the game.

My friends script loads the character file. My script (tries to) loads the animation file. My friends script works, mine failsI should mention that the matrices in the files are ‘absolete’, not relative to parent bone or something. Might that be the problem?Again i could post sample files and the two scripts, but they are explicit content. pm me instead.
Also i use Blender API 2.49

Noone familiar with the posing system?

bump

Its a general question on how posing works.

You could look at some of the importers that ship with blender to see how they do it.

I’m pretty sure that bone locations are stored relative to the parent bone…could be wrong though, too lazy to look it up.

Which of the formats actually support bone based animation? Its pretty hard since i will also need to learn how the format stores its data themselves, not to mention not everyone uses the same modules for reading large binary files.

So anyway, you say the pose bone matrices are “relative matrices”, relative to their parent pose bone? Then why isnt this the case for edit bone matrices? There should be some logic in this but I have no idea.

Anyway, do you have any suggestions on how to calculate new ‘pose bone matrices’ which are relative to their parent if I have “pose bone matrices” stored in my animation files, but which are relative to the center point (pivot) of the armature?

Please post any info. Im pretty much stuck on this.

I think it probably has to do with the facts that edit bones aren’t dependent on their parents while pose bones are.

If you move a bone in pose mode all the children follow but not so in edit mode.

Well, its pretty logical.

I think im starting to understand.
I used to get the edit bone matrices (absolete), multiply them with pose matrices from the file (which are absolete as well) to get the new poses each frame. No wonder they were ending up so far from each other.

So from what you say, I should get the ‘rest pose’ posebone matrices instead, calculate new relative pose matrices from the absolete matrices stored in the files ( I have no idea how to do this. Any hints?) and multiply those two instead. Does this make any sense?

Im getting more frustrated on how pose matrices work.
I just printed the ‘pose bone localMatrices’ to the console and they all are like
[1,0,0,0
0,1,0,0
0,0,1,0
0,0,0,1]

Why?

not a coder but from what i do know ive seen that info like that in other games…

what you could be looking at there are quaternion (WXYZ)

Well, im not gonna repeat what I said, I explained in the game the 2 matrices need to be multiplied to get the bones new position,rot,scale. Now how on earth should I load the animation file in Blender then?

bump (couldnt think of anything)

Double post… Mobile internet sucks. :frowning:

I’ve had a thought that might be relevant to your problem…

You have a rest pose and you have the global orientation of the bones after they have been transformed into a pose.

Starting at the root bone, calculate the difference between the global pose orientation and the global rest orientation. This will give you the required rotation, but relative to the global axes. You need to transform this rotation into the coordinate system of the bone at rest. With quaternions, this is done with the sandwich product, but i’m afraid my matrix math is a bit rusty.

Considering the next bone up the chain, calculate the global rotation as before. There is now an extra step because this bone has already been transformed by it’s parent. You need to take this global rotation and reverse the global rotation of it’s parent. This will give the global rotation that is defined by this bone’s pose matrix. This matrix then needs to be transformed into this bone’s frame of reference. Note that this bone’s frame of reference has already been transformed by it’s parent’s pose rotation.

And so on for the bones up the chain.

I hope this helps a little. I’m on my phone right now so am somewhat limited.

Edit:
In relation to your confusion about the identity matrices when in rest pose…

The matrices represent the rotation from rest with respect to the parent. In my description above, this is covered right at the end. If you rotate the root bone from rest, all other bones will follow it. The matrix for the root bone will change, but all other matrices will remain the identity. Why? Because with respect to their parent they are still at rest (identity). This is what i meant when i said that the posebone’s frame or reference is transformed by it’s parent.

Scripting animation is not one of the easiest things to do. :spin:

Thanks for replying!

I have matrices in the animation file that are absolete (relative to the armature center (center point) which are multiplied with the bone matrices from the character model file for animating in the game.
I think we understand each other, right?

Starting at the root bone, calculate the difference between the global pose orientation and the global rest orientation.

global? as in ‘absolete’? ‘Rest orientation’, ‘pose orientation’? What are these and how are they different?

This will give you the required rotation, but relative to the global axes. You need to transform this rotation into the coordinate system of the bone at rest. With quaternions, this is done with the sandwich product, but i’m afraid my matrix math is a bit rusty.

‘Sandwich product’??

You need to take this global rotation and reverse the global rotation of it’s parent.

i dont understand

This matrix then needs to be transformed into this bone’s frame of reference. Note that this bone’s frame of reference has already been transformed by it’s parent’s pose rotation.

What is the ‘frame of reference’? the key?

In relation to your confusion about the identity matrices when in rest pose…

The matrices represent the rotation from rest with respect to the parent. In my description above, this is covered right at the end. If you rotate the root bone from rest, all other bones will follow it. The matrix for the root bone will change, but all other matrices will remain the identity. Why? Because with respect to their parent they are still at rest (identity). This is what i meant when i said that the posebone’s frame or reference is transformed by it’s parent.

:spin:

Hi,

I think that this post may be helpful to you especially the last post by uncle E.
http://blenderartists.org/forum/showthread.php?t=204516

Hi
Well it would probably solve the whole problem if there was a function to convert absolete matrices to relative (posebone matrix style) matrices, i guess.

But what ‘copy attributes addon’ is he talking about? And is this only a 2.5 thing?

If you see the word addon you can pretty much assume it’s about 2.5+.

So yeah it is an addon for 2.5. The source will be in the 2.55/scrpts/addons/ directory and is called space_view3d_copy_attributes.py
The wiki for this addon is at http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/3D_interaction/Copy_Attributes_Menu

And I’d equate absolute and relative with global and local respectively.

Sorry, I have a very good reason to use 2.49, so it wont help. I think i mentioned i use 2.49 somewhere.

So please lets get back to the original questions