# Assimp and COLLADA bind shape matrix

This topic is 1964 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've been using Assimp to convert models into a nice runtime format. However Assimp does not seem to load/store the bind shape matrix of a given mesh.

This is not to be confused with a bind matrix for skinning. The bind shape matrix is a transformation matrix in which every vertex of a mesh must be transformed by to be in its proper location and orientation in the model.

For example, lets say my COLLADA model is composed of two equal sized cubes, one centred on the origin and one stacked on top of it. In this case, the vertices of both cube meshes will be identical, but one of them will have a translation component in it's bind shape matrix to move it into its proper location.

At first I thought Assimp would simply bake the vertices since thats what I was going to do anyway but it doesn't do that. I checked the *aiNode for the mesh in the scene graph thinking maybe it will store it in its mTransformation field but those only have an identity matrix.

Does anyone know what happens to these matrices and/or where I could find it in the scene graph? Edited by pondwater

##### Share on other sites
Odd ... can you verify that the collada file you're using has those transformations in it? If you aren't using the aiProcess_PreTransformVertices flag when reading the file, the transformations for your aiMesh instances should be in the aiNodes that they're attached to. Are you using the aiProcess_OptimizeGraph flag?

##### Share on other sites
I can verify that the transformations are present in the .dae file. Neither the aiProcess_OptimizeGraph or aiProcess_PreTransformVertices flags are set, im using aiProcessPreset_TargetRealtime_Quality which contains:

aiProcess_CalcTangentSpace | \ aiProcess_GenSmoothNormals | \ aiProcess_JoinIdenticalVertices | \ aiProcess_ImproveCacheLocality | \ aiProcess_LimitBoneWeights | \ aiProcess_RemoveRedundantMaterials | \ aiProcess_SplitLargeMeshes | \ aiProcess_Triangulate | \ aiProcess_GenUVCoords | \ aiProcess_SortByPType | \ aiProcess_FindDegenerates | \ aiProcess_FindInvalidData 

Yeah all the mTransformation aiNodes for meshes are the identity matrix.

##### Share on other sites
Is this something that could be solved by freezing/baking/applying the transforms before you export to .dae? I have to do that with Blender if I want verts to apply correctly to the model-space origin on export. I'm not sure which 3d package you're working with, or if you're getting the .dae files secondhand, but is there a reason to keep 2 cubes and 2 transformation matrices as opposed to 2 cubes with different vertex position values?

##### Share on other sites
I probably could bake them, but its a standard element of the COLLADA structure, Assimp should be able to handle this. Here's a peek at the source code for the ColladaHelper.h http://projects.deve....h?rev=145#L567

 /** A skeleton controller to deform a mesh with the use of joints */ struct Controller { // the URL of the mesh deformed by the controller. std::string mMeshId; // accessor URL of the joint names std::string mJointNameSource; ///< The bind shape matrix, as array of floats. I'm not sure what this matrix actually describes, but it can't be ignored in all cases float mBindShapeMatrix[16]; // accessor URL of the joint inverse bind matrices std::string mJointOffsetMatrixSource; // input channel: joint names. InputChannel mWeightInputJoints; // input channel: joint weights InputChannel mWeightInputWeights; // Number of weights per vertex. std::vector<size_t> mWeightCounts; // JointIndex-WeightIndex pairs for all vertices std::vector< std::pair<size_t, size_t> > mWeights; }; 

So it is at least acknowledged.

 // apply bind shape matrix to offset matrix aiMatrix4x4 bindShapeMatrix; bindShapeMatrix.a1 = pSrcController->mBindShapeMatrix[0]; bindShapeMatrix.a2 = pSrcController->mBindShapeMatrix[1]; bindShapeMatrix.a3 = pSrcController->mBindShapeMatrix[2]; bindShapeMatrix.a4 = pSrcController->mBindShapeMatrix[3]; bindShapeMatrix.b1 = pSrcController->mBindShapeMatrix[4]; bindShapeMatrix.b2 = pSrcController->mBindShapeMatrix[5]; bindShapeMatrix.b3 = pSrcController->mBindShapeMatrix[6]; bindShapeMatrix.b4 = pSrcController->mBindShapeMatrix[7]; bindShapeMatrix.c1 = pSrcController->mBindShapeMatrix[8]; bindShapeMatrix.c2 = pSrcController->mBindShapeMatrix[9]; bindShapeMatrix.c3 = pSrcController->mBindShapeMatrix[10]; bindShapeMatrix.c4 = pSrcController->mBindShapeMatrix[11]; bindShapeMatrix.d1 = pSrcController->mBindShapeMatrix[12]; bindShapeMatrix.d2 = pSrcController->mBindShapeMatrix[13]; bindShapeMatrix.d3 = pSrcController->mBindShapeMatrix[14]; bindShapeMatrix.d4 = pSrcController->mBindShapeMatrix[15]; bone->mOffsetMatrix *= bindShapeMatrix; 

From this it would seem like the transform gets baked into the inverse bind matrix... and checking now... it seems that this is the case because the mOffsetMatrix is different for the same joint when comparing two sepearte meshes with unique bind shape matrices.

Hmm that would explain why the bone influences are defined seperately for each mesh, instead of one global skeleton.

This seems really inefficient, because now I need to store a seperate version of each bone for each mesh because of these unique inverse bind transforms...

Should I just store the inverse binds along with the mesh objects instead of inside the bones? Then for a given model, iterate over the skeleton, update the global transforms, then update the unique skinning matrices using the inverse binds stored in the mesh? Edited by pondwater