mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-25 16:28:57 +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) {
|
if (written == 0) {
|
||||||
perror("write error");
|
perror("write error");
|
||||||
}
|
}
|
||||||
printf("wrote %d\n", written);
|
printf("wrote %x\n", written);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,37 @@
|
|||||||
#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) {
|
void writemesh(const struct MeshHeader *mh,
|
||||||
|
const struct Mesh *m,
|
||||||
|
const char *filename,
|
||||||
|
unsigned int i) {
|
||||||
char *fn = (char*)malloc(strlen(filename) + 3 + 4);
|
char *fn = (char*)malloc(strlen(filename) + 3 + 4);
|
||||||
sprintf(fn, "%s_%d.msh", filename, i);
|
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;
|
unsigned int vertices = m -> b -> bd -> numVertex;
|
||||||
write(fn, (char*)mh, sizeof(struct MeshHeader));
|
newbatch.offsetPositions = sizeof(struct MeshHeader) + sizeof(struct BatchData);
|
||||||
append(fn, (char*)(m -> b -> bd), 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);
|
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.normals), sizeof(struct Coordinate) * vertices);
|
||||||
append(fn, (char*)(m -> b -> vd.u), sizeof(struct UVs) * 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.bi), sizeof(struct BoneIndexes) * vertices);
|
||||||
@ -31,7 +55,6 @@ void extractmeshes(const char *filedata,
|
|||||||
m.b = (struct Batch*)malloc(sizeof(struct Batch) * (mh -> numBatch));
|
m.b = (struct Batch*)malloc(sizeof(struct Batch) * (mh -> numBatch));
|
||||||
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.
|
|
||||||
writemesh(mh, &m, filename, i);
|
writemesh(mh, &m, filename, i);
|
||||||
free(m.b);
|
free(m.b);
|
||||||
}
|
}
|
||||||
@ -43,8 +66,6 @@ int main(int argc, char ** argv) {
|
|||||||
char *f = argv[1];
|
char *f = argv[1];
|
||||||
unsigned int bufsize = 0;
|
unsigned int bufsize = 0;
|
||||||
char *buffer = loadfile(f, &bufsize);
|
char *buffer = loadfile(f, &bufsize);
|
||||||
// unpackpld(buffer, bufsize, f);
|
|
||||||
// exporttextures(buffer, bufsize, f);
|
|
||||||
extractmeshes(buffer, bufsize, f);
|
extractmeshes(buffer, bufsize, f);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -113,7 +113,7 @@ static bool getmesh(struct Mesh *m,
|
|||||||
for (j = 0; j < mh -> numBatch; j++) {
|
for (j = 0; j < mh -> numBatch; j++) {
|
||||||
unsigned int offset = mh->offsetBatches + j * sizeof(struct BatchData);
|
unsigned int offset = mh->offsetBatches + j * sizeof(struct BatchData);
|
||||||
getmeshbatch(&b, offset, filedata);
|
getmeshbatch(&b, offset, filedata);
|
||||||
printmeshbatch(&b);
|
// printmeshbatch(&b);
|
||||||
m -> b[j] = b;
|
m -> b[j] = b;
|
||||||
}
|
}
|
||||||
done = true;
|
done = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user