mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-25 16:28:57 +05:30
Added function to get mesh headers
This commit is contained in:
parent
5b40ffb00b
commit
0e5c96b83b
5
Makefile
5
Makefile
@ -4,7 +4,7 @@ CFLAGS= -I"include"
|
||||
|
||||
all: main
|
||||
|
||||
main: devil1pld.o devil1tex.o
|
||||
main: devil1pld.o devil1tex.o src/devil1geo.o
|
||||
$(CC) $^ test/main.c $(CFLAGS) -o $(EX)
|
||||
|
||||
devil1pld.o: src/devil1pld.c
|
||||
@ -13,5 +13,8 @@ devil1pld.o: src/devil1pld.c
|
||||
devil1tex.o: src/devil1tex.c
|
||||
$(CC) -c $^ $(CFLAGS)
|
||||
|
||||
devil1geo.o: src/devil1geo.c
|
||||
$(CC) -c $^ $(CFLAGS)
|
||||
|
||||
clean:
|
||||
rm *.o $(EX)
|
||||
|
@ -2,7 +2,10 @@
|
||||
#ifndef DEVIL1GEO_H
|
||||
#define DEVIL1GEO_H
|
||||
#include <stdint.h>
|
||||
#pragma pack(1)
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct Header {
|
||||
unsigned char numMesh;
|
||||
unsigned char unknownNumberB;
|
||||
@ -12,7 +15,7 @@ struct Header {
|
||||
uint64_t unknownOffset;
|
||||
};
|
||||
|
||||
struct MeshHeaders {
|
||||
struct MeshHeader {
|
||||
int16_t numBatch;
|
||||
int16_t numVertex;
|
||||
uint32_t u; // <format=hex>
|
||||
@ -39,6 +42,7 @@ struct BoneIndexes {
|
||||
struct BoneWeights {
|
||||
uint16_t weights; // <format=hex>
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
// This is where most of the parsing will be.
|
||||
// this struct is in-order of what the file format will have.
|
||||
@ -65,5 +69,9 @@ struct Mesh {
|
||||
struct Batch b;
|
||||
};
|
||||
|
||||
void printgheader(struct Header*);
|
||||
|
||||
bool getmeshheaders(struct MeshHeader **, const char *, unsigned int);
|
||||
|
||||
#endif
|
||||
|
||||
|
24
test/main.c
24
test/main.c
@ -5,6 +5,7 @@
|
||||
|
||||
#include "devil1pld.h"
|
||||
#include "devil1tex.h"
|
||||
#include "devil1geo.h"
|
||||
|
||||
char *loadfile(const char *fname, unsigned int *s) {
|
||||
FILE *f = fopen(fname, "rb");
|
||||
@ -104,12 +105,33 @@ void exporttextures(const char *filedata,
|
||||
return;
|
||||
}
|
||||
|
||||
void extractmeshes(const char* filedata,
|
||||
unsigned int filesize,
|
||||
const char *filename) {
|
||||
if (filedata == NULL || filesize <= 0) {
|
||||
return;
|
||||
}
|
||||
struct Header *h = NULL;
|
||||
h = (struct Header*)filedata;
|
||||
printf("pointer %x\n", h);
|
||||
printgheader(h);
|
||||
struct MeshHeader **mh = NULL;
|
||||
mh = (struct MeshHeader**)
|
||||
malloc(sizeof(struct MeshHeader*) * h -> numMesh);
|
||||
getmeshheaders(mh, filedata, filesize);
|
||||
unsigned int i;
|
||||
for (i = 0; i < h -> numMesh; i++) {
|
||||
printf("returning %x \n", mh[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
char *f = argv[1];
|
||||
unsigned int bufsize = 0;
|
||||
char *buffer = loadfile(f, &bufsize);
|
||||
unpackpld(buffer, bufsize, f);
|
||||
// unpackpld(buffer, bufsize, f);
|
||||
// exporttextures(buffer, bufsize, f);
|
||||
extractmeshes(buffer, bufsize, f);
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user