Doom3world

The world is yours! Doom 3 - Quake 4 - ET:QW - Prey - Rage
It is currently Fri Jul 30, 2010 10:08 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 113 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject: Final MD5 File Formats
PostPosted: Wed Aug 04, 2004 3:37 pm 
Offline
picked up 75 health

Joined: Mon Feb 17, 2003 1:10 pm
Posts: 96
let's talk about ...
the new formats of the md5mesh and md5anim files

i have take a first look on it and will post here what i have found out, it is not complete

so, start with some excerpts of two example files, i choose the imp:

imp.md5mesh
Code:
MD5Version 10
commandline "mesh models/monsters/imp/animation/cycles/imp.mb -dest models/md5/monsters/imp/imp.md5mesh -game Doom -prefix IMP1_ -keep Lknee Rknee Lelbow Relbow camera Body -keep Rmissile Lmissile -parent Rmissile Rhand -parent Lmissile Lhand -parent Rwing Chest -parent Lwing Chest -parent Hips Body -parent Waist Body -parent camera Head -prefix IMP2_ -prefix IMP_ -align ALL"

numJoints 71
numMeshes 1

joints {
   "origin"   -1 ( 0 0 0 ) ( -0.5 -0.5 -0.5 )      //
   "Body"   0 ( -0.0000002384 0 56.5783920288 ) ( -0.5 -0.5 -0.5 )      // origin
   "Hips"   1 ( 3.3494229317 -0.0225959271 62.0168151855 ) ( -0.5 -0.5 -0.5 )      // Body
   ...
}

mesh {
   // meshes: polySurface1
   shader "models/monsters/imp/imp"

   numverts 891
   vert 0 ( 0.8658549786 0.3910109997 ) 1377 2
   ...

   numtris 1346
   tri 0 2 1 0
   ...

   numweights 1401
   weight 0 47 1 ( 1.5918749571 -0.9465401769 4.3310847282 )
   ...
}


idle1.md5anim
Code:
MD5Version 10
commandline "anim models/monsters/imp/animation/cycles/idle1.ma -dest models/md5/monsters/imp/idle1.md5anim -game Doom -prefix IMP1_ -keep Lknee Rknee Lelbow Relbow camera Body -keep Rmissile Lmissile -parent Rmissile Rhand -parent Lmissile Lhand -parent Rwing Chest -parent Lwing Chest -parent Hips Body -parent Waist Body -parent camera Head -prefix IMP2_ -prefix IMP_ -align ALL"

numFrames 80
numJoints 71
frameRate 24
numAnimatedComponents 52

hierarchy {
   "origin"   -1 0 0   //
   "Body"   0 6 0   // origin ( Ty Tz )
   "Hips"   1 3 2   // Body ( Tx Ty )
   "Lupleg"   2 56 4   // Hips ( Qx Qy Qz )
   ...
}

bounds {
   ( -12.7120218277 -30.5424346924 -0.7133038044 ) ( 18.
4121990204 41.8222160339 81.8068695068 )
   ...
}

baseframe {
   ( 0 0 0 ) ( -0.5 -0.5 -0.5 )
   ( 2.4760267735 51.5447387695 -3.0239832401 ) ( 0 0 -0.0269656405 )
   ( 1.0195504427 5.3025918007 3.3494231701 ) ( 0 0 0 )
   ...
}

frame 0 {
    51.5447387695 -3.0239832401
    1.0195504427 5.3025918007
    0.7355086803 -0.3889687657 0.4772257507
    0.0189839788 0.0578746125 -0.5245873928
    -0.8296036124 0.3866359591 0.0100788241
    0.488070637 -0.3712677062 0.7295016646
    -0.0142540894 -0.0333928876 -0.5200206041
    0.8724460602 -0.4404397309 0.1936372519
    1.0421460867 2.7552113533
    -0.1609682292 0.0150111886 0.067597121
    6.2155857086 5.6233057976 0.0092875436 -0.037551783 -0.0034615761
    -5.4427704811 0.0235444643
    6.0652527809
    0.0415914208 0.1587915123 -0.0024342418
    0.1301603615 0.0321234874 -0.2374467552
    0.0672957376 -0.1049735919 0.1197357625
    0.0461013205
    -6.2936215401 -0.2602182925 0.0192391276 -0.4136874974
    0.0191769451 -0.1025890633 0.0379714668
}
...





