diff options
author | taw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5> | 2008-07-27 23:09:13 +0000 |
---|---|---|
committer | taw27 <taw27@84d2e878-0bd5-11dd-ad15-13eda11d74c5> | 2008-07-27 23:09:13 +0000 |
commit | 11dc9e5855e2dff4a69242a98b9da23c85405ffb (patch) | |
tree | 9b10869e16434d6875313941a4da2ebadf663ace /src/model.c | |
parent | 6dec5c9e53a36a24dbabde0dda23af1812442506 (diff) |
Extend model format to include vertex normals
git-svn-id: svn://cook.msm.cam.ac.uk:745/thrust3d/thrust3d@187 84d2e878-0bd5-11dd-ad15-13eda11d74c5
Diffstat (limited to 'src/model.c')
-rw-r--r-- | src/model.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/model.c b/src/model.c index bf5512e..1e43297 100644 --- a/src/model.c +++ b/src/model.c @@ -226,9 +226,12 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render char line[1024]; GLfloat x, y, z; GLfloat r, g, b; + GLfloat nx, ny, nz; + int have_normals; GLfloat texx, texy, forget; texx = 0.0; texy = 0.0; /* Default texture coordinates */ + have_normals = 0; /* Calculate the normals by default */ fgets(line, 1023, fh); @@ -262,20 +265,34 @@ static int model_load(ModelContext *ctx, const char *name, RenderContext *render texx = x; texy = y; } + if ( sscanf(line, "%f %f %f %f %f %f %f %f", &forget, &forget, &forget, &forget, &forget, + &nx, &ny, &nz) == 8 ) { + have_normals = 1; + } + if ( sscanf(line, "%f %f %f", &x, &y, &z) == 3 ) { vertices[3*num_vertices+0] = x; vertices[3*num_vertices+1] = y; vertices[3*num_vertices+2] = z; texcoords[2*num_vertices+0] = texx; texcoords[2*num_vertices+1] = texy; + if ( have_normals ) { + normals[3*num_vertices+0] = nx; + normals[3*num_vertices+1] = ny; + normals[3*num_vertices+2] = nz; + } num_vertices++; if ( (type == PRIMITIVE_QUADS) && ((num_vertices % 4)==0) ) { - model_calculate_normals(vertices, normals, num_vertices-4, num_vertices-1, + if ( !have_normals ) { + model_calculate_normals(vertices, normals, num_vertices-4, num_vertices-1, num_vertices-4, num_vertices-3, num_vertices-2); + } } if ( (type == PRIMITIVE_TRIANGLES) && ((num_vertices % 3)==0) ) { - model_calculate_normals(vertices, normals, num_vertices-3, num_vertices-1, + if ( !have_normals ) { + model_calculate_normals(vertices, normals, num_vertices-3, num_vertices-1, num_vertices-3, num_vertices-2, num_vertices-1); + } } if ( num_vertices > MAX_VERTICES ) { fprintf(stderr, "Too many vertices in primitive\n"); |