Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to animate a 3d model (mesh) in OpenGL?

I want to animate a model (for example a human, walking) in OpenGL. I know there is stuff like skeleton-animation (with tricky math), but what about this....

  1. Create a model in Blender
  2. Create a skeleton for that model in Blender
  3. Now do a walking animation in Blender with that model and skeleton
  4. Take some "keyFrames" of that animation and export every "keyFrame" as a single model (for example as obj file)
  5. Make an OBJ file loader for OpenGL (to get vertex, texture, normal and face data)
  6. Use a VBO to draw that animated model in OpenGL (and get some tricky ideas how to change the current "keyFrame"/model in the VBO ... perhaps something with glMapBufferRange

Ok, I know this idea is only a little script, but is it worth looking into further? What is a good concept to change the "keyFrame"/models in the VBO?

I know that memory problem, but with small models (and not too much animations) it could be done, I think.

like image 767
user2602528 Avatar asked Aug 22 '13 19:08

user2602528


People also ask

Can you animate 3D models?

Anyone can animate a 3D model if they gather the right tools and take ample time to master the basics.

Can you animate 3D models in blender?

Blender is one of the go-to open-source software choices for animation. Surprisingly, it doesn't take much to get started on creating simple character animations. Once you have a final 3D character model, you can bring it to life with the software's numerous animation features and tools.


1 Answers

The method you are referring to of animating between static keyframes was very popular in early 3D games (quake, etc) and is now often referred to as "blend shape" or "morph target" animation.

I would suggest implementing it slightly differently then you described. Instead of exporting a model for every possible frame of animation. Export models only at "keyframes" and interpolate the vertex positions. This will allow much smoother playback with significantly less memory usage.

There are various implementation options:

  • Create a dynamic/streaming VBO. Each frame find the previous and next keyframe model. Calculate the interpolated model between them and upload it to the VBO.

  • Create a static VBO containing the mesh data from all frames and an additional "next position" or "displacement" attribute at each vertex. Use the range options on glDrawArrays to select the current frame. Interpolate in the vertex shader between position and next position.

You can actually setup blender to export every frame of a scene as an OBJ. A custom tool could then compile these files into a nice animation format.

Read More:

  • http://en.wikipedia.org/wiki/Morph_target_animation

  • http://en.wikipedia.org/wiki/MD2_(file_format)

  • http://tfc.duke.free.fr/coding/md2-specs-en.html

like image 177
Justin Meiners Avatar answered Oct 12 '22 10:10

Justin Meiners