diff options
Diffstat (limited to 'src/model.c')
-rw-r--r-- | src/model.c | 168 |
1 files changed, 0 insertions, 168 deletions
diff --git a/src/model.c b/src/model.c index b0275fe..2f768f5 100644 --- a/src/model.c +++ b/src/model.c @@ -149,165 +149,6 @@ static void model_calculate_normals(GLfloat *vertices, GLfloat *normals, int fir } -static int model_load_obj(ModelContext *ctx, const char *name, RenderContext *render) { - - FILE *fh; - char tmp[64]; - Model *model; - int num_vertices; - GLfloat *vertices; - GLfloat *normals; - GLfloat *texcoords; - GLfloat vtmp[3*MAX_VERTICES]; - GLfloat vntmp[3*MAX_VERTICES]; - int n_vtmp, n_vntmp; - char *texture; - - snprintf(tmp, 63, "%s/models/%s.obj", DATADIR, name); - fh = fopen(tmp, "r"); - if ( fh == NULL ) { - return -1; - } - - /* Zip through and find all the vertices */ - n_vtmp = 0; - n_vntmp = 0; - while ( !feof(fh) ) { - - char line[1024]; - GLfloat x, y, z; - GLfloat texx, texy; - size_t s; - - texx = 0.0; texy = 0.0; /* Default texture coordinates */ - - fgets(line, 1023, fh); - s = 0; - for ( ; s<strlen(line); s++ ) { - if ( line[s] != ' ' ) break; - } - - if ( line[s] == '#' ) { - continue; - } - - if ( sscanf(line+s, "v %f %f %f\n", &x, &y, &z) == 3 ) { - vtmp[3*n_vtmp+0] = x; - vtmp[3*n_vtmp+1] = y; - vtmp[3*n_vtmp+2] = z; - n_vtmp++; - continue; - } - - if ( sscanf(line+s, "vn %f %f %f\n", &x, &y, &z) == 3 ) { - vntmp[3*n_vntmp+0] = x; - vntmp[3*n_vntmp+1] = y; - vntmp[3*n_vntmp+2] = z; - n_vntmp++; - continue; - } - - } - - /* Go through again and look for faces */ - model = model_new(name); - vertices = malloc(MAX_VERTICES*3*sizeof(GLfloat)); - normals = malloc(MAX_VERTICES*3*sizeof(GLfloat)); - texcoords = malloc(MAX_VERTICES*2*sizeof(GLfloat)); - texture = NULL; - num_vertices = 0; - rewind(fh); - while ( !feof(fh) ) { - - char line[1024]; - char **bits; - int n, i; - - fgets(line, 1023, fh); - n = assplode(line, " \t\r\n", &bits, ASSPLODE_NONE); - - /* Read in a face */ - if ( strcmp(bits[0], "f") == 0 ) { - - for ( i=1; i<n; i++ ) { - - char **sp; - int np, vnum, nnum, j, nslash; - - nslash = 0; - for ( j=0; j<strlen(bits[i]); j++ ) { - if ( bits[i][j] == '/' ) nslash++; - } - if ( nslash == 2 ) { - - np = assplode(bits[i], "/", &sp, ASSPLODE_DUPS); - if ( np != 3 ) { - continue; - } - vnum = atoi(sp[0])-1; - nnum = atoi(sp[2])-1; - if ( vnum >= n_vtmp ) { - fprintf(stderr, "Vertex index is too high (%i/%i)\n", vnum, n_vtmp); - continue; - } - if ( nnum >= n_vntmp ) { - fprintf(stderr, "Normal index is too high (%i/%i)\n", nnum, n_vntmp); - continue; - } - if ( num_vertices < MAX_VERTICES ) { - vertices[3*num_vertices+0] = vtmp[3*vnum+0]; - vertices[3*num_vertices+1] = vtmp[3*vnum+1]; - vertices[3*num_vertices+2] = vtmp[3*vnum+2]; - normals[3*num_vertices+0] = vntmp[3*nnum+0]; - normals[3*num_vertices+1] = vntmp[3*nnum+1]; - normals[3*num_vertices+2] = vntmp[3*nnum+2]; - texcoords[2*num_vertices+0] = 0.0; - texcoords[2*num_vertices+1] = 0.0; - num_vertices++; - } else { - fprintf(stderr, "Too many vertices\n"); - } - free(sp[0]); - free(sp[1]); - free(sp[2]); - free(sp); - - } else if ( nslash == 0 ) { - - vnum = atoi(bits[i]); - if ( num_vertices < MAX_VERTICES ) { - vertices[3*num_vertices+0] = vtmp[3*vnum+0]; - vertices[3*num_vertices+1] = vtmp[3*vnum+1]; - vertices[3*num_vertices+2] = vtmp[3*vnum+2]; - normals[3*num_vertices+0] = 1.0; - normals[3*num_vertices+1] = 0.0; - normals[3*num_vertices+2] = 0.0; - num_vertices++; - } else { - fprintf(stderr, "Too many vertices\n"); - } - - } - - } - - model_add_primitive(model, GL_POLYGON, vertices, normals, texcoords, num_vertices, - ATTRIB_NONE, 1.0, 1.0, 1.0, texture); - num_vertices = 0; - - } - - for ( i=0; i<n; i++ ) free(bits[i]); - free(bits); - - } - - fclose(fh); - - return model_add(ctx, model); - -} - static int model_load(ModelContext *ctx, const char *name, RenderContext *render) { FILE *fh; @@ -458,15 +299,6 @@ ModelInstance *model_instance_new(ModelContext *ctx, const char *name, RenderCon /* Couldn't find model, so try to load it */ model_load(ctx, name, render); instance->model = model_lookup(ctx, name); - if ( instance->model == NULL ) { - model_load_obj(ctx, name, render); - instance->model = model_lookup(ctx, name); - if ( instance->model == NULL ) { - free(instance); - printf("Couldn't find model %s\n", name); - return NULL; - } - } } instance->vx = 0.0; |