Wrote 'dump' of batch data

This commit is contained in:
_ 2018-04-18 02:12:06 -07:00
parent ecc206b5e8
commit 240864050e
3 changed files with 32 additions and 2 deletions

View File

@ -44,10 +44,24 @@ void write(const char *filename,
written = fwrite(t, sizeof(unsigned char), size, out); written = fwrite(t, sizeof(unsigned char), size, out);
fclose(out); fclose(out);
if (written == 0) { if (written == 0) {
perror("texture write error"); perror("write error");
} }
} }
} }
void append(const char *filename, const char *t, unsigned size) {
if (filename == NULL) {
return;
}
unsigned int written = 0;
FILE *out = fopen(filename, "ab");
if (out != NULL) {
written = fwrite(t, sizeof(unsigned char), size, out);
fclose(out);
if (written == 0) {
perror("write error");
}
printf("wrote %d\n", written);
}
}

View File

@ -1,6 +1,20 @@
#include "common.h" #include "common.h"
#include "devil1geo.h" #include "devil1geo.h"
void writemesh(struct MeshHeader *mh, struct Mesh *m, const char *filename, unsigned int i) {
char *fn = (char*)malloc(strlen(filename) + 3 + 4);
sprintf(fn, "%s_%d.msh", filename, i);
unsigned int vertices = m -> b -> bd -> numVertex;
write(fn, (char*)mh, sizeof(struct MeshHeader));
append(fn, (char*)(m -> b -> bd), sizeof(struct BatchData));
append(fn, (char*)(m -> b -> vd.positions), sizeof(struct Coordinate) * vertices);
append(fn, (char*)(m -> b -> vd.normals), sizeof(struct Coordinate) * vertices);
append(fn, (char*)(m -> b -> vd.u), sizeof(struct UVs) * vertices);
append(fn, (char*)(m -> b -> vd.bi), sizeof(struct BoneIndexes) * vertices);
append(fn, (char*)(m -> b -> vd.bw), sizeof(struct BoneWeights) * vertices);
free(fn);
}
void extractmeshes(const char *filedata, void extractmeshes(const char *filedata,
unsigned int filesize, unsigned int filesize,
const char *filename) { const char *filename) {
@ -18,6 +32,7 @@ void extractmeshes(const char *filedata,
if (m.b != NULL) { if (m.b != NULL) {
DEVIL1GEO.getmesh(&m, i, filedata); DEVIL1GEO.getmesh(&m, i, filedata);
// do something with mesh e.g write to file. // do something with mesh e.g write to file.
writemesh(mh, &m, filename, i);
free(m.b); free(m.b);
} }
} // end for } // end for

View File

@ -121,3 +121,4 @@ static bool getmesh(struct Mesh *m,
return done; return done;
} }