md5mesh:

Joint:

Code:
"origin"   -1 ( 0 0 0 ) ( -0.5 -0.5 -0.5 )


first the name of the joint

second the index of the parentjoint, -1 == no parent

the next three numers are the position of the joint x y z

the last three numbers are part of the orientation-quaternion
the md5 stores only the x y z components
there are unit quaternions, so there length are 1.0
Code:
1.0 = x^2 + y^2 + z^2 + w^2

so to calc the w component do
Code:
float term = 1.0f - (x*x) - (y*y) - (z*z);
float qw;
if (term < 0.0f)
   qw = 0.0f;
else
   qw = - (float) sqrt(term);


the position and orientation are also absolute values, no offest to the parent joint


Mesh:

beside some ('s and )'s, it's equal to the old format

quick refresh:
verts store the uv texcoords and the startindex and count of the weights
weights store the jointindex and the weight and x y z pos



md5anim:

numFrames 80
numJoints 71
frameRate 24
numAnimatedComponents 52

hierarchy:

numJoints entries

Code:
"Lrib"   21 59 27   // Chest ( Tx Ty Qx Qy Qz )


first the name of the joint

than the parentjoint index

next the flag that tells whitch components are animated in the frames:

six possible components - translation x y z and orientation x y z

one bit for each component:

bit 0 - 1 => translation x
bit 1 - 2 => translation y
bit 2 - 4 => translation z
bit 3 - 8 => orientation x
bit 4 - 16 => orientation y
bit 5 - 32 => orientation z

ie:
56 => 8+16+32 -> alle three orientation values
6 => 2+4 -> translation y and z

the last number in the hierarchy entry line are the startindex of the animated components in each frame,
the count of animated components are indicated by the preceding flag

bounds:

numFrames entries
min x y z and max x y z
the boundingbox coordinates are relative to the root bone's position ( at the first frame of the animation ?)

baseframe:

position x y z and orientation x y z (part of quaternion, see md5mesh joint description)

i think this are the pos and orientation of the joints as offsets (relative to each parent joint), unlike the absolute values of the md5mesh joints

frame:

numAnimatedComponents entries

my assumption is the the anim.components are also relative values and are used in combination with the baseframe data, but i have not tried it currently, so some tests are necessarily


when you know some more infos or have some corrections please post it :)


Last edited by bozo on Mon Aug 23, 2004 2:17 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 5:22 pm 
Offline
Plasma Spammer
User avatar

Joined: Fri Jun 27, 2003 11:24 pm
Posts: 2709
Location: Munich, Germany
Thanks for taking the time to write this up! I was working on the viewer and thought I'd post the info after I'm done with updating the viewer. There'll probably be an update tomorrow.

Quote:
i am not sure about the righthand or lefthand issue, so maybe w must be negate

The w component of the quaternions have to be negated, yep:
Code:
w = - sqrt( 1.0f - ( (x*x) + (y*y) + (z*z) ) )

_________________
Image Staff
Modelviewer | 3DSMax<->MD5 | Blender<->MD5


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Thu Aug 05, 2004 12:27 am 
Offline
picked up 100 armour
User avatar

Joined: Mon Nov 18, 2002 8:40 am
Posts: 138
Location: USA
Excellent info. I guess now is as better time than any for me to start learning quaternions :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 05, 2004 1:29 am 
Offline
picked up 100 armour
User avatar

Joined: Tue Mar 04, 2003 3:11 am
Posts: 114
Location: Spain
Oh wait, anybody understand quaternions?. Just use them! ;)

Hmm I wish I could have Doom3 to try some MD5 coding!

Greets.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 07, 2004 4:07 am 
Offline
picked up 100 armour
User avatar

