# Thread: How do I convert a bone composed of a point and a quaternion to two vectors and a pt?

1. ## How do I convert a bone composed of a point and a quaternion to two vectors and a pt?

I'm trying to visualize the bones of an MD5-Mesh file and I see that the bones are represented as a point and a quaternion. Since a quaternion only represents a rotation, I don't know how to illustrate it. So lets say I have a human model where the arms are going across the x-axis (one hand pointing in the positive direction and the other in the negative). If I have arm bones matching up with mesh, is there a "default" vector where if apply the quaternion to it, the vector would point in the same direction as the arms (and like-wise for the up vector)? Or does every model editor do it's own thing where if I had a bone pointed in the same direction, each editor would give me a different quaternion..... or am I complete wrong about quaternions or how MD5-mesh uses them for bones?

2. The point is the position of the joint in the parent's coordinate system; the quaternion is the rotation of that joint. Between them, they specify the transformation for that joint relative to the parent joint.

If you want to draw a wireframe skeleton, you first need to convert the relative transformations to absolute transformations by multiplying each joint's relative transformation by its parent's absolute transformation. Drawing a line between the origin of each joint's transformation and that of its parent will give the skeleton. Note that there's no way to draw the bone corresponding to a "leaf" joint (e.g. fingertips, toes).

3. What confuses me is the root bone. I understand it changes the entire mesh, but if I want to visualize it, how do I do that? I was planning on representing each bone as 2 vectors (up and forward) and a point. Looking at some md5mesh files I see it's not zero. Is it just expressing that the models mesh is not drawn along the axis lines?

Side note: There's bones at the tip? I thought bones just go up to the last bend (joint).

4. Originally Posted by MrUNOwen
What confuses me is the root bone. I understand it changes the entire mesh, but if I want to visualize it, how do I do that? I was planning on representing each bone as 2 vectors (up and forward) and a point. Looking at some md5mesh files I see it's not zero. Is it just expressing that the models mesh is not drawn along the axis lines?
The root bone is just the root of the transformation hierarchy. As all transformations are relative to their parent, moving or rotating the bone moves or rotates the entire model.

Originally Posted by MrUNOwen
Side note: There's bones at the tip? I thought bones just go up to the last bend (joint).
Well, the term "bone" is a bit misleading; "joint" would be closer. So e.g. in the hand, the parts of the mesh forming the fingertips would be attached to the last "bone". If you were to render the skeleton, it would end at that joint; there wouldn't be lines corresponding to the distal phalanges. For a simpler skeleton with a solid hand, the skeleton would end at the wrist (to which the vertices forming the hand would be attached).

5. So at the moment I don't know of a add-on in blender that will import md5meshes (let me know if you know one), but lets say I have a unit cube mesh that's centered at origin and I have the root bone with a non-zero quaternion and a point of (1,0,0). Does it mean that the mesh in it's current state is the result of that bone or that when I load the model, the cube will now be centered at (1,0,0) with the rotation from the quaternion.

6. Note: most of what follows is based upon what's written here.

The skeleton in an md5mesh file is the bind pose skeleton. This is used to transform each vertex from a list of joint-relative positions and associated weights to an absolute position in the bind pose (AFAICT, this is only used for editing or previewing; in-game rendering uses the animated skeleton in the md5anim file).

The transformations in the md5mesh bind-pose skeleton are absolute (the animated transformations in the md5anim file are relative to the parent joint). Because of this, there's nothing special about the root joint in the md5mesh file. Vertices may be attached to it like any other joint. More generally, the "parent" field for each bone is of no relevance for obtaining absolute vertex positions. It only matters if you want to import the skeleton into an editor or you want to use the animations in an md5anim file.

Each vertex has an index, texture coordinates, and a contiguous list of bone-relative positions ("weights") specified by the index of the first such position and the number of positions. Each position consists of an index, a joint index, a weight (bias) and a joint-relative position. To obtain the absolute bind-pose position of a vertex, you transform each joint-relative position by the corresponding joint, then calculate a weighted sum of the results.

If the only joint in the md5mesh file is the root joint, then each vertex should only have a single position, and all positions will reference the root joint and have a weight of 1.0. So you're just transforming the joint-relative positions by the root joint to get the bind-pose positions. But that will only happen for a rigid body (i.e. something that can only move and rotate as a whole).

When it comes to using the animated skeletons in an md5anim file, the root joint is slightly different because it doesn't have a parent. The animated transformations in the md5anim file are relative to the parent, so you have to multiply a joint's parent-relative transformation by its parent's absolute transformation to get the joint's absolute transformation. But the root joint doesn't have a parent, so its parent-relative transformation is its absolute transformation.

7. So the mesh is not already reflecting what the joints are doing. If I were to ignore the joints and draw the mesh as is and the model was of a human character, I'd get the usual arms out pose? The joints are just reflecting the last pose. If all the quaternions were set to zero, I'd get mesh as is?

8. Originally Posted by MrUNOwen
So the mesh is not already reflecting what the joints are doing. If I were to ignore the joints and draw the mesh as is and the model was of a human character, I'd get the usual arms out pose? The joints are just reflecting the last pose. If all the quaternions were set to zero, I'd get mesh as is?
The only vertex positions in the file are in joint space; if you ignore the joints, you'll typically get garbage.

9. Oh! So the mesh isn't independent of the joints? So if I had a simple stick figure, and I just drew the mesh wireframe, I'd see the legs, midsection, arms and head start at origin? I thought the way it worked was that you'd subtract the joint position before applying the quaturnion transforms and then adding the joint's position after it has been changed by quaternion transforms as well.

I always thought the joints acted more like a modifier of the mesh rather than a dependency of the mesh.

10. Originally Posted by MrUNOwen
Oh! So the mesh isn't independent of the joints? So if I had a simple stick figure, and I just drew the mesh wireframe, I'd see the legs, midsection, arms and head start at origin? I thought the way it worked was that you'd subtract the joint position before applying the quaturnion transforms and then adding the joint's position after it has been changed by quaternion transforms as well.

I always thought the joints acted more like a modifier of the mesh rather than a dependency of the mesh.
Some formats have object-space vertices and a bind-pose skeleton that's used to transform them to bone space. MD5 appears to have the vertices already in bone space, and a bind-pose skeleton for reference.

The MD5 approach requires less computation (you don't have to transform the vertices to bone space) but more space (when a vertex is attached to multiple bones, it has multiple bone-space positions).

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•