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 looks like this

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?

  • \$\begingroup\$ Does you bind pose look correct? \$\endgroup\$ – Homar Jul 19 '14 at 4:36
  • \$\begingroup\$ Yes. It looks correct \$\endgroup\$ – Csoki Jul 19 '14 at 9:22

I have founded the solution: https://www.youtube.com/watch?v=xf0VD4ba4ns In this video's desc link shows a file that I used to the new code wich is working

| improve this answer | |
  • \$\begingroup\$ Cardinal internet sin: "I fixed it". I have the exact same problem, although this is hardly a solution. \$\endgroup\$ – Yattabyte Feb 18 '16 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.