diff --git a/demo/common.h b/demo/common.h index 9d3d888..37779d4 100644 --- a/demo/common.h +++ b/demo/common.h @@ -44,10 +44,24 @@ void write(const char *filename, written = fwrite(t, sizeof(unsigned char), size, out); fclose(out); 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); + } +} diff --git a/demo/extractmesh.c b/demo/extractmesh.c index 2ce3c6e..6b6a983 100644 --- a/demo/extractmesh.c +++ b/demo/extractmesh.c @@ -1,6 +1,20 @@ #include "common.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, unsigned int filesize, const char *filename) { @@ -18,6 +32,7 @@ void extractmeshes(const char *filedata, if (m.b != NULL) { DEVIL1GEO.getmesh(&m, i, filedata); // do something with mesh e.g write to file. + writemesh(mh, &m, filename, i); free(m.b); } } // end for diff --git a/src/devil1geo.c b/src/devil1geo.c index bf3cfb2..2882bd2 100644 --- a/src/devil1geo.c +++ b/src/devil1geo.c @@ -121,3 +121,4 @@ static bool getmesh(struct Mesh *m, return done; } +