# 3D Assimp bone structure

## Recommended Posts

Hello.

Basically i want to draw a skeleton of a model in initial position.

Assimp has aiBone type and it has mOffsetMatrix which is "Matrix that transforms from mesh space to bone space in bind pose".

So i assumed that what i need is just use position component of that matrix and it's done. But no, skeleton is not correct.

Does anyone know how to get correct bone matrices in initial position?

##### Share on other sites

Turns out that first we need to calculate global transforms of all nodes by doing this.

global_transform = global_parent_transform * node_transform.

Then we can apply offset.

mesh_transform = global_transform * offset_matrix.

The only problem is that we also need to apply global inverse matrix of root.

final_transform = global_inverse * mesh_transform

But skeleton in not correct even after these operations.

Also I don't understand the point of global_inverse transformation.

Can anyone shed light on global_inverse transformation from here - http://ogldev.atspace.co.uk/www/tutorial38/tutorial38.html?

##### Share on other sites
Posted (edited)

Comments in that linked tutorial indicate the purpose of global_inverse transformation is to flip the handedness of the author’s content by changing its orientation.

Edited by Steve_Segreto

##### Share on other sites
1 hour ago, Steve_Segreto said:

Comments in that linked tutorial indicate the purpose of global_inverse transformation is to flip the handedness of the author’s content by changing its orientation.

Thanks. Does it mean we shouldn't apply this weird transform in general?

##### Share on other sites

That I don't know … I don't have familiarity with ASSIMP myself. It seems like the commenter on the article said if the model content is designed for left-hand coordinate system but is to be displayed in GL's traditional right-hand coordinate system then you would need the weird transform.

##### Share on other sites

well wait...we need the inverse op to put rotation at the origin otherwise we'd have orbit behavior. Order of operation in play here?

##### Share on other sites
27 minutes ago, GoliathForge said:

well wait...we need the inverse op to put rotation at the origin otherwise we'd have orbit behavior. Order of operation in play here?

Could you elaborate please?

For now i update skeleton structure by multiplying parent and node matrices: world_transform = parent->world_transform * transform;

But skeleton looks broken.

##### Share on other sites
Posted (edited)

Oh I really wish I could. Is it possible to see a video of the result. I tried looking through one of my projects that use assimp (ogl3/glfw thing) all I've seen that was relative is this function call. I put it for reference or compare maybe. its the recursive one at startup.

void cJoint::calcInverseBindTransform(glm::mat4 parentBindTransform)
{
glm::mat4 bindTransform = parentBindTransform * _localBindTransform;
_inverseBindTransform = glm::inverse(bindTransform);

for (cJoint* child : children)
{
child->calcInverseBindTransform(bindTransform);
}
}

I'm a little short on animation structure in this code base I'm looking at. Worst case, it would be good to walk through your entire process making sure every step is logical. I always want the quick fix too.

edit: we appear to do it the same here.

Edited by GoliathForge

##### Share on other sites

It looks like you are calculation inverse matrices in order to use them to transform vertices to bone space(or local space). These matrices should be same as the offset matrices of assimp.

I don't think it's same as global_inverse transformation of first node in the article.

For now i want to draw only a skeleton and i don't think we need inverse matrices for it at all.

##### Share on other sites

This might be helpful … didn't realize it was using ASSIMP

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 12
• 9
• 11
• 15