Assimp Animation not working correctly

Started by
-1 comments, last by ViX3LG0N 10 years, 8 months ago

Hey,
I try to get working animations with Assimp.
As you can see in the picture, head and lamp are correctly transformed, but the body isnt.
Also notice the holes in the body.
I think the problem is that the body is transformed by multiple bones.
[attachment=17287:assimp.png]

My code is designed that the whole model is splitted into single meshes (Assimp does this).
So each mesh has its own VBO with vertices, normals, uvs, weights ...

The bonematrices should be correctly calculated each frame.
But maybe im uploaded them wrong to the shader:


for (unsigned int m = 0; m < scene->mNumMeshes; m++)
{
	/*...*/
	if (scene->HasAnimations()&&scene->mMeshes[m]->HasBones())
	{
		/*...*/
		for (unsigned int i = 0; i < 100; i++)
		{
			mat4 tmpMat = mesh[m].bonemat[i];
			string loc = "gBones["+convertInt(i)+"]";
			glUniformMatrix4fv(glGetUniformLocation(shader, loc.c_str()),  1, GL_FALSE, value_ptr(tmpMat));
		}
		/*...*/
	}
	/*...(Draw)...*/
}

Also im not sure if filling up the bonedata(bonematrix+weight for each vertex) is correct:


for (unsigned int m = 0; m < scene->mNumMeshes; m++)
{
	/*...*/
	if (scene->HasAnimations()&&scene->mMeshes[m]->HasBones())
	{
		for (unsigned int k = 0; k < 100; k++)
		{
			mesh[m].bonemat[k] = mat4(1.0);
		}

		for(unsigned int i = 0; i < scene->mMeshes[m]->mNumVertices; i++)
		{
			ivec4 tmpID;
			vec4 tmpW;
			for (unsigned int  h = 0 ; h < 4; h++)
			{
				tmpID[h] = 0;
				tmpW[h] = 0.0;
			}
			mesh[m].boneIDs.push_back(tmpID);
			mesh[m].weights.push_back(tmpW);
		}
		for(unsigned int i = 0; i < scene->mMeshes[m]->mNumBones; i++)
		{
			for (unsigned int j = 0 ; j < scene->mMeshes[m]->mBones[i]->mNumWeights ; j++)
			{
				int v = scene->mMeshes[m]->mBones[i]->mWeights[j].mVertexId;
				float w = scene->mMeshes[m]->mBones[i]->mWeights[j].mWeight;

				//check if is filled
				int notFilled = -1;
				for (unsigned int  h = 0 ; h < 4; h++)
				{
					if (notFilled == -1)
					{
						if (mesh[m].weights[v][h] == 0.0)
						{
							notFilled = h;
						}
					}
				}
				mesh[m].boneIDs[v][notFilled] = i;
				mesh[m].weights[v][notFilled] = w;
			}
		}
	}
	/*...*/
}

If this code is out of context for you, i linked the whole Model class from my dropbox account.

Model.h

Model.cpp

Hopefully we find a solution

This topic is closed to new replies.

Advertisement