Animating 3D Models

Moderator
Posts: 608
Joined: 2002.04
Post: #1
Time for some newbie OpenGL questions Huh How does one go about making 3D models animate in OpenGL. Right now I am using the OBJ Model Loader class from the source code section and it works great but I am at a loss as to how to animate the model. I have read things about key frames and interpolating between frames but how do I do this and how do I put animations in my OBJ model? I am using Wings 3D to make the model.
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #2
I'm not sure exactly if OBJ supports animation poses. Either way, you could store your animation in a separate file...

Most animation systems use bones to define what vertices are connected to what, and a heirarchy of bones to animate bones in relation to their parent bones.

The way I achieve this with OpenGL and Meshwork (a format supporting bones and poses), is storing all the vertices connected to each individual bone, and then I loop through the bones in parent-child descending order, rotating the matrix as I go. For animating the bones, I just change the orientation of the bone I want. Interpolating is just a matter of going from one number to the next in a matter of steps.
Quote this message in a reply
AJ Infinity
Unregistered
 
Post: #3
I heard dim3's Animator is better than Meshwork for animations. Dim3 has a solid XML based animation file format. I've written XML parsers before and I find it's not to hard. Might want a tutorial though.
Quote this message in a reply
Member
Posts: 33
Joined: 2002.04
Post: #4
Yeah I'd say definitely look at dim3 Animator. It can import Meshwork, OBJ, and Lightwave models and lets you set up animations by way of bones and poses. In fact the source is available for download on idevgames (I think it's an earlier version than the current beta), which should make rendering a little easier for you.

You set up key frames (poses), which are just rotations and transformations of bones. To get animation you assign poses along with a time factor to create movement. It's neither as complicated nor as simple as I described it.

Good luck!
Quote this message in a reply
Member
Posts: 142
Joined: 2002.11
Post: #5
Quote:Originally posted by jabber
Time for some newbie OpenGL questions Huh How does one go about making 3D models animate in OpenGL. Right now I am using the OBJ Model Loader class from the source code section and it works great but I am at a loss as to how to animate the model. I have read things about key frames and interpolating between frames but how do I do this and how do I put animations in my OBJ model? I am using Wings 3D to make the model.


.OBJ files do not support animation. If your going to do this keeping the .OBJ format, you're going to have to program keyframe interpolation between differen't .OBJ files. This is not undoable, but after doing it myself I did realize its a bit unpracticle. Slight changes to the model mean remaking tons of files. Also, you'll have to change the model loader code a bit since it uses display lists and frees the model data after building the list (afterwards its not availible for interpolation).

But anyway, the basic theory works like this:

Pick an amount that the drawn model is morphed between one model and another. Morph amount is some value between 0, not morphed at all, and 1, completely morphed. Loop through all the vertices and go like this (sudocode) with all of their x,y, an z positions.

drawnVertex = vertexFromModel1*(1-morphAmount) + vertexFromModel2*morphAmount

Nehe has a tutorial on this:
http://nehe.gamedev.net/data/lessons/les...?lesson=25
Quote this message in a reply
kberg
Unregistered
 
Post: #6
Does wings 3D, or any other popular modeler that people are using for that matter, support any of the following features of .obj's?
  • groups
  • smoothing groups
  • .mtl files
and if it supports material files, which of these properties does it support?
  • (ka) ambient colour
  • (kd) diffuse colour
  • (ks) specular colour
  • (map_kd) diffuse texture
  • (map_ks) specular texture
  • (map_ka) ambient texture
  • (map_bump) bumpmap texture


If someone has a modeller that supports these features, and wouldn't mind creating a sample .obj or two, I might be able to hack up the model loader class to support some of this stuff.

I'm thinking that group support, combined with some form of describing connectivity between groups, could be used to create some form of basic animation support.
Quote this message in a reply
hardinjmm
Unregistered
 
Post: #7
Okay, so you want to know how to animate OBJ models?

(I hope that you're not too much of a newbie and know what you're doing with display lists and quaternions, etc.)

