-
MD2 Model Format Issues
Basically I'm loading the first frames verticies to start out with (Gotta start somewhere), then scale and translate them, swap Y-Z values, all that stuff. Now when I render it, I get this:
Image: http://img3.imageshack.us/img3/9662/model1.jpg
Basically if you;re to lazy to look ;) all the triangles and such are disorirented, although you can make out the basic shape if u look hard enough. Anyone run into this problem and manage to fix it? Thanks.
-
You're problem could be anywhere. Maybe post up your code or samples from it. Have you tried stepping through the debugging and making sure you're getting the correct values from the file? Are you using OpenGL or Direct3D. Make sure you are using the correct vertex information with the correct parameters passed to the rendering method.
Sorry if that doesn't help much but it would be nice to have more information.
-
Looks to me like you are not loading the mesh correctly. This could be from using the wrong vertex format. Whatever FVF they are using is what you must also use when loading it or D3D will parse the info incorrectly - actually it will process it how you tell it to it's just that the info will not be in the right spot.
Most likely your FVF is simply off somewhere which is causing the distorted triangles, but like Mr. Wizard said it could be anything and w/o any code to go by...your guess is as good as ours.
-
Code:
struct md2Header {
int magic;
int version;
int skinWidth;
int skinHeight;
int frameSize;
int numSkins;
int numVertices;
int numTexCoords;
int numTriangles;
int numGlCommands;
int numFrames;
int offsetSkins;
int offsetTexCoords;
int offsetTriangles;
int offsetFrames;
int offsetGlCommands;
int offsetEnd;
};
struct md2cVert {
unsigned char Verts[3];
unsigned char LightNormalIndex;
};
struct md2Vert {
float Verts[3];
};
struct cTexCoords {
short s, t;
};
struct rTexCoords {
float s, t;
};
struct md2TrigInd {
short VertexIndicies[3];
short TextureIndicies[3];
};
struct md2Frame {
float Scale[3];
float Translate[3];
char Name[16];
md2cVert Verts[1];
};
struct md2Frame_t {
md2Vert *pVerts;
char Name[16];
};
struct md2Triangle {
float Verts[3];
float Normals[3];
};
There are my structures, perhaps somethign is wrong with them perhaps not.
Code:
FILE *pFile = fopen("tris.md2","rb");
md2Header Header;
md2Triangle *Triangles;
md2Frame *Frames;
cTexCoords *TexCoords;
fread(&Header,1,sizeof(md2Header),pFile);
Triangles = new md2Triangle[Header.numTriangles];
Frames = new md2Frame[Header.numFrames];
TexCoords = new cTexCoords[Header.numTexCoords];
fseek(pFile,Header.offsetTexCoords,SEEK_SET);
fread(TexCoords,sizeof(cTexCoords),Header.numTexCoords,pFile);
fseek(pFile,Header.offsetTriangles,SEEK_SET);
fread(Triangles,sizeof(md2Triangle),Header.numTriangles,pFile);
My loading Code (its in the winmain function as of now).
Now my rendering code:
Code:
glPushMatrix();
glScalef(.05f,.05,.05);
glBegin(GL_TRIANGLES);
for(int i = 0; i < Header.numVertices; i++) {
glTexCoord2f(TexCoords[i].s / Header.skinWidth,TexCoords[i].t / Header.skinHeight);
glVertex3f(((Frames[0].Verts[i].Verts[0] * Frames[0].Scale[0]) + Frames[0].Translate[0]),
((Frames[0].Verts[i].Verts[2] * Frames[0].Scale[2]) + Frames[2].Translate[2]),
((-1 * Frames[0].Verts[i].Verts[1] * Frames[0].Scale[1]) + Frames[1].Translate[1]));
}
glEnd();
glPopMatrix();
Edit: Sorry that I didn't post this before, but its a fair bit to look at, but if you see somethign wrong, please let me know.
-
YOu should knwo that the Frame index was changed because I was messing around with it, that doesn't make the difference, I just realized I posted it like that, sorry!
-
I don't personally have any experience with the MD2 file format. However, you could try the tutorial on MD2 models over at GameTutorials and compare your values with theirs. That is what I would do.
-
Thats what I did to get my code in the first place. Turns out I was rendering all the verticies from the array, I kinda assumed that you could render the verticies in order, but you need to use hte triangles you read in for that as well. I feel kinda stupid, but it works :D