So I'm working on loading and rendering an animated model, I can render the mesh in its static position no problem as well as draw the animated bones with a debug lines.
Here is a short video illustrating the issue.
As you can see in the video, I've got the animated "stick-figure" displaying properly. The mesh over-top however appears to only be partially properly displaying.
As mentioned in the title, I'm using Assimp, and OpenGL.
On the model loading side of things I load in the Scene, traverse the nodes keeping there parent child rotation, identify the nodes which are bones and add the bone information to the nodes.
└───Scene
├───Camera
├───Armature
│ └───Torso : [ ROOT_BONE ]
│ ├───Chest : [ BONE ]
│ │ ├───Neck : [ BONE ]
│ │ │ └───Head : [ BONE ]
│ │ ├───Upper_Arm_L : [ BONE ]
│ │ │ └───Lower_Arm_L : [ BONE ]
│ │ │ └───Hand_L : [ BONE ]
│ │ └───Upper_Arm_R : [ BONE ]
│ │ └───Lower_Arm_R : [ BONE ]
│ │ └───Hand_R : [ BONE ]
│ ├───Upper_Leg_L : [ BONE ]
│ │ └───Lower_Leg_L : [ BONE ]
│ │ └───Foot_L : [ BONE ]
│ └───Upper_Leg_R : [ BONE ]
│ └───Lower_Leg_R : [ BONE ]
│ └───Foot_R : [ BONE ]
└───Character: [ 1 MESH(ES) ]
Here's a diargem of my current models node structure. Each of the nodes has a transform matrix, the ones with [ROOT_BONE]/[BONE] next to them also include an offset matrix.
To render the animated bones, I read in the animation key frames, construct the matrix for each "channel"(bone) based on the interpolated position rotation and scale values. When I multiply the animated matrices together (based on there parent hierarchy) I get the bone/join position in world space.(I don't appear to need to know any of the nodes transform matrices or the bones offset matrices to get this to render properly. (just multiply the animation matrix with its parent animation matrix)
To render the mesh, I've tried a few things, using just the matrices from the animation gives results similar to the video shown above however the torso is laying on the ground in-front of the debug skeleton, the arms/legs however are still displayed the same as the video. The results as seen in the video were achieved by multiplying the animation matrices by there respective bones, the result was then passed to the vertex shader.
uniform mat4 uModelViewProjection;
uniform mat4 uBones[100];
in vec4 aPosition;
in vec4 aWeights;
in ivec4 aBoneIds;
void main(void) {
mat4 skinMat =
uBones[aBoneIds[0]] * aWeights[0] +
uBones[aBoneIds[1]] * aWeights[1] +
uBones[aBoneIds[2]] * aWeights[2] +
uBones[aBoneIds[3]] * aWeights[3];
gl_Position = uModelViewProjection * skinMat * aPosition;
}
Here is the relevant code for the vertex shader. I've tried a few different approaches here as well with the same results (or worse in some cases).
A few of the things I thought immediately upon seeing the strange "collapsed" vertices was perhaps the bone matrices were not being passed properly, I did log them to verify they are indeed being sent, and I also checked the shader uniform location handles to make sure they were found properly.
I'm assuming I'm missing a step somewhere or prehapse just going about something in the wrong order. I've been working on a hand full of different "tutorials" for this topic but they are all quite difficult to follow. (code is all over the place with not the greatest documentation and I'm unable to run any of it as all of the examples require different languages/pre existing frameworks, or its just plain broken.)
Additional Info:
- The model I'm currently trying to load is a Collada (.dae) file.
- I'm using the LWJGL bindings for Assimp and OpenGL.