From 4b9473eda97ce62778bfedf03d3c344f9c656a23 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 22 Apr 2002 09:31:54 +0000 Subject: [PATCH] Fixes the .mlt loading from Ben Discoe. --- src/osgPlugins/obj/glm.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/osgPlugins/obj/glm.cpp b/src/osgPlugins/obj/glm.cpp index b0a38d87d..005c3c437 100644 --- a/src/osgPlugins/obj/glm.cpp +++ b/src/osgPlugins/obj/glm.cpp @@ -201,7 +201,7 @@ _glmAddGroup(GLMmodel* model, char* name) group = _glmFindGroup(model, name); if (!group) { group = (GLMgroup*)malloc(sizeof(GLMgroup)); - group->init(); + group->init(); group->name = strdup(name); group->material = 0; group->numtriangles = 0; @@ -246,10 +246,15 @@ _glmDirName(char* path) { char* dir; char* s; + char* s2; dir = strdup(path); s = strrchr(dir, '/'); + s2 = strrchr(dir, '\\'); // also look for backslashes + if (s2 > s) // take whichever is later + s = s2; + if (s) s[1] = '\0'; else @@ -283,7 +288,7 @@ _glmReadMTL(GLMmodel* model, char* name) file = fopen(filename, "r"); if (!file) { fprintf(stderr, "_glmReadMTL() failed: can't open material file \"%s\".\n", - filename); + filename); return; } free(filename); @@ -292,11 +297,11 @@ _glmReadMTL(GLMmodel* model, char* name) nummaterials = 1; while(fscanf(file, "%s", buf) != EOF) { switch(buf[0]) { - case '#': /* comment */ + case '#': /* comment */ /* eat up rest of line */ fgets(buf, sizeof(buf), file); break; - case 'n': /* newmtl */ + case 'n': /* newmtl */ fgets(buf, sizeof(buf), file); nummaterials++; sscanf(buf, "%s %s", buf, buf); @@ -339,11 +344,11 @@ _glmReadMTL(GLMmodel* model, char* name) nummaterials = 0; while(fscanf(file, "%s", buf) != EOF) { switch(buf[0]) { - case '#': /* comment */ + case '#': /* comment */ /* eat up rest of line */ fgets(buf, sizeof(buf), file); break; - case 'n': /* newmtl */ + case 'n': /* newmtl */ fgets(buf, sizeof(buf), file); sscanf(buf, "%s %s", buf, buf); nummaterials++; @@ -403,6 +408,7 @@ _glmReadMTL(GLMmodel* model, char* name) break; } } + fclose(file); } /* _glmWriteMTL: write a wavefront material library file @@ -430,7 +436,7 @@ _glmWriteMTL(GLMmodel* model, char* modelpath, char* mtllibname) file = fopen(filename, "w"); if (!file) { fprintf(stderr, "_glmWriteMTL() failed: can't open file \"%s\".\n", - filename); + filename); return; } free(filename);