Cleanup model list and some model loading code

This commit is contained in:
ROllerozxa 2023-12-28 21:52:59 +01:00
commit 25f11443df
7 changed files with 352 additions and 717 deletions

File diff suppressed because it is too large Load diff

View file

@ -303,7 +303,6 @@ enum {
MODEL_PLANT3,
MODEL_PLANT4,
MODEL_WAR_AXE,
//MODEL_BANNER,
MODEL_PIXEL_SWORD,
MODEL_HARD_HAT,
MODEL_SERPENT_SWORD,

View file

@ -99,27 +99,23 @@ tms_model_shift_mesh_uv(struct tms_model *m,
struct tms_mesh *
tms_model_load(struct tms_model *m, const char *filename, int *status)
{
const char *ext = strrchr(filename, '.')+1;
const char *ext = strrchr(filename, '.');
struct tms_mesh *ret = 0;
*status = T_ERR;
if (ext != 1) {
if (ext) {
struct tms_mesh * (*loader)(struct tms_model *, SDL_RWops *, int *)
= thash_get(tms.model_loaders, ext, strlen(ext));
if (!loader) {
tms_errorf("unsupported model format: %s", ext);
*status = T_UNSUPPORTED_FILE_FORMAT;
return 0;
tms_fatalf("unsupported model format: %s", ext);
}
SDL_RWops *fp = SDL_RWFromFile(filename,"rb");
if (!fp) {
tms_errorf("could not open model file: %s", filename);
*status = T_COULD_NOT_OPEN;
return 0;
tms_fatalf("could not open model file: %s", filename);
}
ret = loader(m, fp, status);

View file

@ -1,6 +0,0 @@
#ifndef _TMS_MODULE__H_
#define _TMS_MODULE__H_
#include "glob.h"
#endif

View file

@ -1,9 +1,6 @@
#ifndef _TMS_SETTINGS__H_
#define _TMS_SETTINGS__H_
#define TMS_MESH_MAX_ATTRIBUTES 64
#define TMS_MESH_MAX_TEXTURES 8
#define TMS_NUM_PIPELINES 4
#endif

View file

@ -14,7 +14,7 @@ static struct tms_mesh * load_3ds_model(struct tms_model *model, SDL_RWops *fp,
void
tmod_3ds_init(void)
{
tms_register_model_loader(load_3ds_model, "3ds");
tms_register_model_loader(load_3ds_model, ".3ds");
}
static struct tms_mesh *
@ -39,13 +39,11 @@ load_3ds_model(struct tms_model *model,
filesz = SDL_RWtell(fp);
SDL_RWseek(fp, 0, SEEK_SET);
//tms_infof("3DS FILE SIZE: %d", (int)filesz);
tms_infof("3DS FILE SIZE: %d", (int)filesz);
while (SDL_RWtell(fp) < filesz) {
SDL_RWread(fp, &chunk_id, 2, 1);
SDL_RWread(fp, &chunk_len, 4, 1);
//fread(&chunk_id, 2, 1, fp);
//fread(&chunk_len, 4, 1, fp);
//tms_debugf("chunk id: %x, chunk size: %d", chunk_id, chunk_len);
@ -74,7 +72,7 @@ load_3ds_model(struct tms_model *model,
case 0x4110: /* vertices list */
SDL_RWread(fp, &num_items, 2, 1);
//fread(&num_items, 2, 1, fp);
//tms_debugf("found vertices chunk, num items: %d", num_items);
tms_assertf(num_vertices == 0, "multiple meshes per model not currently supported");
@ -93,14 +91,12 @@ load_3ds_model(struct tms_model *model,
for (int x=0; x<num_items; x++) {
SDL_RWread(fp, &vertex_buf[x].pos, 4, 3);
//fread(&vertex_buf[x].pos, 4, 3, fp);
vertex_buf[x].nor = (tvec3){0,0,0};
}
break;
case 0x4120: /* faces list */
SDL_RWread(fp, &num_items, 2, 1);
//fread(&num_items, 2, 1, fp);
// tms_debugf("found faces chunk, num items: %d", num_items);
tms_assertf(num_indices == 0, "face list specified more than once, not supported");
num_indices = num_items * 3;
@ -112,7 +108,6 @@ load_3ds_model(struct tms_model *model,
for (int x=0; x<num_items; x++) {
uint16_t _i[4];
SDL_RWread(fp, &_i, sizeof(uint16_t)*4, 1);
//fread(&_i, sizeof(uint16_t) * 4, 1, fp);
/* calculate this face's normal and update the vertices */
tvec3 a = vertex_buf[_i[0]].pos;
@ -135,19 +130,18 @@ load_3ds_model(struct tms_model *model,
case 0x4140: /* texture coordinates */
SDL_RWread(fp, &num_items, 2, 1);
//fread(&num_items, 2, 1, fp);
// tms_debugf("found uv mapping chunk, num items: %d", num_items);
tms_assertf(num_vertices != 0, "oops! texture coordinates specified before vertices list, unsupported at this time");
//tms_assertf(num_items*sizeof(struct vertex) == vertices->size, "number texture coordinates does not match number of vertices");
for (int x=0; x<num_items; x++)
SDL_RWread(fp, &vertex_buf[x].uv, 4, 2);
//fread(&vertex_buf[x].uv, 4, 2, fp);
break;
default:
SDL_RWseek(fp, chunk_len-6, SEEK_CUR);
//fseek(fp, chunk_len-6, SEEK_CUR);
break;
}
}