mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-29 10:12:02 +05:30
Updated offset related attributes before file write.
This commit is contained in:
parent
240864050e
commit
ceb6409abd
@ -62,6 +62,6 @@ void append(const char *filename, const char *t, unsigned size) {
|
||||
if (written == 0) {
|
||||
perror("write error");
|
||||
}
|
||||
printf("wrote %d\n", written);
|
||||
printf("wrote %x\n", written);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,37 @@
|
||||
#include "common.h"
|
||||
#include "devil1geo.h"
|
||||
|
||||
void writemesh(struct MeshHeader *mh, struct Mesh *m, const char *filename, unsigned int i) {
|
||||
void writemesh(const struct MeshHeader *mh,
|
||||
const struct Mesh *m,
|
||||
const char *filename,
|
||||
unsigned int i) {
|
||||
char *fn = (char*)malloc(strlen(filename) + 3 + 4);
|
||||
sprintf(fn, "%s_%d.msh", filename, i);
|
||||
struct Header h = {
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0xCCCCCCCC,
|
||||
0
|
||||
};
|
||||
// mesh header offset batches need to be changed for compability with parsing.
|
||||
struct MeshHeader newmh = *(mh);
|
||||
newmh.offsetBatches = sizeof(struct Header) + sizeof(struct MeshHeader);
|
||||
// batch data the same treatment.
|
||||
struct BatchData newbatch = *(m -> b) -> bd;
|
||||
unsigned int vertices = m -> b -> bd -> numVertex;
|
||||
write(fn, (char*)mh, sizeof(struct MeshHeader));
|
||||
append(fn, (char*)(m -> b -> bd), sizeof(struct BatchData));
|
||||
newbatch.offsetPositions = sizeof(struct MeshHeader) + sizeof(struct BatchData);
|
||||
newbatch.offsetNormals = newbatch.offsetPositions + (sizeof(struct Coordinate) * vertices);
|
||||
newbatch.offsetUVs = newbatch.offsetNormals + (sizeof(struct Coordinate) * vertices);
|
||||
newbatch.offsetBoneIndexes = newbatch.offsetUVs + (sizeof(struct UVs) * vertices);
|
||||
newbatch.offsetBoneWeights = newbatch.offsetBoneIndexes + (sizeof(struct BoneIndexes) * vertices);
|
||||
// write to file.
|
||||
write(fn, (char*)(&h), sizeof(struct Header));
|
||||
append(fn, (char*)(&newmh), sizeof(struct MeshHeader));
|
||||
append(fn, (char*)(&newbatch), sizeof(struct BatchData));
|
||||
append(fn, (char*)(m -> b -> vd.positions), sizeof(struct Coordinate) * vertices);
|
||||
DEVIL1GEO.printcoordinate(m -> b -> vd.positions, 3);
|
||||
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);
|
||||
@ -31,7 +55,6 @@ void extractmeshes(const char *filedata,
|
||||
m.b = (struct Batch*)malloc(sizeof(struct Batch) * (mh -> numBatch));
|
||||
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);
|
||||
}
|
||||
@ -43,8 +66,6 @@ int main(int argc, char ** argv) {
|
||||
char *f = argv[1];
|
||||
unsigned int bufsize = 0;
|
||||
char *buffer = loadfile(f, &bufsize);
|
||||
// unpackpld(buffer, bufsize, f);
|
||||
// exporttextures(buffer, bufsize, f);
|
||||
extractmeshes(buffer, bufsize, f);
|
||||
free(buffer);
|
||||
return 0;
|
||||
|
@ -113,7 +113,7 @@ static bool getmesh(struct Mesh *m,
|
||||
for (j = 0; j < mh -> numBatch; j++) {
|
||||
unsigned int offset = mh->offsetBatches + j * sizeof(struct BatchData);
|
||||
getmeshbatch(&b, offset, filedata);
|
||||
printmeshbatch(&b);
|
||||
// printmeshbatch(&b);
|
||||
m -> b[j] = b;
|
||||
}
|
||||
done = true;
|
||||
|
Loading…
Reference in New Issue
Block a user