mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-12-22 13:29:46 +05:30
Added getmesh function
This commit is contained in:
parent
383abb1607
commit
9a75cd0940
@ -52,7 +52,7 @@ struct BatchData {
|
||||
};
|
||||
|
||||
struct VertexData {
|
||||
// following structs should in an array of size numVertex
|
||||
// following structs should in an array of size 'numVertex'
|
||||
struct Coordinate *positions;
|
||||
struct Coordinate *normals;
|
||||
struct UVs *u;
|
||||
@ -60,15 +60,13 @@ struct VertexData {
|
||||
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 BatchData *bd; // pointer to region in file data
|
||||
struct VertexData vd; // collection of pointers to regions in file data
|
||||
};
|
||||
|
||||
struct Mesh {
|
||||
// may contain multiple batches
|
||||
// array of batches
|
||||
struct Batch *b;
|
||||
};
|
||||
|
||||
@ -85,10 +83,9 @@ void printcoordinate(struct Coordinate*, unsigned int);
|
||||
// ** = 'pass by reference' of a pointer to struct
|
||||
bool getmeshheader(struct MeshHeader**, unsigned int i, const char * const);
|
||||
|
||||
// ** = 'pass by reference' of a pointer to struct
|
||||
bool getmeshbatch(struct Batch*,
|
||||
unsigned int offset,
|
||||
const char * const);
|
||||
bool getmeshbatch(struct Batch*, unsigned int offset, const char * const);
|
||||
|
||||
bool getmesh(struct Mesh*, unsigned int i, const char* filename);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -88,3 +88,28 @@ bool getmeshbatch(struct Batch *b,
|
||||
done = true;
|
||||
return done;
|
||||
}
|
||||
|
||||
// assume client has allocated memory for mesh
|
||||
bool getmesh(struct Mesh *m,
|
||||
unsigned int i,
|
||||
const char * const filedata) {
|
||||
bool done = false;
|
||||
if (m == NULL || filedata == NULL || m -> b == NULL) {
|
||||
return done;
|
||||
}
|
||||
struct MeshHeader *mh = NULL;
|
||||
bool ok = getmeshheader(&mh, i, filedata);
|
||||
if (ok) {
|
||||
unsigned int j;
|
||||
struct Batch b;
|
||||
for (j = 0; j < mh -> numBatch; j++) {
|
||||
unsigned int offset = mh->offsetBatches + j * sizeof(struct BatchData);
|
||||
getmeshbatch(&b, offset, filedata);
|
||||
printmeshbatch(&b);
|
||||
m -> b[j] = b;
|
||||
}
|
||||
done = true;
|
||||
}
|
||||
return done;
|
||||
}
|
||||
|
||||
|
22
test/main.c
22
test/main.c
@ -113,20 +113,17 @@ void extractmeshes(const char *filedata,
|
||||
}
|
||||
struct Header *h = (struct Header*)filedata;
|
||||
struct MeshHeader *mh = NULL;
|
||||
struct Batch b;
|
||||
struct Mesh m;
|
||||
m.b = NULL;
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
bool ok;
|
||||
//for (i = 0; i < 5; i++) {
|
||||
for (i = 0; i < h -> numMesh; i++) {
|
||||
ok = getmeshheader(&mh, i, filedata);
|
||||
if (ok) {
|
||||
for (j = 0; j < mh -> numBatch; j++) {
|
||||
unsigned int offset = mh->offsetBatches + j * sizeof(struct BatchData);
|
||||
getmeshbatch(&b, offset, filedata);
|
||||
printmeshbatch(&b);
|
||||
} // end for
|
||||
} // end if
|
||||
getmeshheader(&mh, i, filedata);
|
||||
m.b = (struct Batch*)malloc(sizeof(struct Batch) * (mh -> numBatch));
|
||||
if (m.b != NULL) {
|
||||
getmesh(&m, i, filedata);
|
||||
// do something with mesh e.g write to file.
|
||||
free(m.b);
|
||||
}
|
||||
} // end for
|
||||
}
|
||||
|
||||
@ -141,3 +138,4 @@ int main(int argc, char ** argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user