Mulitple Models

Started by
7 comments, last by Mr_Ridd 20 years, 3 months ago
Howzit The character in my game has to have multiple positions in which he can be placed,like standing, running, ducking etc. I also want him to be able to hold all different kinds of weapons. Do I have to make seperate models and then just show them at the appropriate time or is there another way of doing it. Shot
The ability to succeed is the ability to adapt
Advertisement
Multiple models is the old technique, quake 2's md2 models used that. The directx sdk has a sample, dolphin, in which the dolphin mesh contains 2 dolphins in the 2 extreme states of the animation, and the software interpolates between those two states.

Nowadays the technique to use is skeletal animation, which was used by Half-Life's mdl model format in 1998, in quake 3's md3 format in 1999 and in just about any game since then. In this technique there is only one mesh, and you store extra information about which triangle belongs to which part. Then if you move your leg forward, it can be seen as a rotation of say 0 to 30 degrees around the anchor point, the hip. The body triangles stay the same, the leg triangles are drawn with the rotation applied.

The data is stored hierarchially and called bones, although they are not really bones, but an anchor point and a rotation. If the upper leg rotates forward, the lower leg rotates along, so the whole leg moves, not just the upper leg. But the lower leg can rotate too, around its anchor (the knee), then only the lower leg and foot moves.

This way you can define animation with just the movement data in time, say a leg is angle 0 at time 0 and angle 30 at time 0.5, your software would draw the interpolated position in between if it's called at moment 0.2.

To make it better, a triangle can belong to several regions with weights, eg. the triangles of the knee belong 50% to the upper leg and 50% to the lower leg, this makes them stretch along so that no holes or overlaps happen, this is called indexed skinning.

Just look up skeleton animation and skinned meshes, and you should be able to find a lot. You can also read Jim Adams' Advanced Animation book, it's very good.

[edited by - Fidelio66 on January 23, 2004 11:38:43 AM]
But that would imply that I would have to handle the animation in my game. At the moment I''m animating it in the modeling program and just importing it to my game. I do use skeletons in the modeling program.
The ability to succeed is the ability to adapt
No, you would still animate the model in a modelling package like 3d studio max.

Skeletal animation still relies on "keyframes" but where md2 for example stores a copy of the mesh at each keyframe this solution will store a "setup" of the bones at each keyframe (ie. position and rotation). Your application will load the animation data - the keyframes with bone setups - and "skin" the mesh, that is modify the vertex positions of the mesh based on the setup.

Btw, not to be a nitpick but md3 isn''t a skeletal system, it relies on mesh dumps just like md2. The difference IIRC is that md3 splits the model up into bodyparts so the engine can program for example a twist between legs and torso model. I guess you *could* call that a primitive 3-bone system though

- Kasper
Mr_Ridd, you must be handling the animation in your game, otherwise nothing would move. Cycling through a precalculated set of mesh dumps (the ''old way'') is still animating - it''s just not necessarily as flexible as a skeletal system.

For holding weapons, you might want to look into ''attachments points.'' Attachment points are basically specially tagged vertices in the mesh which move and animate like the rest of it, but which you keep track of so you can position other models relative to them. You might pick a vertex on the hand to use as an attachment point, and then the same with one on each gun, and then set the models up in-game so that the two attachment points are in the same physical position. Ideally you''d use more than one point (or store extra information in that one point) so that you can rotate the gun correctly.

Then you''ll just be able to move the hand around, and the gun will follow. It''s almost like a runtime extension of the skeleton.

Richard "Superpig" Fine
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
Enginuity1 | Enginuity2 | Enginuity3 | Enginuity4 | Enginuity5
ry. .ibu cy. .y''ybu. .abu ry. dy. "sy. .ubu py. .ebu ry. py. .ibu gy." fy. .ibu ny. .ebu
Preserve wildlife: pickle a squirrel today!

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

What I''m doing now is having one model with multiple animations.
The first say 8 frames will have him idle, then then the next will have him running and so on. Then I just call the relevant keyframes.

I think I''m gonna have to do that thing about the points on the model for the weapons, but I''m not quite sure how to.
The ability to succeed is the ability to adapt
quote:Original post by Mr_Ridd
What I''m doing now is having one model with multiple animations.
The first say 8 frames will have him idle, then then the next will have him running and so on. Then I just call the relevant keyframes.

Yeah, that''s the same way Quake does it. It should work with whatever underlying animation system you actually use (i.e. skeleton or meshdump). Just be careful that the last frame of one sequence doesn''t affect the first frame of the next in any way.

quote:I think I''m gonna have to do that thing about the points on the model for the weapons, but I''m not quite sure how to.


The easiest way to do it is probably just to pick a vertex for it and record that vertex''s number in the vertex array. It does require that you have the same number of vertices per frame, though - unless you want to record which vertex to use for each frame and somehow switch from one vertex to the next as you interpolate between frames.

Richard "Superpig" Fine
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
Enginuity1 | Enginuity2 | Enginuity3 | Enginuity4 | Enginuity5
ry. .ibu cy. .y''ybu. .abu ry. dy. "sy. .ubu py. .ebu ry. py. .ibu gy." fy. .ibu ny. .ebu
Preserve wildlife: pickle a squirrel today!

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

But thats not going to work one hundred percent, because a shotgun for instance is going to be held differently to a pistol.

If I don't do it with vertex way I will have to have seperate animations for each gun, item and position.

E.g.
There will also be a crawling feature, so the character will have to be animated going down for the crawl with a particular gun, and then once down another animation will come in with him crawling with the gun.

If I do it that way I will need 70 animations for one model with 6 weapons, 3 items and 7 positions. Thats a lot of animations.

There has to be a better way.

[edited by - Mr_Ridd on January 26, 2004 4:32:07 AM]

[edited by - Mr_Ridd on January 26, 2004 4:32:42 AM]
The ability to succeed is the ability to adapt
quote:Original post by Mr_Ridd
But thats not going to work one hundred percent, because a shotgun for instance is going to be held differently to a pistol.


OK, so you have multiple attachment points on the hand and pick which one you use when attaching a given weapon. Just how accurate do you want this thing to be?

If you''re trying to account for something like the difference between a handgun and an RPG, then OK, the difference is a little more obvious. What you can maybe do in a situation like that is use a ''sub-pose'' - data for just a small part of the skeleton. The rest of the model can be walking or whatever, but you use the RPG sub-pose for the arm bones.

It does work. Otherwise there wouldn''t be so many commercial games using it.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

This topic is closed to new replies.

Advertisement