I could load an animation of a skinned model using assimp by interpolating between key-frames. Now, I have been trying to orient or position bones from a user defined transformation matrix instead of just loading it from an animation file. Like, rotating an arm by a certain angle in which the angle would be specified by the user. I loaded the model in it's bind pose as:
void recursion(aiNode* gNode)
{
std::string gNodeName(gNode->mName.data);
if(boneMapping.find(gNodeName) != boneMapping.end())
{
//if node corresponds to a bone,
Matrix4f boneMatrix = IdentityMatrix;
aiNode* tempNode = gNode;
//find combined transform of a bone
while(tempNode != NULL)
{
Matrix4f NodeMatrix(tempNode->mTransformation);
boneMatrix = NodeMatrix * boneMatrix;
tempNode = tempNode->mParent;
}
pBoneData[boneId].FinalTransform = GlobalInverseTransform * boneMatrix * pBoneData[boneId].OffsetMatrix;
}
for(int i = 0; i < gNode->mNumChildren; i++)
{ //repeat this process for child nodes
recursion(gNode->mChildren[i]);
}
}
To orient one of the meshes of a model using transformation matrix, I tried searching for name of the bone that corresponds to the parent-bone of the mesh and then replace it's node matrix with the required matrix. However, that didn't work at all as it deformed a bone at a different mesh.
The model to the right is in T pose and I intended to modify it by rotating the bone at the neck by a 45 deg angle, but it remained the same and the leg portion got deformed as seen in model to the left. So, any links to existing articles or answers could be really helpful.