mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-22 22:03:00 +05:30
Implemented correct initialization of batch and positions array
This commit is contained in:
parent
cc31734e44
commit
fb962d2ffe
@ -56,7 +56,6 @@ struct Batch {
|
|||||||
uint64_t offsetBoneIndexes; // <format=hex>
|
uint64_t offsetBoneIndexes; // <format=hex>
|
||||||
uint64_t offsetBoneWeights; // <format=hex>
|
uint64_t offsetBoneWeights; // <format=hex>
|
||||||
uint64_t offsets[1]; // <format=hex>
|
uint64_t offsets[1]; // <format=hex>
|
||||||
int64_t pos; // set while parsing batch from ftell();
|
|
||||||
// following structs should in an array of size numVertex
|
// following structs should in an array of size numVertex
|
||||||
struct Positions *p;
|
struct Positions *p;
|
||||||
struct Normals *n;
|
struct Normals *n;
|
||||||
@ -73,7 +72,17 @@ void printgheader(struct Header*);
|
|||||||
|
|
||||||
void printmeshheader(struct MeshHeader*);
|
void printmeshheader(struct MeshHeader*);
|
||||||
|
|
||||||
|
void printmeshbatch(struct Batch*);
|
||||||
|
|
||||||
|
void printpositions(struct Positions*, unsigned int);
|
||||||
|
|
||||||
|
// ** = 'pass by reference' of a pointer to struct
|
||||||
bool getmeshheader(struct MeshHeader**, unsigned int i, const char * const);
|
bool getmeshheader(struct MeshHeader**, unsigned int i, const char * const);
|
||||||
|
|
||||||
|
// ** = 'pass by reference' of a pointer to struct
|
||||||
|
bool getmeshbatch(struct Batch**,
|
||||||
|
struct MeshHeader*,
|
||||||
|
const char * const);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -24,6 +24,31 @@ void printmeshheader(struct MeshHeader *mh) {
|
|||||||
printf("flags %x\n\n", mh -> flags);
|
printf("flags %x\n\n", mh -> flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printmeshbatch(struct Batch *b) {
|
||||||
|
if (b == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
printf("number of vertices %x\n", b -> numVertex);
|
||||||
|
printf("unknown byte %x\n", b -> uB);
|
||||||
|
printf("padding %x\n", b -> padding);
|
||||||
|
printf("offsetPositions %x\n", b -> offsetPositions);
|
||||||
|
printf("offsetNormals %x\n", b -> offsetNormals);
|
||||||
|
printf("offsetUVs %x\n", b -> offsetUVs);
|
||||||
|
printf("offsetBoneIndexes %x\n", b -> offsetBoneIndexes);
|
||||||
|
printf("offsetBoneWeights %x\n", b -> offsetBoneWeights);
|
||||||
|
printf("offsets %x\n\n", b -> offsets[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printpositions(struct Positions *p, unsigned int count) {
|
||||||
|
if (p == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; i < count; i++) {
|
||||||
|
printf("(%f, %f, %f)\n", (p[i]).x, (p[i]).y, (p[i]).z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool getmeshheader(struct MeshHeader **hs,
|
bool getmeshheader(struct MeshHeader **hs,
|
||||||
unsigned int i,
|
unsigned int i,
|
||||||
const char * const filedata) {
|
const char * const filedata) {
|
||||||
@ -40,3 +65,23 @@ bool getmeshheader(struct MeshHeader **hs,
|
|||||||
done = true;
|
done = true;
|
||||||
return done;
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool getmeshbatch(struct Batch **b,
|
||||||
|
struct MeshHeader *h,
|
||||||
|
const char * const filedata) {
|
||||||
|
bool done = false;
|
||||||
|
if (b == NULL || h == NULL || filedata == NULL) {
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
unsigned int offset = h -> offsetBatches;
|
||||||
|
*b = (struct Batch*)(filedata + offset);
|
||||||
|
(*b) -> p = (struct Positions*)(filedata + ((*b) -> offsetPositions));
|
||||||
|
printf("p = %x\n", (*b) -> offsetPositions);
|
||||||
|
printpositions((*b) -> p, 3);
|
||||||
|
(*b) -> n = NULL;
|
||||||
|
(*b) -> u = NULL;
|
||||||
|
(*b) -> bi = NULL;
|
||||||
|
(*b) -> bw = NULL;
|
||||||
|
done = true;
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
@ -105,7 +105,7 @@ void exporttextures(const char *filedata,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void extractmeshes(const char* filedata,
|
void extractmeshes(const char *filedata,
|
||||||
unsigned int filesize,
|
unsigned int filesize,
|
||||||
const char *filename) {
|
const char *filename) {
|
||||||
if (filedata == NULL || filesize <= 0) {
|
if (filedata == NULL || filesize <= 0) {
|
||||||
@ -113,12 +113,15 @@ void extractmeshes(const char* filedata,
|
|||||||
}
|
}
|
||||||
struct Header *h = (struct Header*)filedata;
|
struct Header *h = (struct Header*)filedata;
|
||||||
struct MeshHeader *mh = NULL;
|
struct MeshHeader *mh = NULL;
|
||||||
|
struct Batch *b = NULL;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
bool ok;
|
bool ok;
|
||||||
for (i = 0; i < h -> numMesh; i++) {
|
//h -> numMesh
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
ok = getmeshheader(&mh, i, filedata);
|
ok = getmeshheader(&mh, i, filedata);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
printmeshheader(mh);
|
getmeshbatch(&b, mh, filedata);
|
||||||
|
printmeshbatch(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user