问题
Recently I am working on some way to transform a given bone (rotate by some angle ) using Assimp in visual Studio C++.
I read at many sites procedure to do this and still I am not able to find error with multiple trials for matrix multiplication orders.
What I'm doing is given a model I firstly find the perVertexBone data and then I find bone locations prior any transformation and then represent all vertices in Model using linear weight assignment with bones using perVertexBone data calculated earlier . So , the initial Model looks like this (printing vertices location in Obj format)->
enter image description here
Transformation Process :
Then what I am doing is ( to rotate from neckNode to head portion of Mesh ) :
1.Find the neck node and change
neckNode -> mtransformation = GlmToaiMatrix4x4 ( glm::mat4 ( 1.57f ) )
(I've taken transpose in function for aiMatrix to glm::mat4 conversion).
2.Then I call visitNode ( neckNode ) function and the function is ->
void visitNode(aiNode*node)
{
string NodeName(node->mName.data);
glm::mat4 globalTransformation=glm::mat4(1.0f);
if(boneMap.count(NodeName))
{
aiNode*tmp=node;
while(tmp!=0){
glm::mat4 mat=aiMatrix4x4ToGlm(tmp->mTransformation);
globalTransformation=mat*globalTransformation; // If i change this
// order whole model is distorted
tmp=tmp->mParent;
}
boneMap[NodeName]=boneOffsetInverse[NodeName]*globalTransformation*boneOffset[NodeName];
}
for(int i=0;i<node->mNumChildren;i++)
{
visitNode(node->mChildren[i]);
}
}
After this again I calculate boneLocations from this boneMap and assign vertices based on perVertexBonedata and print vertices location which results in a Model like this (printing vertices location in Obj format)->
enter image description here
As you can see the model's neck to head portion is stretched too far away.
Note : Initailly also I call a visitNode() type function to store in boneMap heirarchy of bone skeleton in which I pass mRootNode to print the intial Model vertices .
So can anyone suggest what I'm doing wrong . I have tried many different ways for a week but this was the closest I could achieve.I need this step for a project and this is most crucial step without which I am unable to progress in this .
Any suggestions will be appreciated.
来源:https://stackoverflow.com/questions/62340023/wrong-bone-rotation-in-assimp