typedef struct { int facetype; int splitcount; int indexcount; int **split; } binmesh; typedef struct { char *texture; char *alpha; char color[4]; } material; typedef struct { char Textured; char Modulate; char Light; char Normals; char Prelit; char Textured2; char Positions; char Tristrip; short flags; int facecount; int vertexcount; int framecount; float Ambient; float Diffuse; float Specular; char *vcolor; float *uv; short *faces; float *vertices; float *normals; char *name; int matcount; int viewable; material *mat; binmesh bm; } geometry; typedef struct { float rotmatrix[9]; float pos[3]; int parent; char *name; int isgeo; int geo; } frame; typedef struct { int frameindex; int geometryindex; } atomic; int geometrycount; int framecount; int objectcount; int version; geometry *geo; frame *frm; atomic *atm; /* skips rw header and returns size */ int skipheader(FILE *rw) { int size; fseek(rw, 4, SEEK_CUR); fread(&size, 4, 1, rw); fseek(rw, 4, SEEK_CUR); return size; } int IsGeo(int frameno) { int objectno; if(frameno > framecount) printf("Error in function IsGeo()\n "); for(objectno = 0; objectno < objectcount; objectno++) { if(frameno == atm[objectno].frameindex) { return 1; } } return 0; } int calculateflags(int j) { geo[j].Tristrip = geo[j].flags & 0x01; geo[j].flags >>= 1; geo[j].Positions = geo[j].flags & 0x01; geo[j].flags >>= 1; geo[j].Textured = geo[j].flags & 0x01; geo[j].flags >>= 1; geo[j].Prelit = geo[j].flags & 0x01; geo[j].flags >>= 1; geo[j].Normals = geo[j].flags & 0x01; geo[j].flags >>= 1; geo[j].Light = geo[j].flags & 0x01; geo[j].flags >>= 1; geo[j].Modulate = geo[j].flags & 0x01; geo[j].flags >>= 1; geo[j].Textured2 = geo[j].flags & 0x01; geo[j].flags >>= 1; } int DffLoad(char *filename) { FILE *dff; int size, size2, size3; int matsize, matsize2; int texcount; int i, j, k, l; if((dff = fopen(filename, "r")) == NULL) { printf("Error, could not open %s\n", filename); return 0; } fseek(dff, 8, SEEK_CUR); //clump fread(&version, 4, 1, dff); //get file version size = skipheader(dff) + ftell(dff); //struct fread(&objectcount, 4, 1, dff); atm = (atomic *) malloc(objectcount*sizeof(atomic)); fseek(dff, size, 0); // // Frame // size = skipheader(dff) + ftell(dff);; //frame list skipheader(dff); //struct fread(&framecount, 4, 1, dff); frm = (frame *) malloc(framecount*sizeof(frame)); for(j = 0; j < framecount; j++) { fread(&frm[j].rotmatrix, 4, 9, dff); fread(&frm[j].pos, 4, 3, dff); fread(&frm[j].parent, 4, 1, dff); fseek(dff, 4, SEEK_CUR); } printf("hello\n"); for(j = 0; j , j < framecount; j++) { size2 = skipheader(dff) + ftell(dff); // Extension size3 = skipheader(dff) + ftell(dff); // Frame frm[j].name = (char *) malloc(size3+1); // make room for frame name fread(frm[j].name, size3, 1, dff); // read name // \0 is still missing fseek(dff, size2, 0); // goto next section (ignore hanim plg) } fseek(dff, size, 0); // // Geometry // //printf("Before Geometry %X\n", ftell(dff)); skipheader(dff); //geometry list size = skipheader(dff); //struct fread(&geometrycount, 4, 1, dff); geo = (geometry *) malloc(geometrycount*sizeof(geometry)); for(j = 0; j < geometrycount; j++) { size2 = skipheader(dff) + ftell(dff); //geometry size = skipheader(dff); //struct fread(&geo[j].flags, 2, 1, dff); calculateflags(j); fseek(dff, 2, SEEK_CUR); //unknown fread(&geo[j].facecount, 4, 1, dff); fread(&geo[j].vertexcount, 4, 1, dff); fread(&geo[j].framecount, 4, 1, dff); if(version == 0x0c02ffff || version == 0x0800ffff) { fread(&geo[j].Ambient, 4, 1, dff); fread(&geo[j].Diffuse, 4, 1, dff); fread(&geo[j].Specular, 4, 1, dff); } geo[j].viewable = 1; // Vertex colors if(geo[j].Prelit) { geo[j].vcolor = (char *) malloc(4*geo[j].vertexcount); for(i = 0; i < geo[j].vertexcount*4; i++) { geo[i].vcolor[i] = getc(dff); } } // UV coords if(geo[j].Textured) { geo[j].uv = (float *) malloc(8*geo[j].vertexcount); fread(geo[j].uv, geo[j].vertexcount, 8, dff); } // Faces geo[j].faces = (short *) malloc(8*geo[j].facecount); fread(geo[j].faces, geo[j].facecount, 8, dff); // skip bounding sphere and 2 unknown ints fseek(dff, 24, SEEK_CUR); // Vertices geo[j].vertices = (float *) malloc(12*geo[j].vertexcount); fread(geo[j].vertices, geo[j].vertexcount, 12, dff); // Normals if(geo[j].Normals) { geo[j].normals = (float *) malloc(12*geo[j].vertexcount); fread(geo[j].normals, geo[j].vertexcount, 12, dff); } // Now we are at the Material List skipheader(dff); // Material List size = skipheader(dff); // Struct fread(&geo[j].matcount, 4, 1, dff); fseek(dff, size-4, SEEK_CUR); geo[j].mat = (material *) malloc(geo[j].matcount*sizeof(material)); for(k = 0; k < geo[j].matcount; k++) { matsize = skipheader(dff)+ftell(dff); // material matsize2 = skipheader(dff); // struct fseek(dff, 4, SEEK_CUR); fread(geo[j].mat[k].color, 4, 1, dff); fseek(dff, 4, SEEK_CUR); fread(&texcount, 4, 1, dff); fseek(dff, 12, SEEK_CUR); skipheader(dff); // texture matsize2 = skipheader(dff); // struct fseek(dff, matsize2, SEEK_CUR); if(texcount == 1) { matsize2 = skipheader(dff); // string geo[j].mat[k].texture = (char *) malloc(matsize2); fread(geo[j].mat[k].texture, matsize2, 1, dff); // texturename matsize2 = skipheader(dff); // string geo[j].mat[k].alpha = (char *) malloc(matsize2); fread(geo[j].mat[k].alpha, matsize2, 1, dff); // alphaname } fseek(dff, matsize, 0); //skipheader(dff); // Extension //skipheader(dff); // Bin Mesh PLG //fread(&geo[j].bm.facetype, 4, 1, dff); //fread(&geo[j].bm.splitcount, 4, 1, dff); //fread(&geo[j].bm.indexcount, 4, 1, dff); //*geo[j].bm.split = (int *) malloc(geo[j].bm.splitcount*sizeof(int)); } fseek(dff, size2, 0); } // // Atomic // printf("Before Atomic %X\n", ftell(dff)); for(j = 0; j < objectcount; j++) { size = skipheader(dff) + ftell(dff); // Atomic skipheader(dff); // Struct fread(&atm[j].frameindex, 4, 1, dff); fread(&atm[j].geometryindex, 4, 1, dff); fseek(dff, size, 0); } for(i = 0; i < objectcount; i++) { // write geometryindex into frame struct frm[atm[i].frameindex].geo = atm[i].geometryindex; } for(i = 0; i < framecount; i++) { // check if frame has geometry frm[i].isgeo = IsGeo(i); } /* for(i = 0; i < framecount; i++) { printf("frm[%d].isgeo = %d, frm[%d].geo = %d\n", i, frm[i].isgeo, i, frm[i].geo); } */ }