Anyway, assuming that you are doing this in Project Builder and have Apple Developer Tools installed, open up the GLUT Samples project and look at the source for a program called "Blue Pony". Now, you might say, "what does this have to do with animating .OBJ files?".

Well, it manually creates its display lists and then animates them. If you look at the code for the ModelType class in the .OBJ importer, you will see that it too creates a display list from your imported models.

With this stunning knowledge in hand Rolleyes, you should now be able to implement an animation of OBJ files, assuming that you properly break up your mesh into its cooresponding parts and load them independently into an array of display lists.

Personally, if you really want to do this I would recommend rewriting the ModelType class to support either an array or linked-list of display lists, instead of making an array of ModelTypes, as that would be very inefficient.

The only reason I mentiond this animation method (this is how many old games did it), is because you said that you were a Newbie and the code to Dim3 Animator can be daunting to someone who has never done much OpenGL programming before.

Assuming that you are familiar with C++ in general, and know enough OpenGL (like what's found in NeHe's tutorials), you shouldn't have any trouble modifying the ModelType class to support an array/linked-list/binary-tree (I mention binary-tree if you want to make it really bone-based). Good luck, however you try to do it!

Jon Hardin
Quote this message in a reply
lpetrich
Unregistered
 
Post: #8
The earlier versions of it had had a curious bug in their model posing, and I've been unable to determine whether the latest versions have fixed it. The posing of each bone was done relative to the global coordinate system rather than relative to that bone's parent bone. The relative-to-parent approach is much more reasonable, and is how animation packages like Poser do it. It is also much easier to impose anatomical constraints in relative-to-parent mode; our elbows and knees do not have universal joints.

This I discovered rather inadvertently. I had implemented the "correct" sort of skeletal animation for Aleph One, the Marathon Open Source project, and it worked screwy with Dim3-Animator models. So I ended up creating a hacked version of Dim 3 Animator ("Cumulative") that does skeletal animation correctly.

Also, the Dim3-Animator file format has changed, from a set of XML and images files to a single file.
Quote this message in a reply
lpetrich
Unregistered
 
Post: #9
As to doing skeletal animation with an OBJ file, one would have to create a separate file (or files) that contains:

Bone definitions
Assignments of vertices to bones
Animations
Quote this message in a reply
Sta7ic
Unregistered
 
Post: #10
I've been wondering: what *does* happen to the triangles you're drawing when you decide to alter the modelview matrix stack? I've always thought that would would tear or something if you had solid meshes.
Quote this message in a reply
lpetrich
Unregistered
 
Post: #11
They won't tear, because the card won't "know" about your modelview-matrix changes until after the triangles are rendered. So you don't have to call glFlush() or glFinish() as it renders.
Quote this message in a reply
Sta7ic
Unregistered
 
Post: #12
Wouldn't that defeat the purpose of using the OGL matrix stacks for solid-mesh animation?
Quote this message in a reply
Member
Posts: 177
Joined: 2002.08
Post: #13
If you call a matrix operation between a begin/end pair, GL throws an error and you get nothing Rasp

Using GL for "true" skeletal animation is not easy; see the "how to take advantage of HW T&L" thread.
Quote this message in a reply
lpetrich
Unregistered
 
Post: #14
I was thinking of rendering with glDrawArrays() or glDrawElements() -- IMO, glBegin()/glEnd() is mostly useful for relatively small-scale tasks.
Quote this message in a reply
nickdabner
Unregistered
 
Post: #15
Has anyone looked into animation with Realbasic3D? It is quesa based, so I assume the same rules will generally apply (eg: Transforms in RB3D are the same as OpenGL).

Declares would be required to access the object vertices as RB doesnt expose this internally.

So, I should be able to make a linked list for the bones, and then use a hash table to go through the changes vertices and tranform bone based on its morphing state plus/times its parent? Quaternions should make this easy as they are free in RB3D.

Nick
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Nice models and free models, new site! 3d4ya 4 4,208 Sep 18, 2008 07:36 AM
Last Post: NYGhost
  OpenGL stops animating after title bar is dragged mbrady 2 2,233 Jul 2, 2006 01:14 AM
Last Post: Fenris