简体   繁体   中英

Android OpenGLES bone animation issue

I am having trouble implementing bone animation in my OpenGLES app in android. For the model, i used assimp to convert a FBX file exported with 3ds max and converted it into a text file. This file loads the bone data (vertices, weights, offset matrices, heirarchy etc.)

I can get the bind pose if i send the bone matrices as identity matrices:

在此处输入图片说明

Then I store the children of each node and multiply the node transformation matrix by their parents recursively using this code

public void setBoneHeirarchy()
{

    for (Bone b : mRootBones)
    {
        setBoneTransformations(b, mRootTransform);//From assimp aiScene->mRootNode->mTransformation
    }
}

private void setBoneTransformations(Bone b, Matrix4 parent)
{
    Matrix4 globalTransform = new Matrix4();
    globalTransform.multMatrix(parent); //[this].multMatrix([arg]) multiplies the matrix like [this] = [this] * [arg]
    globalTransform.multMatrix(b.nodeTransformation); //loaded from assimp as aiNode->mTransformation

    b.transformation.loadIdentity(); //the final transformation to return
    b.transformation.multMatrix(mRootTransformInverse); //Inverse of mRootNode->mTransformation
    b.transformation.multMatrix(globalTransform); //calculated above
    b.transformation.multMatrix(b.offsetMatrix); //read from text file (converted with assimp)

    for (Bone child: b.children)
        setBoneTransformations(child, globalTransform);
}

This blob is the result:

在此处输入图片说明

I think my bone weights and ids are correct because I get this: i.stack.imgur.com/fcTro.png when i translate one of the transformation matrices

I was trying to follow ogldev.org/www/tutorial38/tutorial38.html tutorial

and now I don't know where to look for errors

Is there a problem in reading the matrices or is it the calculation?

I solved it after trying many combinations of matrix multiplications

  1. First of all I switched from FBX to Collada file format and then converted it into my own format
  2. Transpose the matrix right after loading it from assimp (I was transposing it while loading it into the shader)
  3. Instead of multiplying with the node transformation loading from assimp, i created a matrix from the animation node's translation, rotation and scaling vectors

I don't completely understand if it was changing it to Collada that helped or not but google search suggests that people had problems with the FBX format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM