View Full Version : Animating 3D Models
Time for some newbie OpenGL questions :???: 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.
MacFiend
2003.05.11, 05:37 PM
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.
AJ Infinity
2003.05.17, 11:25 PM
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.
Nickolei
2003.05.18, 03:45 AM
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!
Holmes
2003.05.27, 03:01 AM
Originally posted by jabber
Time for some newbie OpenGL questions :???: 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/lesson.asp?lesson=25
kberg
2003.05.31, 06:14 PM
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.
hardinjmm
2003.06.18, 07:55 PM
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
lpetrich
2003.06.22, 09:53 AM
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.
lpetrich
2003.06.22, 09:55 AM
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
Sta7ic
2003.06.22, 03:24 PM
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.
lpetrich
2003.06.22, 04:33 PM
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.
Sta7ic
2003.06.22, 05:39 PM
Wouldn't that defeat the purpose of using the OGL matrix stacks for solid-mesh animation?
Mark Levin
2003.06.22, 06:17 PM
If you call a matrix operation between a begin/end pair, GL throws an error and you get nothing :P
Using GL for "true" skeletal animation is not easy; see the "how to take advantage of HW T&L" thread.
lpetrich
2003.06.23, 01:06 PM
I was thinking of rendering with glDrawArrays() or glDrawElements() -- IMO, glBegin()/glEnd() is mostly useful for relatively small-scale tasks.
nickdabner
2003.07.13, 04:35 AM
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
MacFiend
2003.07.13, 11:37 AM
The easiest way to do animation in RB3D is to just model each piece separately, and continue with the animation after that. I've also heard of people with the need for dynamic models simply rewriting 3DMF data and passing it through the RB3D classes. Of course I think the declares would work as well. imho, RB3D is ugly and incredibly underdeveloped. I'd stick with OpenGL through declares.
nickdabner
2003.07.13, 08:34 PM
Originally posted by MacFiend
The easiest way to do animation in RB3D is to just model each piece separately, and continue with the animation after that. I've also heard of people with the need for dynamic models simply rewriting 3DMF data and passing it through the RB3D classes. Of course I think the declares would work as well. imho, RB3D is ugly and incredibly underdeveloped. I'd stick with OpenGL through declares.
Modelling each piece separately was my first choice, but it ends up with an early Tomb Raider look. Had some trouble with Meshwork observing the centroid as well, so gave up. May restart the process using the meshwork bone output. Easy to parse and would be a good building block / proof of functionality approach.
Obviously, RB3D would suffer from the same performance hits as OpenGL with regards to status changes, etc, so loading new 3DMF data may not be the best way to go.
Would you say RB3D is under-developed compared to Quesa? I find it a good stepping stone into programming and 3D for those of us short on attention span. Going to OpenGL would be a change for me (and a steep learning curve). Perhaps in the future.
kberg
2003.07.14, 03:14 PM
I had been thinking about recoding or adding the option to use a vertex array object instead of display lists. To do the animation, recode the modeltype class so that it can hold an array of vertex arrays, and make a new Draw() function that accepts two array indexes and a morph value. The morph value is simply a linear weight to calculate a new vertex using the associated verticies from the two referenced objects.
Between this, and some creative higher level boning, it should be possible to create some decent looking animations using sets of .obj files. Of course I haven't gotten around to doing any of this stuff lately as I've been kind of busy, and now finals are less then a month away :(
Holmes
2003.07.15, 08:26 AM
To do the animation, recode the modeltype class so that it can hold an array of vertex arrays, and make a new Draw() function that accepts two array indexes and a morph value. The morph value is simply a linear weight to calculate a new vertex using the associated verticies from the two referenced objects.
[/B][/QUOTE]
This is similar to the approach i took. it works well for morphing...but for things like limbs though, it'd take a lot of keyframes. i made a new class, an animation one, that stored an array of models. then you could call a draw between function which took two models and a percent morph.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.