Skip to main content
GameDev.net gamedev.net
🔒 Locked

loading .md2 files

Started by Alpha_Neuron Jun 15, 2002 at 3:49 AM 12 replies 500+ views
Original Post
Alpha_Neuron
Alpha_Neuron
G''day, I''m using Trents lesson 4 game programming tutorail and decided to experiment. I downloaded a couple of models from www.plycount.com to see if they would work. They alwasy come with a .pcx texture, so i change them into a .bmp(using paint or paint shop pro). Then i just pasted the tris.md2, and the Alien.bmp file into the models folder in invader(that way i don''t have to change the code), BUT the texure is all screwy. It is not on the model properly, the face is over there, toes up here. I think it might be that i changed the texture file from a .pcx to a .bmp, but I don''t know. If that is the case, then i need to know how to load in a .pcx file. PLEASE HELP
_DarkWIng_
_DarkWIng_
Try inverting texture coordinats when you load model.

u = 1.0f - u;
v = 1.0f - v;

try one of them.. or both if you need them. That solved some problems with me.

You could also flip texture and the result will be the same.

You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.
MagTDK
MagTDK
The MD2 loading code I've looked at including the one I coded myself work with different image formats. And in my case because I'm using Direct3d, I have several formats to choose from like .bmp, tga, ect.

You may want to look at the MD2 loading code at gametutorials.com

[edited by - MagTDK on June 15, 2002 5:23:01 AM]
Alpha_Neuron
Alpha_Neuron
Hey,

Thanks darkwing, that did the job
drBones
drBones
as this topic arised I''d like to ask another question.
what is animation arganised in md2 file...
there is pointer to frames and each frame contains some strange structure. (I read the gametutorials.com btw)
Could you help me - I dont wanna use someone''s code, I''d like to understand it and do it myself. (you can tell,why inventing the wheel again, but still I dont want to be dumb using and not knowing "what,when and why" the code does one thing)
thanks in advance
Pet
Pet
drBones
drBones
i got it... i think.
There _IS_ each frame stored within the file but it is scaled so that everyt vertex coord fit into one byte.
that is why a md2 file is like 400kb and loaderd were getting aprox 1,2MB .
correct me if I''m worng please.

anybody here?
Pet
Pet
_DarkWIng_
_DarkWIng_
You are right about vertices. Also normals are in some realy wierd format. File contains just index into array of normals you have to provide yourself. (anorms.h form Q2 source)

You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.
drBones
drBones
what noramls... face or vertex, or both.

actually you have to calculate normals each frame... is it better to store them (like vertex, and rotate and translate) or calculate them each frame ?
Pet
_DarkWIng_
_DarkWIng_
vertex normals. you don''t have face normals. I just store them with each frame so I dont have to look them up in array every time I use them. But for drawing animated mesh you have to interpolate them anyway.

You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.
drBones
drBones
actally no. I can create something like:

struct Face
{
int vertIndex[3];
}

struct Vertex
{
float coord[3];
}

struct Frame
{
Vertex* vert_list;
}

struct Walk
{
Frame *framlist;
}

and every frame you interpolate vertices according to the first frame or key frame. in this case I _calculate_ face normals using its verts.
Or I can use some modification:

struct Frame
{
Vertex* vert_list;
Normal* face_normals;
}

and in this cane you _interpolate_ normals like verts (rotate etc.)
My question is what are the benefits - would it be better to allocate more memory or use more cpu power ?

thanks in advance
Pet

[edited by - Pet on June 19, 2002 4:59:21 AM]
Pet
BGCJR
BGCJR
bmp image needs to be flipped, top to bottom.
Game Core
BGCJR
BGCJR
bmp image needs to be flipped, top to bottom.
Game Core
Buzzy
Buzzy
I couldn''t stand the whole normal index thing with ''optimized'' normals, so I just calculate my own normals. Looks a million times better (on the model I use for testing at least).

--Buzzy
(formerly buzzy_b)
_DarkWIng_
_DarkWIng_
Pet : You are right if you want to save some memmory but you'll have troubble when using it(normals) with vertex programs to interpolate mesh on GPU. (I'm working on this now)
Look at nVidias SDK / dev pages for more info.

You should never let your fears become the boundaries of your dreams.

[edited by - _DarkWIng_ on June 20, 2002 9:56:54 AM]
You should never let your fears become the boundaries of your dreams.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.