I startded to make an assimp only opengl skeletal animation demo. For that I used this: http://sourceforge.net/p/assimp/discussion/817654/thread/5462cbf5
And something is not correct in bone matrices.
and my standerd bob_with_lamp model(.md5) looks like this. its moving its parts but not in correct way.This is the code:
for( size_t a = 0; a < anim->mNumChannels; ++a)
{
const aiNodeAnim* channel = anim->mChannels[a];
aiVector3D curPosition(0,0,0);
aiQuaternion curRotation(1,0,0,0);
aiNode* targetNode = scene->mRootNode->FindNode(channel->mNodeName);
while((int)time >channel->mNumPositionKeys) time-=channel->mNumPositionKeys;
curPosition = channel->mPositionKeys[(int)time].mValue;
curRotation = channel->mRotationKeys[(int)time].mValue;
aiMatrix4x4 trafo = aiMatrix4x4(curRotation.GetMatrix());
trafo.a4 = curPosition.x; trafo.b4 = curPosition.y; trafo.c4 = curPosition.z;
targetNode->mTransformation = trafo;
}
for (unsigned int n = 0; n < scene->mNumMeshes; ++n)
{
const aiMesh* mesh = scene->mMeshes[n];
std::vector<aiMatrix4x4> boneMatrices( mesh->mNumBones);
for( size_t a = 0; a < mesh->mNumBones; a++)
{
const aiBone* bone = mesh->mBones[a];
aiNode* node = scene->mRootNode->FindNode( bone->mName);
boneMatrices[a] = bone->mOffsetMatrix;
const aiNode* tempNode = node;
while( tempNode)
{
aiMatrix4x4 m = tempNode->mTransformation;
boneMatrices[a] *= tempNode->mTransformation;
tempNode = tempNode->mParent;
}
}
and my render:
std::vector<aiVector3D> resultPos( mesh->mNumVertices);
std::vector<aiVector3D> resultNorm( mesh->mNumVertices);
for( size_t a = 0; a < mesh->mNumBones; ++a)
{
const aiBone* bone = mesh->mBones[a];
const aiMatrix4x4& posTrafo = boneMatrices[a];
aiMatrix3x3 normTrafo = aiMatrix3x3( posTrafo);
for( size_t b = 0; b < bone->mNumWeights; ++b)
{
const aiVertexWeight& weight = bone->mWeights[b];
size_t vertexId = weight.mVertexId;
const aiVector3D& srcPos = mesh->mVertices[vertexId];
const aiVector3D& srcNorm = mesh->mNormals[vertexId];
resultPos[vertexId] += weight.mWeight * (posTrafo *srcPos);
resultNorm[vertexId] += weight.mWeight * (normTrafo * srcNorm);
}
}
//And rendering the vertices from the pos vector
what should I change to made this to get correct positions?