mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-22 05:42:59 +05:30
Merge branch 'a/demo' of scuti/lib3ddevil1 into master
This commit is contained in:
commit
ffcd5a0e72
3
.gitignore
vendored
3
.gitignore
vendored
@ -4,6 +4,9 @@
|
||||
*.stackdump
|
||||
*.log
|
||||
devil1test
|
||||
demo-extractpld
|
||||
demo-extracttexture
|
||||
demo-extractmesh
|
||||
|
||||
# Test files
|
||||
*.dds
|
||||
|
17
Makefile
17
Makefile
@ -1,11 +1,20 @@
|
||||
EX=devil1test
|
||||
PEX=demo-extractpld
|
||||
TEX=demo-extracttexture
|
||||
MEX=demo-extractmesh
|
||||
|
||||
CC=gcc
|
||||
CFLAGS= -I"include"
|
||||
|
||||
all: main
|
||||
all: pld texture mesh
|
||||
|
||||
main: devil1pld.o devil1tex.o src/devil1geo.o
|
||||
$(CC) $^ test/main.c $(CFLAGS) -o $(EX)
|
||||
pld: devil1pld.o devil1tex.o src/devil1geo.o
|
||||
$(CC) $^ demo/pld.c $(CFLAGS) -o $(PEX)
|
||||
|
||||
texture: devil1pld.o devil1tex.o src/devil1geo.o
|
||||
$(CC) $^ demo/texture.c $(CFLAGS) -o $(TEX)
|
||||
|
||||
mesh: devil1pld.o devil1tex.o src/devil1geo.o
|
||||
$(CC) $^ demo/mesh.c $(CFLAGS) -o $(MEX)
|
||||
|
||||
devil1pld.o: src/devil1pld.c
|
||||
$(CC) -c $^ $(CFLAGS)
|
||||
|
@ -86,68 +86,3 @@ bool unpackpld(const char *filedata,
|
||||
return true;
|
||||
}
|
||||
|
||||
void exporttextures(const char *filedata,
|
||||
unsigned int filesize,
|
||||
const char *filename) {
|
||||
struct TexturePack *p = NULL;
|
||||
struct Texture *t = NULL;
|
||||
struct TextureBatchDescriptor *d = NULL;
|
||||
char * fmt = NULL;
|
||||
if (filedata == NULL || filesize == 0) {
|
||||
return;
|
||||
}
|
||||
p = (struct TexturePack*)filedata;
|
||||
fmt = (char*)malloc(strlen(filename) + 3 + 4);
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
unsigned int id = 0;
|
||||
for (i = 0; i < p -> batchNumber; i++) {
|
||||
DEVIL1TEX.getbatchdesc(&d, i, filedata, filesize);
|
||||
t = (struct Texture*)
|
||||
malloc(sizeof(struct Texture) * (d -> texNumber));
|
||||
DEVIL1TEX.gettextures(t, i, filedata, filesize);
|
||||
for (j = 0; j < d -> texNumber; j++) {
|
||||
sprintf(fmt, "%s_%d.dds", filename, id);
|
||||
write(fmt, t[j].data, d -> textureSize);
|
||||
id++;
|
||||
}
|
||||
free(t);
|
||||
}
|
||||
free(fmt);
|
||||
return;
|
||||
}
|
||||
|
||||
void extractmeshes(const char *filedata,
|
||||
unsigned int filesize,
|
||||
const char *filename) {
|
||||
if (filedata == NULL || filesize <= 0) {
|
||||
return;
|
||||
}
|
||||
struct Header *h = (struct Header*)filedata;
|
||||
struct MeshHeader *mh = NULL;
|
||||
struct Mesh m;
|
||||
m.b = NULL;
|
||||
unsigned int i;
|
||||
for (i = 0; i < h -> numMesh; i++) {
|
||||
DEVIL1GEO.getmeshheader(&mh, i, filedata);
|
||||
m.b = (struct Batch*)malloc(sizeof(struct Batch) * (mh -> numBatch));
|
||||
if (m.b != NULL) {
|
||||
DEVIL1GEO.getmesh(&m, i, filedata);
|
||||
// do something with mesh e.g write to file.
|
||||
free(m.b);
|
||||
}
|
||||
} // end for
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
char *f = argv[1];
|
||||
unsigned int bufsize = 0;
|
||||
char *buffer = loadfile(f, &bufsize);
|
||||
// unpackpld(buffer, bufsize, f);
|
||||
// exporttextures(buffer, bufsize, f);
|
||||
extractmeshes(buffer, bufsize, f);
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
38
demo/mesh.c
Normal file
38
demo/mesh.c
Normal file
@ -0,0 +1,38 @@
|
||||
#include "common.h"
|
||||
|
||||
|
||||
void extractmeshes(const char *filedata,
|
||||
unsigned int filesize,
|
||||
const char *filename) {
|
||||
if (filedata == NULL || filesize <= 0) {
|
||||
return;
|
||||
}
|
||||
struct Header *h = (struct Header*)filedata;
|
||||
struct MeshHeader *mh = NULL;
|
||||
struct Mesh m;
|
||||
m.b = NULL;
|
||||
unsigned int i;
|
||||
for (i = 0; i < h -> numMesh; i++) {
|
||||
DEVIL1GEO.getmeshheader(&mh, i, filedata);
|
||||
m.b = (struct Batch*)malloc(sizeof(struct Batch) * (mh -> numBatch));
|
||||
if (m.b != NULL) {
|
||||
DEVIL1GEO.getmesh(&m, i, filedata);
|
||||
// do something with mesh e.g write to file.
|
||||
free(m.b);
|
||||
}
|
||||
} // end for
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
char *f = argv[1];
|
||||
unsigned int bufsize = 0;
|
||||
char *buffer = loadfile(f, &bufsize);
|
||||
// unpackpld(buffer, bufsize, f);
|
||||
// exporttextures(buffer, bufsize, f);
|
||||
extractmeshes(buffer, bufsize, f);
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
11
demo/pld.c
Normal file
11
demo/pld.c
Normal file
@ -0,0 +1,11 @@
|
||||
#include "common.h"
|
||||
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
char *f = argv[1];
|
||||
unsigned int bufsize = 0;
|
||||
char *buffer = loadfile(f, &bufsize);
|
||||
unpackpld(buffer, bufsize, f);
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
44
demo/texture.c
Normal file
44
demo/texture.c
Normal file
@ -0,0 +1,44 @@
|
||||
#include "common.h"
|
||||
|
||||
|
||||
void exporttextures(const char *filedata,
|
||||
unsigned int filesize,
|
||||
const char *filename) {
|
||||
struct TexturePack *p = NULL;
|
||||
struct Texture *t = NULL;
|
||||
struct TextureBatchDescriptor *d = NULL;
|
||||
char * fmt = NULL;
|
||||
if (filedata == NULL || filesize == 0) {
|
||||
return;
|
||||
}
|
||||
p = (struct TexturePack*)filedata;
|
||||
fmt = (char*)malloc(strlen(filename) + 3 + 4);
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
unsigned int id = 0;
|
||||
for (i = 0; i < p -> batchNumber; i++) {
|
||||
DEVIL1TEX.getbatchdesc(&d, i, filedata, filesize);
|
||||
t = (struct Texture*)
|
||||
malloc(sizeof(struct Texture) * (d -> texNumber));
|
||||
DEVIL1TEX.gettextures(t, i, filedata, filesize);
|
||||
for (j = 0; j < d -> texNumber; j++) {
|
||||
sprintf(fmt, "%s_%d.dds", filename, id);
|
||||
write(fmt, t[j].data, d -> textureSize);
|
||||
id++;
|
||||
}
|
||||
free(t);
|
||||
}
|
||||
free(fmt);
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
char *f = argv[1];
|
||||
unsigned int bufsize = 0;
|
||||
char *buffer = loadfile(f, &bufsize);
|
||||
exporttextures(buffer, bufsize, f);
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user