Joined: Mon Nov 18, 2002 8:40 am
Posts: 138
Location: USA
Hmm, I've managed to read in the joint data, however my problem seems to lie with drawing them (and general understanding). Do the X Y Z coords have to be transformed via the orientation quaternion? I'm curious as to everyone's progress :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 07, 2004 5:34 am 
Offline
picked up 100 armour
User avatar

Joined: Tue Mar 04, 2003 3:11 am
Posts: 114
Location: Spain
¿Do you mean how to draw the skeleton just like the console command r_showSkel does?.

If so, I only use the positions from the md5mesh file to create the hierarchy. Here you see the code I use for drawing the skeleton in MAX:

Code:
fn buildSkeleton =
(
   -- For each MD5 bone
   for auxBone in bones do
   (
      local bonePos = auxBone.bindPos
      local parentBonePos = [0, 0, 0]

      -- If the current MD5 bone has a parent...
      if auxBone.parent > 0 do
      (
         -- Set the current MD5 bone's parent position
         parentBonePos = bones[auxBone.parent].bindPos
      )
      
      -- Create the new MAX bone
      local newBone = BoneSys.createBone parentBonePos bonePos [0, 0, 1]
      newBone.width = 1
      newBone.height = 1
      newBone.name = copy auxBone.name
      
      -- If current MD5 bone has a parent...
      if auxBone.parent > 0 do
      (
         -- Assign current MAX bone's parent
         newBone.parent = MAXBones[auxBone.parent]
      )

      -- Add new MAX bone to array of MAX bones
      append MAXBones newBone
   )

   -- Zoom extends to all objects
   max zoomext sel all
)


But I'm not sure if the result is the correct. Look this image:

Image

That is the MD5 importer I was working on long time ago (it's not finished, though). I was hoping that the "chest" bone would be where the "shoulders" bone is but it seems that's correct. Somebody can confirm that?. Anyway the relationships between bones seems to be correct.

Ah, one question. It's possible to draw the skeleton using only the info from the md5anim file or the md5mesh info is necessary?.

BTW, I'm also interested on how the other coders handle this.

Happy coding! ;)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 07, 2004 6:51 am 
Offline
picked up 100 armour
User avatar

