Advertisement

OpenGL Assimp animation issue

Started by May 11, 2019 03:20 AM
2 comments, last by skatehumor 5 years, 8 months ago

I have been working on a game engine for a few months now and have recently been implementing the animation system using the Assimp model loader. At this point I have skeletal animations working properly within the engine but there is a small bug that I have been tackling for a few days and was hoping somebody might know something about it.

I am running a demo scene in the engine where an animation starts to play once you click on an imported wolf model, but the model translates discretely when starting the animation (once the model is clicked). I have attached a GIF below.

I am almost certain it has something to do with the animation keyframe transforms, or possibly with one of the nodes in the skeletal joint hierarchy, but after trying a great many things I have not been able to figure this one out. Fortunately I have open sourced the project and it is freely available on Github. Most of the relevant code is either in the ZModelImporter or ZModel class if you need a code reference.

If you've encountered something like this before, any help would be greatly appreciated.

demo.gif

Check if any of the animation keyframes have any translation along say the root bone (or any bone for that matter). Especially for this type of animation, I would expect no scaling or translation in any of the keyframes, just rotation.

Now each keyframe might have some translation in each node to counteract the offset translation in the skeleton's per node offset matrix. In that case if you properly apply the offset transform, then it should be no problem having the translation remain in the animation keyframes (and the character should not translate when it starts animating, due to the offset transform correcting for that).

A good strategy is find if there is translation in the anim keyframes, and then just ignore it in the calculation and see if that fixes things visually. If it does, revert the change and then look into properly honoring the offset transform in the skeleton before moving to the animation step.

Advertisement

Thanks Steve,

One of my first attempts to fix this was to ignore the translation when calculating the node transform like you suggested, but this imploded the model since all the bones were subsequently placed at the same location. I also tried ignoring the translation in the skeleton's root transform only but this didn't seem to work either.

I also realized that Assimp was loading a lot of other things like the top level scene node, the mesh node and a light node when populating the skeleton data structure, so my skeleton was kind of bogus at first. I ignored those top level nodes until I got to the skeleton root joint, but this didn't seem to fix the translation issue either.

I suspect it has something to do with the root joint's position relative to the collider that encloses it, since I am using bullet physics within the engine and using bullet's motion states to update the model's transform matrix. The root joint has no translation (the model was exported with the root joint at the origin), and since this joint lies between the 4 paws of the wolf I suspect once it is concatenated with the other joint transforms it resets the model so that the root is at the center of the collider.

What I did for now is to introduce a hard coded offset that moves the model back to it's original location, but it seems like too much of a hack.

This topic is closed to new replies.

Advertisement