• Advertisement
Sign in to follow this  

Doom MD5 model format

This topic is 4704 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Anyone know where to find some information on the doom³ md5 level format? I found this thingy on a Dutch guy's site, but that was rather scarse on info... :) Thnx, Danny

Share this post


Link to post
Share on other sites
Advertisement
The link that he pointed you to is great, but it doesn't cover a few of the finer points of the mesh loading. Specifically: You need to transform the vertcies given to you in the mesh by the joints in order to get them into their correct position.

Here's my little chunk of code to get the "real" vertex positions. This uses DirectX, but I was able to easily adapt it to OpenGL.


// Read in Joint data first, then:

for(i = 0; i < jointNum; i++)
{
vec3 r = joint.rot;

float qw = 1.0f - (r.x*r.x) - (r.y*r.y) - (r.z*r.z);

if (qw < 0.0f)
qw = 0.0f;
else
qw = -(float) sqrt(qw);


joint.quat = D3DXQUATERNION( r.x, r.y, r.z, qw );
}

//...... later on down the line (building the vertex buffer)

for(i = 0; i < numVerts; i++)
{
MD5_VERT v = verts;
pVertices.tex = v.tex;

pVertices.pos = vec3(0.0f, 0.0f, 0.0f);

for( j = 0; j < v.weightCount; j++ )
{
MD5_WEIGHT w = mesh->weights[v.startIndex + j];
MD5_JOINT joint = md5Model::joints[w.jointIndex];

D3DXMATRIX mat;
D3DXMatrixRotationQuaternion(&mat, &j.quat);
D3DXVECTOR3 orig = D3DXVECTOR3(w.pos.x, w.pos.y, w.pos.z);
D3DXVECTOR4 vec;
D3DXVec3Transform(&vec, &orig, &mat);

pVertices.pos += (bhxVec3( vec.x, vec.y, vec.z ) + joint.pos) * w.weight;
}
}



[Edited by - _the_phantom_ on April 1, 2005 11:22:29 AM]

Share this post


Link to post
Share on other sites
Original post by Kwizatz
As far as I know Level Format is the same old .map and .bsp.
/quote]
I don't think that's possible because .bsp maps are binary and the new Doom3 maps are in text.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ainokea
I don't think that's possible because .bsp maps are binary and the new Doom3 maps are in text.


I have not really checked, but if they're text, they are probably .map files, .map files are the text files you compile to .bsp in other engines.

I will do some research and find out [smile]

Edit: By the way, if you need to Load and Save MD5 (.md5mesh and .md5anim) I am about 75% done writting a library just for that, kind of my way of learning to use flex and bison [grin]

Share this post


Link to post
Share on other sites
Thanx...

Yeah, I meant the model format, somehow I don't think the level format would be suitable for my project (a 3D isometric viewpoint based RPG framework thingie ;) )

I'll prolly get back to this on monday, when I get some implementation time at work ;)

Greetz...

Share this post


Link to post
Share on other sites
The doom 3 .map files are very similar to the old .map format with a change in how the brushes are defined. Instead of giving points on a plane they just give you the plane equation coefficients instead. An example:


// primitive 3
{
brushDef3
{
( 0 0 -1 160 ) ( ( 0.0078125 0 0.25 ) ( 0 0.00390625 0 ) ) textures/recyc_wall/girders02e128_fin 0 0 0
( 0 0 1 -220 ) ( ( 0.0078125 0 0.25 ) ( 0 0.00390625 0 ) ) textures/recyc_wall/girders02e128_fin 0 0 0
( 0 -1 0 -2376 ) ( ( 0.0078125 0 0.25 ) ( 0 0.00390625 0 ) ) textures/recyc_wall/girders02e128_fin 0 0 0
( 1 0 0 -72 ) ( ( 0.0078125 0 0.25 ) ( 0 0.00390625 0 ) ) textures/recyc_wall/girders02e128_fin 0 0 0
( 0 1 0 2368 ) ( ( 0.0078125 0 0 ) ( 0 0.00390625 0 ) ) textures/base_trim/a_reactorpipe_04_fin 0 0 0
( -1 0 0 -136 ) ( ( 0.0078125 0 0.25 ) ( 0 0.00390625 0 ) ) textures/recyc_wall/girders02e128_fin 0 0 0
}
}





The first set of ()'s is the plane, the other numbers in the ()'s after are for tex coord generation similar to before.

What happens when you run a doom 3 map is the .map file is only used for entity information and the .proc file (which is also text) is the "compiled" map containing geometry info, precomputed shadow volume geometry for static lights, portals and nodes.


EDIT: Yeah I know the topic was about MD5 not map...but hey! :)


-SirKnight

Share this post


Link to post
Share on other sites
Quote:
Original post by SirKnight
EDIT: Yeah I know the topic was about MD5 not map...but hey! :)


No fuzz, I for one appreciate the Information, thanks [smile]

Share this post


Link to post
Share on other sites
By the way, since its about models I thought I should post the code to my lib, it is WIP (work in progress), the animation in particular is not working yet.

It is LGPL, but I dont mind if you (or anyone) grab pieces of code for your own stuff, giving some credit would be nice though [smile], if you decide to use the library as is, then I must ask you to abide the LGPL, which means share any improvements and bug fixes you make to it.

You dont need flex or bison to compile it, but you will need them if you modify the .l and .y files.

See the sample and trueSpace folders for examples on how to use it, the trueSpace folder which contains a .md5mesh importer for trueSpace has the code Blue*Omega pointed out as well as some useful Quaternion function.

Best of luck.

PS: md5lib, yeah, I am didnt spent much time finding a name, it was too late when I found out how unoriginal and misleading it is (MD5 also being a cryptographic algorithm), I will change the name once it gains a following [wink]

Share this post


Link to post
Share on other sites
Quote:
Original post by Kwizatz
Quote:
Original post by Ainokea
I don't think that's possible because .bsp maps are binary and the new Doom3 maps are in text.


I have not really checked, but if they're text, they are probably .map files, .map files are the text files you compile to .bsp in other engines.


The .map file is similar.. but in Quake3 it compiles into a .bsp file and in Doom3 into a .proc file. There are some differences though...

The .proc file is just text and really easy to read in and render.
Just have to get the shadows and per pixel light working though. :D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement