There is a function in that addon that gives a big clue on how to do what you want to do… sure it is for the new API but the fundamentals remain the same. You could apply it to the 2.49 API.
I guess I should have defined terms better…
When I said “frame of reference”, I meant which “Space” it is measured in comparison to. (More on “Space” in a moment)
Global == absolute, yes. I’ll use the word global from now on since all the relevant matrices in the api are labelled global.
Global space is in relation to the world axes. This is the absolute orientation.
Local space is in relation to the armature’s axes. If the armature has no rotation or translation, this will be the identity so can be ignored.
Bone space is in relation to the bone’s axes. If the armature has no rotation and all parent bones in the chain have no rotation, this will be the rest orientation.
The pose bone orientation is given in Bone Space. This is why all bones have an identity matrix when in rest position. They have not been rotated in bone space.
Ignore the sandwich product, as I said, that’s a quaternion thing and you are sticking with matrices (I think?). That’s how I’d reorient a rotation from one space to another with quaternions. I’m not sure how you’d do it with matrices. eg. You have a rotation in global space, but want the rotation to be in bone space, use the sandwich product of the rotation with the difference between the two spaces. But ignore it, it’s not needed for you.
You need to take this global rotation (M1 -ed.) and reverse the global rotation of it’s parent (M2 -ed.).
Maybe this would mean M1*(inverse of M2)? As I said, my matrix math is rusty and I’m not sure which side the matrices go on. You need to remove the global rotation of the parent from the global rotation of the bone you are considering. This will give the rotation that the bone is responsible for. Rotations that the parents are responsible for are not given in the bone’s pose matrix.
ie. The parent rotates, the child rotates with it, but the child’s pose matrix is still the identity. This is because the child bone has not rotated with respect to it’s parent. The parent bone rotates and the child bone’s space rotates with the parent, but the child bone does not rotate in it’s own bone space.
eg. If you hold your arm straight out in front and rotate your shoulder so your arm is straight out to the side, this is the same principle. Imagine axes sticking out of your elbow (y is down the length of the lower arm). These axes represent the bone space for the lower arm. The bone space for the lower arm rotates with with the upper arm as you rotate the shoulder. If you bend your arm at the elbow then the axes at your elbow do not change, the y axis points to where your lower arm was before you bent your elbow (this is the rest orientation). The lower arm rotates with respect to these axes (or in other words, in the frame of reference defined by these axes).
If in doubt, just play about with an armature and print out the pose matrices. It’s pretty simple really, I guess I’m pretty crap at explaining stuff.
OK, then ignoring the difference i might experience in reading Python 3.1 code, where can i get that addon?
If you mean this: http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/3D_interaction/Copy_Attributes_Menu , then the download link is down…
That really does clear many things out.
This means I have used the term ‘absolute matrix’ wrongly, as I meant the matrix which is relative to the armature’s center, not the world’s, so the matrices in my animation files are local space matrices. I think this is the problem, as I thought posebone matrices are relative to their parent, not themselves. I don’t know how to convert the ‘local space matrices’ from the animation files to ‘loc,rot,scale’ data for posing. They are stored in the pose matrix I believe, and are extracted with locationPart(), rotationPart() and scalePart(), am i right?
As for paent<->child space relations, I have used a scene graph based engines for quite some time now, so I understand it all.
I think you guys talk about rotation, but not about positions and scales too much?
Now that you specified you’re using 2.49 (in an edit, days later) it makes a big difference.
Still think if you’d taken my advice and searched for importers that do this (which are bundled with blender btw) you’d have had this problem licked days ago. A lot of this stuff needed to be freshly figured out for 2.5x after the api change but people have been doing these exact things in 2.4x for years.
you guys talk about rotation, but not about positions and scales too much?
This is true, but once you have the rotations nailed down the scaling and translating is easy.
Also, for animating a character, the main transformation that is really needed is rotation. Since the bones are all linked, the translation is kind of done by the rotation of parents (rotate the shoulder and the hand is translated and rotated). Translation becomes very important for positioning IK targets, but for FK is not so important. With FK, translation is most important on the root bone where it is used to create the ‘bobbing’ action in walk cycles by effectively translating all the bones up and down as the cycle progresses.
Edit:
locationPart(), rotationPart() and scalePart()
This is correct.
I believe that the rotation is actually keyframed as quaternion components in 2.49 (w, x, y, z). This is easy to manage since rotQuat = rotMat.toQuat(). Just extract the components from a quaternion created from the rotation matrix. toQuat() is a function available to all matrices that returns a quternion representation of the matrix. Check out the Mathutils module in the api for more info.
What makes you think Ive added it in an edit, and not something else, or simply fixed a typo? Because no, I havent added it later, you maybe can check the original one if your a mod.
Also how is it such a big difference? Unless the posing system in 2.5 is completely different from 2.4?
Either ways, I had mentioned it.
Still think if you’d taken my advice and searched for importers that do this (which are bundled with blender btw) you’d have had this problem licked days ago.
I have actually replied to that. I said that its not so easy as i would also need to learn how the formats store their data to have any idea what the code does. The collada specifications, for example are 300 pages long. But that left aside, I did ask which formats I should have a look at, because Blenders 2.4 x importer is terrible, I havent had any luck with collada as well. But you dont seem to have replied to this.
@FunkyWyrm
I forgot to mention that I also use toQuat() for rotatioPart. thx.
So what should I do to get the pose matrix (loc,rot,scale) from a local matrix (relative to armature center) loaded from the animation file?
Well, you see, I was just trying to give you a helpful nudge after two bumps with no responses.
Give a man a fish and all that…
@Uncle Entity: I know.
Just saying I didnt ignore your suggestions.
I have an idea, since the children connected to the parent bone cant have real position transformation, shouldnt I just check if there is a parent bone and not modify the translationPart if True?
I think the scale part shoudnt really care if its in a local, global, or bone space matrix, right? So since the bones matrices in the animation files are the same size (yeah), then I can just leave it as is.
So the only thing to do will be to get the pose matrix (loc,rot,scale) from a local matrix (relative to armature center) loaded from the animation file for setting the position of parent (only) bones and calculate relative rotations and Im good to go. Is this right?Im excited
maybe i got excited too early
From the api under Pose.PoseBone
poseMatrix
The total transformation of this PoseBone including constraints.
This matrix is in armature space, for the current worldspace location of this pose bone, multiply it with its objects worldspace matrix.
eg. pose_bone.poseMatrix * object.matrixWorld
Setting the poseMatrix only sets the loc/size/rot, before constraints are applied (similar to actions). After setting pose matrix, run pose.update() to re-evaluate the pose and see the changes in the 3d view. Type:Matrix object
Considering everything said in this thread, and the resolved confusion about the nature of your absolute matrices, perhaps this is the only thing to set? Then call insertKey()?
Bear in mind that the coordinate system might be different. Blender has a z up right-handed coordinate system. Some 3d specifications have a y up left handed coordinate system.
Check out “Orientation and handedness” at the bottom of this page:
That would be great. To be honest my english fails me. By ‘armature space’ he means ‘local’ (relative to armature center)? Because if it is… then im trying to invent the wheel in this thread.
Bear in mind that the coordinate system might be different. Blender has a z up right-handed coordinate system. Some 3d specifications have a y up left handed coordinate system.
thanks, it is.
EDIT: actually, i got even crazier visual results. Also the the bones keep getting farther from each other each frame,
Perhaps the bones are getting further from each other every frame because the translation from the armature centre defined in your source file poses is being applied to every pose in your imported animation? Perhaps you are applying the pose translation from your source file to the previous pose in your converted file?
What i mean is, maybe you are applying the transform to the previous pose each frame instead of applying the transform to the rest position each frame. If you are applying each transform to the previous pose rather than the rest position then the transforms would accumulate over time and result in too much translation and too much rotation.
It’s hard to know without access to your source files, your script and your output files.
Maybe, i do:
pose.bones['name'].poseMatrix = matrixloadedfromanimfile
each frame. Maybe I need to reset transforms each frame before insertKey(). Either way, the poses are really messed up, even in the first frame.
It’s hard to know without access to your source files, your script and your output files.
Like i said, the game is an adult one, i could pm you the files, but its surely against the rules to post it in a post.
I’m not guaranteeing I can help, but if you can put together a simple file for me and pm the link, I can give it a shot. I’m 33 yrs old and I’m sure your game won’t offend me. I’m currently attempting to model an attractive but very skinny, scantily clothed zombie chick for my own game.
I’ll not redistribute anything that you put together for me, but if you have concerns then by all means strip out the models and replace them with a simple mesh, and leave only a basic animation. The issue is with the animation importing so this is the main requirement.
I would need a source file containing a character and animation, and the import script that you have so far. Also, let me know the exact Blender version that you are using. I’m currently assuming that you’re using the official Blender 2.49b release from www.blender.org. Perhaps a .blend file containing the current results of your import would help too. It would allow me to quickly get an idea of your current results and issues.
I’m on Windows 32 bit, but the os shouldn’t matter too much since Blender plays well across platforms.
Thanks
Ill add all the necessary files in a small archive and pm you the link.
also I use 2.49b, windows version
FunkyWyrm has been kind enough to have a look at the files. Though I havent heard from him for few days, its probably because everyone is busy these days.
Ive got alot of free time right now and would like to learn about this part of Blender API a bit more.
I think i didnt completely understand the logic behind this.
According to the API there are 2 kinds of posebone matrices:
localMatrix and poseMatrix.
-
From what I understand, according to it’s API ref definition “the matrix combination of rot/size/loc” ,localMatrix is just a matrix holding the rot, loc and scale values,so… it isnt a true transformation matrix as it doesnt determine the end transforms of bones, but rather those values are added to the real matrix. Am I somehow close? Its just theres nowhere else to learn about it.
-
The poseMatrix is defined as “The total transformation of this PoseBone including constraints” and “This matrix is in armature space”. When we talk about “Armature space”, do we mean “Local Space” (relative to armatures center)? Because it confuses me even more as some people say posebone matrices are relative to their parent(s) bones.
Answer for my last post please…