OK so some background…
I’m building a 3D game engine from scratch (NIH syndrome detected). I have managed to get Skeletal animation into my engine. The only problem I’m running into at this point is skinning my mesh (getting the vertices to move with the bones).
I have my mesh stored in a VBO and it is drawn using a shader, but I’m moving the joints in the “old fashioned way” by applying transformations to the model view matrix by calling openGL functions. I want to keep the engine like this until release, because I only have two characters in-game at any one time so I don’t want to write another shader, or add support for these transformations into my current shader. (If it is easier then I guess I can)
As I said I have the bone animation in, I can draw the bones using this recursive function and it looks great
private int drawJoints(GL2 gl, Joint b, int index)
{
//Get the transform from the current frame for the current bone
Transform t = m_animation.m_frames[m_animation.m_curr_frame].m_transforms[index];
//Push the current matrix on the stack
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glPushMatrix();
//Update the model view matrix with our current transform
gl.glTranslatef(t.getTranslate().m_x, t.getTranslate().m_y, t.getTranslate().m_z);
gl.glScalef(t.getScale().m_x, t.getScale().m_y, t.getScale().m_z);
gl.glRotatef(t.getRotation().m_z, 0.0f, 0.0f, 1.0f);
gl.glRotatef(t.getRotation().m_y, 0.0f, 1.0f, 0.0f);
gl.glRotatef(t.getRotation().m_x, 1.0f, 0.0f, 0.0f);
//draw the current joint
gl.glPointSize(t.getScale().m_x * 400);
gl.glBegin(GL.GL_POINTS);
gl.glColor3f(0.0f, 0.5f, 0.5f);
gl.glVertex3f(0.0f, 0.0f, 0.0f);
gl.glEnd();
//Now for each of the children on this bone, draw them
if(b.m_children.length > 0)
for(int i = 0; i < b.m_children.length; i++)
index = drawJoints(gl, m_joints[b.m_children[i]], index+1);
//Pop the current matrix off the stack
gl.glPopMatrix();
//return the index of the current bone
return index;
}
Now if I want to attach the vertices
Now I can draw the vertices with their transformed locations(not a change in actual position, but using this technique it looks like they are moving), but I need to actually apply these transformations to the vertex locations so I can send the new vertex positions to my VBO. Can I just grab the ModelView matrix after I perform the transformation on the bone and apply it to each vertex that this bone influences?
Obviously this would be a rigid bind, so for a smooth bind it will be more complicated, but you do think that this will work, or am I over complicating it?