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