/* objloader.c * Created by Jon Mayo on 7/26/06. * This software is PUBLIC DOMAIN as of July 2006. No copyright is claimed. * - Jon Mayo */ /* a small library to load a subset of the Wavefront OBJ model format */ #include #include #include #include #include #include #include #include "objloader.h" #include "model.h" #include "logger.h" #define MAX_LINE_LEN 1024 #define MAX_TESS 6 /* biggest polygon we will tessellate */ static int parse_face_data(const char *filename, unsigned line, struct model *m, struct object **curr_grp, char *buf) { char *tmp, *idx=buf; unsigned i, j; int data[3][MAX_TESS]; if(!*curr_grp) { LOG_DEBUG("%s:%u:face data before group name\n", filename, line); *curr_grp=model_object_create(m, "ungrouped", 1); if(!*curr_grp) { LOG_DEBUG("%s:%u:face data allocation error\n", filename, line); return 0; } } /* for(i=0;inr_object;i++) { int nr_vertex; float (*vertex)[3]; o=m->object+i; if(o->global_vertex) { nr_vertex=m->nr_vertex; vertex=m->vertex; } else { /* TODO: handle per object vertex tables */ goto error; /* nr_vertex=o->nr_vertex; vertex=o->vertex; */ } printf("[%s]\n", o->tag?o->tag:"noname"); printf(" faces=%d vertices=%d\n", o->nr_face, nr_vertex); for(j=0;jnr_face;j++) { fprintf(out, "f"); for(k=0;k<3;k++) { fprintf(out, " %u", o->face[j][k]+1); } fprintf(out, "\n"); } } fclose(out); return 1; error: fclose(out); return 0; }