Joined: Mon Nov 18, 2002 8:40 am
Posts: 138
Location: USA
Ahh, Thanks BeRSeRKeR! The skeleton looks great! I even checked out the bones in game for ya (since I can't go too long without seeing doom)

Image

I was trying to draw the joints out as boxes (like Max's Dummy objects) but I was doing something wrong. It seems there's a bug somewhere in my joint reading code. (You seem to be a good luck charm. ) This is specifically why I am rewriting it, but alas, I haven't learned :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 07, 2004 7:28 am 
Offline
picked up 100 armour
User avatar

Joined: Tue Mar 04, 2003 3:11 am
Posts: 114
Location: Spain
Hey, thanks for posting that image. Just what I was looking for!. :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 07, 2004 12:39 pm 
Offline
picked up 75 health

Joined: Mon Feb 17, 2003 1:10 pm
Posts: 96
@BeRSeRKeR
Quote:
It's possible to draw the skeleton using only the info from the md5anim file or the md5mesh info is necessary?.


with the old fileformats you need the md5mesh file for the parent/child hierarchy infos

but for the other data like position and orientation only the md5anim file,each joint has a pos and orient relative to it's parentjoint,
so you calc the pos and orient for the wished frame for the joint, build a matrix of this values and multiply this matrix with the parent matrix (when available),
with this finalmatrix you can draw the skeleton (use the translationpart of the matrix as the origin of each joint and create the hierarchy)

i dont try the new fileformat at present,
but now the hierarchy info is also in the md5anim files,
so it could be that the data, the baseframe + the animated components in the frames, in the md5anim file are sufficiently to calc the pos and orient of the joints for a wished frame


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 07, 2004 3:04 pm 
Offline
picked up 100 armour
User avatar

Joined: Tue Mar 04, 2003 3:11 am
Posts: 114
Location: Spain
bozo wrote:
i dont try the new fileformat at present,
but now the hierarchy info is also in the md5anim files,
so it could be that the data, the baseframe + the animated components in the frames, in the md5anim file are sufficiently to calc the pos and orient of the joints for a wished frame

By the end of the next week I could buy Doom3 so maybe then I will give a try to the new format.

Thanks!.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 07, 2004 6:27 pm 
Offline
Plasma Spammer
User avatar

Joined: Fri Jun 27, 2003 11:24 pm
Posts: 2709
Location: Munich, Germany
I'm getting a headache from the md5anim format. Some quaternion values seem to toggle their sign, even though the bone doesn't really move. But in my viewer, that sign toggling causes major rotations... anyone has an idea what's going on there?

example:
baseframe: Qx, Qy, Qz: ( -0.802292943 0.5969303846 0.0000000054 )
Qx and Qy are animated components:
frame 14: -0.8022928834 0.5969305038
frame 15: 0.802292943 -0.5969305634

_________________
Image Staff
Modelviewer | 3DSMax<->MD5 | Blender<->MD5


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Sun Aug 08, 2004 12:13 pm 
Offline
picked up 75 health

Joined: Mon Feb 17, 2003 1:10 pm
Posts: 96
@der_ton

i didn't try the new md5anim format currently,
but in a other own project, i had troubles that sounds like yours,
here is what i did:

Code:
float cosom = q1[0] * q2[0] + q1[1] * q2[1] + q1[2] * q2[2] + q1[3] * q2[3];
if (cosom < 0.0f)
{
   q2[0] = -q2[0];
   q2[1] = -q2[1];
   q2[2] = -q2[2];
   q2[3] = -q2[3];
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 09, 2004 5:20 am 
Offline
picked up 100 armour
User avatar

Joined: Wed Aug 04, 2004 11:58 pm
Posts: 141
So.. to export a mesh properly i would need the following data:

-Joints ( name of joint & joint location & index & index of parent joint & orientation quaternion )
-Mesh Data ( verts & tris & weights )

Some questions:

1. Not sure about the orientation quaternions, do i calculate thosed based off of data i already have, or pull them out of the mesh data?

2. Vertex indexes, is there a specific order in which the verts need to be extracted?

3. Are the numbers following the vertex coordinates the UV coords? If not, what are they and where do the UV's go?

4. Im not sure what weights are.. can i get a primer real quick?

5. Once i have all this data, i just need to write it to a file with the same format as all the md5mesh files: joints { ... } mesh { ... }, ect..?

6. Oh, and i just noticed this.. what is the fourth number in the triangles list?

Im working with the MayaAPI specifically, and hoping to write an importer/exporter. All help is greatly appreciated, so thanks : )


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 09, 2004 5:48 am 
Offline
picked up 100 armour
User avatar

Joined: Tue Mar 04, 2003 3:11 am
Posts: 114
Location: Spain
syphlitix wrote:
So.. to export a mesh properly i would need the following data:

-Joints ( name of joint & joint location & index & index of parent joint & orientation quaternion )
-Mesh Data ( verts & tris & weights )

If you only want the geometry data, yes.

syphlitix wrote:
3. Are the numbers following the vertex coordinates the UV coords? If not, what are they and where do the UV's go?

Example:
Code:
vert 0 ( 0.8658549786 0.3910109997 ) 1377 2

1st param -> vertex index
2nd and 3rd params -> u and v (texture coordinates)
4th param -> start of the vertex weights into the array of weights
5th -> number of weights starting at 4th param (in this case would be weights 1377 and 1378)

syphlitix wrote:
4. Im not sure what weights are.. can i get a primer real quick?

The weights indicate the percentage one vertex is affected by a set of bones, ie. how many influence a bone has over a given vertex. The sum of the vertex weights should be 1.

syphlitix wrote:
5. Once i have all this data, i just need to write it to a file with the same format as all the md5mesh files: joints { ... } mesh { ... }, ect..?

Yeah, otherwise Doom3 won't be able to load your models.

syphlitix wrote:
6. Oh, and i just noticed this.. what is the fourth number in the triangles list?

Example:
Code:
tri 0 2 1 0

1st param -> triangle index
2nd, 3rd and 4th params -> vertex indices (a, b, c)

Greetings.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 09, 2004 6:09 am 
Offline
picked up 100 armour
User avatar

Joined: Wed Aug 04, 2004 11:58 pm
Posts: 141
Cool, thanks for your reply BeRSeRKeR, this is starting to come together a bit for me.

Just a few more questions though, if you guys dont mind:

I understand the concept of weights now, but im still not sure how to calculate them. Or should i be able to pull them out of the model/mesh data?

And how do you calculate the offset of a weight or set of weights into the array of weights for a given vertex, or should i be able to find this data in the model/mesh?

And still, the queaternion bit, do they need to be calculated based on data i have collected, or should the model/mesh data contain this information alread?

Thanks again for all the help, this forum is great!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 09, 2004 7:29 am 
Offline
picked up 100 armour
User avatar

Joined: Tue Mar 04, 2003 3:11 am
Posts: 114
Location: Spain
syphlitix wrote:
I understand the concept of weights now, but im still not sure how to calculate them. Or should i be able to pull them out of the model/mesh data?

Yes. For example, in MAX you have a set of functions (built in the API) to retrieve weights from the model data. Ok, other modelling packages should support these functions too.

syphlitix wrote:
And how do you calculate the offset of a weight or set of weights into the array of weights for a given vertex, or should i be able to find this data in the model/mesh?

IIRC, same above.

syphlitix wrote:
And still, the queaternion bit, do they need to be calculated based on data i have collected, or should the model/mesh data contain this information alread?

All the bone trasformations at a given frame are accessed using the modelling package API (the same as above).

As you can see, whatever mesh property you want to know (vertex coordinates, texture coordinates, vertex indices, weights, animation keys, materials, etc), could be accessed through modelling package API.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 09, 2004 7:32 am 
Offline
picked up 100 armour
User avatar

Joined: Wed Aug 04, 2004 11:58 pm
Posts: 141
Awesome, that makes things much easier for me :D

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 21, 2004 12:41 am 
Offline
Plasma Spammer
User avatar

Joined: Fri Jun 27, 2003 11:24 pm
Posts: 2709
Location: Munich, Germany
It seems that the boundingbox coordinates in the md5anim are relative to the root bone's position at the first frame of the animation.

_________________
Image Staff
Modelviewer | 3DSMax<->MD5 | Blender<->MD5


Last edited by der_ton on Mon Aug 23, 2004 12:05 pm, edited 1 time in total.

Top
 Profile E-mail  
 
 Post subject:
PostPosted: Mon Aug 23, 2004 1:52 am 
Offline
is connecting to Doom3world.org

Joined: Mon Aug 23, 2004 1:44 am
Posts: 4
With the assistance of many people on this forum's knowledge that has been posted, I have written an MD5 loader class that uses OpenGL to draw. It was originally designed to load the V6 format, and worked great. I've since added support for the new V10 format using the specs that are, I think, at the top of this thread, but I've encountered some unusual issues. Basically, for a couple models I've tried to load (namely Cacodemon and Cyberdemon), I encounter very strange errors in the mesh. Since a picture speaks a thousand words, here's the cyberdemon and his strange mesh issues:

http://dragonhawk.dyndns.org/avalon/pics/md5-32.jpg

You'll notice the left leg has been squashed, the right foot is messed up, and it's hard to tell from that picture, but the rocket launcher on the right arm is out of place, and looks completely wrong if you rotate the model a bit. I was wondering if anyone else who's been playing with the new format has noticed anything like this? I can't say I honestly understand quaternions, but using some information I've found, I was able to transform the bones' quaternion orientation data into the old bind matrix style used in the V6 format. Anyway, thought I'd try to get a fresh perspective on this, as I've been banging my head on the wall trying to figure this out, given how inconsistant it is (I have no issues loading the Imp's mesh, but the Cacodemon's right half is skewed).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 23, 2004 2:34 am 
Offline
picked up 100 armour
User avatar

Joined: Tue Mar 04, 2003 3:11 am
Posts: 114
Location: Spain
Take a look at this. I think the answer of bozo could be the solution to your problem.

Greets.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 113 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group