mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-12-22 21:39:47 +05:30
Wrote 'dump' of batch data
This commit is contained in:
parent
ecc206b5e8
commit
240864050e
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -121,3 +121,4 @@ static bool getmesh(struct Mesh *m,
|
||||
return done;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user