Hello there, I am trying to do .md3 file loading so I can load and then convert .md3 models. I have been using the tutorial from www.gametutorials.com on .md3 loading. I have almost successfully made the load work, i.e information about the model is correct (# vertices, #triangles, header, bone, tag information all correct, i opened the model in milkshape to check this information). However the actual values for the x, y, and z coordinates of the triangles are bogus and I'm not sure how I'm readiang this data wrong. I have scrutinized my code and compared it with the gametutorials' code, but I'm not sure where I've gone wrong. I know that when working with file streams doing one thing wrong can throw everything off.
anyway here is just the code that does the reading of the files. THis is from a console app I did to just read in the file and print to the screen the values (also writes it to another confirmation text file which should exactly mirror the jibberish found in the .md3 file).
I am posting as little code as I possibly can. The defines are from the md3.h file found on gametutorials.com. I don't really expect anyone to reply to this post because I have hardly seen conversations on .md3 file loading.
Code:
#include "Md3.h"
#define Header tMd3Header
#define Mesh tMd3MeshInfo
#define Tag tMd3Tag
#define Bone tMd3Bone
#define Triangle tMd3Triangle
#define Face tMd3Face
#define TexCoord tMd3TexCoord
#define Skin tMd3Skin
vector<Mesh*> Meshes;
vector<Skin*> Skins;
vector<Face*> Faces;
vector<TexCoord*> Textures;
vector<Triangle*> Triangles;
int VectorIndices = 0;
Header pHeader;
Mesh pMesh;
Tag *pTag = NULL;
Bone *pBone = NULL;
................................................
fread(&pHeader, 1, sizeof(Header), filePtr);
pBone = new Bone[pHeader.numFrames];
fread(pBone, sizeof(Bone), pHeader.numFrames, filePtr);
delete[] pBone;
pTag = new Tag[pHeader.numTags * pHeader.numFrames];
fread(pTag, sizeof(Tag), pHeader.numTags * pHeader.numFrames, filePtr);
long offset = ftell(filePtr);
for(int index = 0; index < pHeader.numMeshes; index++) {
fseek(filePtr, offset, SEEK_SET);
fread(&pMesh, sizeof(Mesh), 1, filePtr); //READ IN ALL OF THE MESH INFORMATION
Skin *pSkin = new Skin[pMesh.numSkins];
Face *pTriangle = new Face[pMesh.numTriangles];
TexCoord *pTexCoord = new TexCoord[pMesh.numVertices];
Triangle *pVertices = new Triangle[pMesh.numVertices * pMesh.numMeshFrames];
Meshes.push_back(new Mesh);
Skins.push_back(new Skin[pMesh.numSkins]);
Faces.push_back(new Face[pMesh.numTriangles]);
Textures.push_back(new TexCoord[pMesh.numVertices]);
Triangles.push_back(new Triangle[pMesh.numVertices * pMesh.numMeshFrames]);
fread(pSkin, sizeof(Skin), pMesh.numSkins, filePtr);
fseek(filePtr, offset + pMesh.triStart, SEEK_SET);
fread(pTriangle, sizeof(Face), pMesh.numTriangles, filePtr);
fseek(filePtr, offset + pMesh.uvStart, SEEK_SET);
fread(pTexCoord, sizeof(TexCoord), pMesh.numVertices, filePtr);
fseek(filePtr, offset + pMesh.vertexStart, SEEK_SET);
fread(pVertices, sizeof(Triangle), pMesh.numVertices * pMesh.numMeshFrames, filePtr);
Meshes[VectorIndices] = &pMesh;
Skins[VectorIndices] = pSkin;
Faces[VectorIndices] = pTriangle;
Textures[VectorIndices] = pTexCoord;
Triangles[VectorIndices] = pVertices;
Confirm(pSkin, pTriangle, pTexCoord, pVertices, pMesh);
getch();
//THIS IS WHERE WE ASSIGN THE OBJECTS TO GLOBAL VARIABLES SO WE CAN THEN CONFIRM REAL DATA
//strncpy(Skins[VectorIndices]->strName, pSkin->strName, 68); //STRNAME = 68 BYTES
delete[] pSkin;
delete[] pTriangle;
delete[] pTexCoord;
delete[] pVertices;
VectorIndices++;
offset += pMesh.meshSize;
}
I've probably made tons of stupid errors, but if you could please help me out I would be very happy.
thx