2018-04-07 17:09:16 +05:30
|
|
|
#include "devil1geo.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2018-04-19 18:12:44 +05:30
|
|
|
static void printgheader(struct Header*);
|
|
|
|
|
|
|
|
static void printmeshheader(struct MeshHeader*);
|
|
|
|
|
|
|
|
static void printmeshbatch(struct Batch*);
|
|
|
|
|
|
|
|
static void printcoordinate(struct Coordinate*, unsigned int);
|
|
|
|
|
2018-04-24 06:13:04 +05:30
|
|
|
static bool getgheader(struct Header**, const char*);
|
2018-04-19 18:12:44 +05:30
|
|
|
|
|
|
|
static bool getmeshheader(struct MeshHeader**, unsigned int i, const char * const);
|
|
|
|
|
|
|
|
static bool getmeshbatch(struct Batch*, unsigned int offset, const char * const);
|
|
|
|
|
2018-04-20 04:38:36 +05:30
|
|
|
static bool getmesh(struct Mesh*, unsigned int i, const char*, unsigned int filesize);
|
2018-04-19 18:12:44 +05:30
|
|
|
|
2018-04-18 08:44:45 +05:30
|
|
|
fn_devil1geo const DEVIL1GEO = {printgheader,
|
|
|
|
printmeshheader,
|
|
|
|
printmeshbatch,
|
|
|
|
printcoordinate,
|
2018-04-24 05:45:56 +05:30
|
|
|
getgheader,
|
2018-04-18 08:44:45 +05:30
|
|
|
getmeshheader,
|
|
|
|
getmeshbatch,
|
|
|
|
getmesh};
|
|
|
|
|
|
|
|
static void printgheader(struct Header *gh) {
|
2018-04-07 17:09:16 +05:30
|
|
|
if (gh != NULL) {
|
2018-04-19 18:12:44 +05:30
|
|
|
printf("pointer %p\n", gh);
|
2018-04-07 17:09:16 +05:30
|
|
|
printf("number of meshes %x\n", gh -> numMesh);
|
|
|
|
printf("unknown number B %x\n", gh -> unknownNumberB);
|
|
|
|
printf("unknown number C %x\n", gh -> unknownNumberC);
|
|
|
|
printf("unknown number D %x\n", gh -> unknownNumberD);
|
2018-04-19 18:16:23 +05:30
|
|
|
printf("padding %x\n", gh -> padding);
|
|
|
|
printf("unknown offset %lx\n", gh -> unknownOffset);
|
2018-04-07 17:09:16 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-18 08:44:45 +05:30
|
|
|
static void printmeshheader(struct MeshHeader *mh) {
|
2018-04-07 17:09:16 +05:30
|
|
|
if (mh == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2018-04-19 18:16:23 +05:30
|
|
|
printf("number of batches %x\n", mh -> numBatch);
|
2018-04-07 17:09:16 +05:30
|
|
|
printf("number of vertices %x\n", mh -> numVertex);
|
2018-04-19 18:16:23 +05:30
|
|
|
printf("unknown %x\n", mh -> u);
|
|
|
|
printf("batch offset %lx\n", mh -> offsetBatches);
|
|
|
|
printf("flags %lx\n\n", mh -> flags);
|
2018-04-07 17:09:16 +05:30
|
|
|
}
|
|
|
|
|
2018-04-18 08:44:45 +05:30
|
|
|
static void printmeshbatch(struct Batch *b) {
|
2018-04-08 08:07:43 +05:30
|
|
|
if (b == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2018-04-14 03:26:14 +05:30
|
|
|
struct BatchData *bd = b -> bd;
|
|
|
|
printf("number of vertices %x\n", bd -> numVertex);
|
|
|
|
printf("unknown byte %x\n", bd -> uB);
|
|
|
|
printf("padding %x\n", bd -> padding);
|
2018-04-19 18:12:44 +05:30
|
|
|
printf("offsetPositions %lx\n", bd -> offsetPositions);
|
|
|
|
printf("offsetNormals %lx\n", bd -> offsetNormals);
|
|
|
|
printf("offsetUVs %lx\n", bd -> offsetUVs);
|
|
|
|
printf("offsetBoneIndexes %lx\n", bd -> offsetBoneIndexes);
|
|
|
|
printf("offsetBoneWeights %lx\n", bd -> offsetBoneWeights);
|
|
|
|
printf("offsets %lx\n\n", bd -> offsets[0]);
|
2018-04-14 03:26:14 +05:30
|
|
|
printcoordinate(b -> vd.positions, 3);
|
2018-04-08 08:07:43 +05:30
|
|
|
}
|
|
|
|
|
2018-04-18 08:44:45 +05:30
|
|
|
static void printcoordinate(struct Coordinate *p, unsigned int count) {
|
2018-04-08 08:07:43 +05:30
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-24 06:13:04 +05:30
|
|
|
static bool getgheader(struct Header** h, const char* filedata) {
|
2018-04-24 05:45:56 +05:30
|
|
|
if (filedata == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-24 06:13:04 +05:30
|
|
|
(*h) = (struct Header*)filedata;
|
2018-04-24 05:45:56 +05:30
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-18 08:44:45 +05:30
|
|
|
static bool getmeshheader(struct MeshHeader **hs,
|
2018-04-07 17:09:16 +05:30
|
|
|
unsigned int i,
|
|
|
|
const char * const filedata) {
|
2018-04-24 05:58:39 +05:30
|
|
|
bool done = false;
|
|
|
|
struct Header *h = NULL;
|
2018-04-24 06:13:04 +05:30
|
|
|
if (hs == NULL || !(getgheader(&h, filedata))) {
|
2018-04-07 17:09:16 +05:30
|
|
|
return done;
|
|
|
|
}
|
|
|
|
if (h -> numMesh < i) {
|
|
|
|
return done;
|
|
|
|
}
|
|
|
|
unsigned int pos = sizeof(struct MeshHeader) * i + sizeof(struct Header);
|
|
|
|
(*hs) = (struct MeshHeader*)(filedata + pos);
|
|
|
|
done = true;
|
|
|
|
return done;
|
|
|
|
}
|
2018-04-08 08:07:43 +05:30
|
|
|
|
2018-04-18 08:44:45 +05:30
|
|
|
static bool getmeshbatch(struct Batch *b,
|
2018-04-14 05:52:07 +05:30
|
|
|
unsigned int offset,
|
2018-04-08 08:07:43 +05:30
|
|
|
const char * const filedata) {
|
|
|
|
bool done = false;
|
2018-04-14 05:52:07 +05:30
|
|
|
if (b == NULL || filedata == NULL) {
|
2018-04-08 08:07:43 +05:30
|
|
|
return done;
|
|
|
|
}
|
2018-04-14 03:26:14 +05:30
|
|
|
struct BatchData *d1 = NULL;
|
|
|
|
struct VertexData d2;
|
|
|
|
d1 = (struct BatchData*) (filedata + offset);
|
|
|
|
d2.positions = (struct Coordinate*) (filedata + (d1 -> offsetPositions));
|
|
|
|
d2.normals = (struct Coordinate*) (filedata + (d1 -> offsetNormals));
|
|
|
|
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;
|
2018-04-08 08:07:43 +05:30
|
|
|
done = true;
|
|
|
|
return done;
|
|
|
|
}
|
2018-04-18 07:02:23 +05:30
|
|
|
|
|
|
|
// assume client has allocated memory for mesh
|
2018-04-18 08:44:45 +05:30
|
|
|
static bool getmesh(struct Mesh *m,
|
2018-04-18 07:02:23 +05:30
|
|
|
unsigned int i,
|
2018-04-19 18:28:35 +05:30
|
|
|
const char * const filedata,
|
|
|
|
unsigned int filesize) {
|
2018-04-18 07:02:23 +05:30
|
|
|
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);
|
2018-04-19 18:28:35 +05:30
|
|
|
if (offset > filesize) {
|
|
|
|
return done;
|
|
|
|
}
|
2018-04-18 07:02:23 +05:30
|
|
|
getmeshbatch(&b, offset, filedata);
|
2018-04-18 15:36:48 +05:30
|
|
|
// printmeshbatch(&b);
|
2018-04-18 07:02:23 +05:30
|
|
|
m -> b[j] = b;
|
|
|
|
}
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
return done;
|
|
|
|
}
|
|
|
|
|
2018-04-18 14:42:06 +05:30
|
|
|
|