mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-29 10:12:02 +05:30
Fixed iterating bug with initializing mesh batches
This commit is contained in:
parent
d38926b86a
commit
4df1024a55
@ -23,11 +23,7 @@ struct MeshHeader {
|
|||||||
uint64_t flags;
|
uint64_t flags;
|
||||||
}; // put these in an array of size: [header.numMesh]
|
}; // put these in an array of size: [header.numMesh]
|
||||||
|
|
||||||
struct Positions {
|
struct Coordinate {
|
||||||
float x, y, z;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Normals {
|
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -43,10 +39,7 @@ struct BoneWeights {
|
|||||||
uint16_t weights; // <format=hex>
|
uint16_t weights; // <format=hex>
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct BatchData {
|
||||||
// This is where most of the parsing will be.
|
|
||||||
// this struct is in-order of what the file format will have.
|
|
||||||
struct Batch {
|
|
||||||
int16_t numVertex;
|
int16_t numVertex;
|
||||||
int16_t uB;
|
int16_t uB;
|
||||||
uint32_t padding; // <format=hex>
|
uint32_t padding; // <format=hex>
|
||||||
@ -56,16 +49,27 @@ 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>
|
||||||
|
};
|
||||||
|
|
||||||
|
struct VertexData {
|
||||||
// following structs should in an array of size numVertex
|
// following structs should in an array of size numVertex
|
||||||
struct Positions *p;
|
struct Coordinate *positions;
|
||||||
struct Normals *n;
|
struct Coordinate *normals;
|
||||||
struct UVs *u;
|
struct UVs *u;
|
||||||
struct BoneIndexes *bi;
|
struct BoneIndexes *bi;
|
||||||
struct BoneWeights *bw;
|
struct BoneWeights *bw;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This is where most of the parsing will be.
|
||||||
|
// this struct is in-order of what the file format will have.
|
||||||
|
struct Batch {
|
||||||
|
struct BatchData *bd;
|
||||||
|
struct VertexData vd;
|
||||||
|
};
|
||||||
|
|
||||||
struct Mesh {
|
struct Mesh {
|
||||||
struct Batch b;
|
// may contain multiple batches
|
||||||
|
struct Batch *b;
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
@ -76,15 +80,13 @@ void printmeshheader(struct MeshHeader*);
|
|||||||
|
|
||||||
void printmeshbatch(struct Batch*);
|
void printmeshbatch(struct Batch*);
|
||||||
|
|
||||||
void printpositions(struct Positions*, unsigned int);
|
void printcoordinate(struct Coordinate*, unsigned int);
|
||||||
|
|
||||||
void printnormals(struct Normals*, unsigned int);
|
|
||||||
|
|
||||||
// ** = 'pass by reference' of a pointer to struct
|
// ** = '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
|
// ** = 'pass by reference' of a pointer to struct
|
||||||
bool getmeshbatch(struct Batch**,
|
bool getmeshbatch(struct Batch*,
|
||||||
struct MeshHeader*,
|
struct MeshHeader*,
|
||||||
const char * const);
|
const char * const);
|
||||||
|
|
||||||
|
@ -28,18 +28,20 @@ void printmeshbatch(struct Batch *b) {
|
|||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printf("number of vertices %x\n", b -> numVertex);
|
struct BatchData *bd = b -> bd;
|
||||||
printf("unknown byte %x\n", b -> uB);
|
printf("number of vertices %x\n", bd -> numVertex);
|
||||||
printf("padding %x\n", b -> padding);
|
printf("unknown byte %x\n", bd -> uB);
|
||||||
printf("offsetPositions %x\n", b -> offsetPositions);
|
printf("padding %x\n", bd -> padding);
|
||||||
printf("offsetNormals %x\n", b -> offsetNormals);
|
printf("offsetPositions %x\n", bd -> offsetPositions);
|
||||||
printf("offsetUVs %x\n", b -> offsetUVs);
|
printf("offsetNormals %x\n", bd -> offsetNormals);
|
||||||
printf("offsetBoneIndexes %x\n", b -> offsetBoneIndexes);
|
printf("offsetUVs %x\n", bd -> offsetUVs);
|
||||||
printf("offsetBoneWeights %x\n", b -> offsetBoneWeights);
|
printf("offsetBoneIndexes %x\n", bd -> offsetBoneIndexes);
|
||||||
printf("offsets %x\n\n", b -> offsets[0]);
|
printf("offsetBoneWeights %x\n", bd -> offsetBoneWeights);
|
||||||
|
printf("offsets %x\n\n", bd -> offsets[0]);
|
||||||
|
printcoordinate(b -> vd.positions, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printpositions(struct Positions *p, unsigned int count) {
|
void printcoordinate(struct Coordinate *p, unsigned int count) {
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -49,16 +51,6 @@ void printpositions(struct Positions *p, unsigned int count) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void printnormals(struct Normals *n, unsigned int count) {
|
|
||||||
if (n == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
unsigned int i;
|
|
||||||
for (i = 0; i < count; i++) {
|
|
||||||
printf("(%f, %f, %f)\n", (n[i]).x, (n[i]).y, (n[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) {
|
||||||
@ -76,7 +68,7 @@ bool getmeshheader(struct MeshHeader **hs,
|
|||||||
return done;
|
return done;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool getmeshbatch(struct Batch **b,
|
bool getmeshbatch(struct Batch *b,
|
||||||
struct MeshHeader *h,
|
struct MeshHeader *h,
|
||||||
const char * const filedata) {
|
const char * const filedata) {
|
||||||
bool done = false;
|
bool done = false;
|
||||||
@ -84,12 +76,16 @@ bool getmeshbatch(struct Batch **b,
|
|||||||
return done;
|
return done;
|
||||||
}
|
}
|
||||||
unsigned int offset = h -> offsetBatches;
|
unsigned int offset = h -> offsetBatches;
|
||||||
*b = (struct Batch*)(filedata + offset);
|
struct BatchData *d1 = NULL;
|
||||||
(*b) -> p = (struct Positions*)(filedata + ((*b) -> offsetPositions));
|
struct VertexData d2;
|
||||||
(*b) -> n = (struct Normals*)(filedata + ((*b) -> offsetNormals));
|
d1 = (struct BatchData*) (filedata + offset);
|
||||||
(*b) -> u = (struct UVs*)(filedata + ((*b) -> offsetUVs));
|
d2.positions = (struct Coordinate*) (filedata + (d1 -> offsetPositions));
|
||||||
(*b) -> bi = (struct BoneIndexes*)(filedata + ((*b) -> offsetBoneIndexes));
|
d2.normals = (struct Coordinate*) (filedata + (d1 -> offsetNormals));
|
||||||
(*b) -> bw = (struct BoneWeights*)(filedata + ((*b) -> offsetBoneWeights));
|
d2.u = (struct UVs*) (filedata + (d1 -> offsetUVs));
|
||||||
|
d2.bi = (struct BoneIndexes*)(filedata + (d1 -> offsetBoneIndexes));
|
||||||
|
d2.bw = (struct BoneWeights*)(filedata + (d1 -> offsetBoneWeights));
|
||||||
|
b -> bd = d1;
|
||||||
|
b -> vd = d2;
|
||||||
done = true;
|
done = true;
|
||||||
return done;
|
return done;
|
||||||
}
|
}
|
||||||
|
10
test/main.c
10
test/main.c
@ -113,18 +113,18 @@ 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;
|
struct Batch b;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
bool ok;
|
bool ok;
|
||||||
//h -> numMesh
|
//h -> numMesh
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < h -> numMesh; i++) {
|
||||||
ok = getmeshheader(&mh, i, filedata);
|
ok = getmeshheader(&mh, i, filedata);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
for (j = 0; j < mh -> numBatch; j++) {
|
// for (j = 0; j < mh -> numBatch; j++) {
|
||||||
getmeshbatch(&b, mh, filedata);
|
getmeshbatch(&b, mh, filedata);
|
||||||
printmeshbatch(b);
|
printmeshbatch(&b);
|
||||||
} // end for
|
// } // end for
|
||||||
} // end if
|
} // end if
|
||||||
} // end for
|
} // end for
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user