Advertisement

how many of you people

Started by November 25, 2001 06:39 PM
5 comments, last by Stashi 23 years, 3 months ago
how many of you people could sit down and simply write the coding to a .md2/.md3 viewer? am i that stupid that i cannot seem to understand ANYTHING in loading an .md2/3 model? ive downloaded several sources to renderers that you posters have made, and theyre completely mystifying. is there some prefabricated loading code than id released that youre all using, and youre all just writing the rendering code for it? or are you all completely familiar with how to load models and would have no trouble coding software for it. ahhh it hurts my head!#
I''ve took existing loading code, read through all of it, read MD2 file format, created my own class for md2 model and wrote the loading code.
If you need it ,I can send it. BTW its in OpenGL.
Advertisement
I havent tried it with MD2 loading (I modified someone elses code for that), but if I were to do it again, I would use nothing but the file format specification as reference.

I did that for Quake3 BSP file loading and rendering, used nothing but the file format specification, and I got everything except curves rendering fine.
-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack
I usally write my own model formats.
www.EberKain.comThere it is, Television, Look Listen Kneel Pray.
Stashi,


Don't give up man, its not that hard.

I wrote my own MD2 loader and got it working, without using any 'magic' libraries.

I found that most of the example code out there presumes that you are using Visual C++. If you are using a different compiler or operating system the code may not work, as the bit sizes of the data types used may be different. Its safer to code your own conversion routine for each data type.

Here is a high level description of the file format:

Header
Skins List
Texture Table
Triangle Table
Frame List
GL Command List

Basically , you can ignore the skins list and the GL commands list.

The frame list contains the vertex definitions for each frame. Each frame has a frame header, then the vertex list. The frame header look like:

float sx,sy,sz;
float tx,ty,tz;
char name[16]; //assuming char = 1 byte, unsigned int

The floats are 4 byte floats! These are used to scale and translate the x,y and coordinates of the vertices. These are needed because each vertex is stored as a 1 byte UNSIGNED int.

The vertices in the frame vertex table look like this:
char x,y,z;
char light;

(light is a lookup index to an external table of light normals. Its usually easier to ignore this and calculate the normals yourself once the model is loaded)

You work out the 'true' value for each vertex like so:
x = ((float) vx)*sx+tx;
y = ((float) vy)*sy+ty;
z = ((float) vz)*sz+tz;

Only the vertex positions change between frames. How the vertices connect to form triangles stays the same for each frame, so this infomation has been extracted into the triangle table.


The triangle table consists of indexes to the texture coordinate table and the frame vertex tables . This information is stored as 16 bit unsigned ints. The triangle definitions look like this:

unsigned int v1,v2,v3;
unsigned int t1,t2,t3;

If v1=50, then this indicates that the first vertex of this triangle is the 50th vertex in the frame list (the x,y,z value of this vertex will change for each frame, but it will always be vertex number 50 in the list).

If t1=20, this indicates that the texture cordinates for the first vertex of this triangle can be found at position 20 of the texture coordinate list.

The texture coordinate list consists of pairs of unsigned 16 bit values. Each pair of values defines a position on the texture surface.

Hope this helps,


Keith

------------------
Trouble is my business
------------------


Edited by - kkitchin on November 25, 2001 12:45:57 AM
------------------Trouble is my business------------------
quote:
Original post by Stashi
how many of you people could sit down and simply write the coding to a .md2/.md3 viewer?


I couldn''t yet... but I''ve just bought the book OpenGL gameprogramming and they have a pretty good explanation on the .md2 fileformat and how to load it. The .md3 I don''t know anything about

Advertisement
Actually I just wrote an md2 loader the other day, it wasn''t too hard. Search Google for "md2 file format" and you should find some explanations.

There is one annoying quirk in the format. Instead of storing normal vectors for each face it stores an index into a standardized list of normal vectors that id used. To get this list, download the source to the md2 loader from the Milkshape3D site, and look in the "anorms.h" file.

This topic is closed to new replies.

Advertisement