# HG changeset patch # User John Tsiombikas # Date 1380507449 -10800 # Node ID d24f63e8031e54e20b099d45d26d27b1685857f4 # Parent 4058337fbb927fe1b3a741ad3b400b6fba515cf3 foo diff -r 4058337fbb92 -r d24f63e8031e src/goat3d.cc --- a/src/goat3d.cc Mon Sep 30 04:26:21 2013 +0300 +++ b/src/goat3d.cc Mon Sep 30 05:17:29 2013 +0300 @@ -15,6 +15,7 @@ struct goat3d { Scene *scn; unsigned int flags; + char *search_path; }; struct goat3d_material : public Material {}; @@ -36,6 +37,7 @@ { goat3d *goat = new goat3d; goat->flags = 0; + goat->search_path = 0; goat->scn = new Scene; goat3d_setopt(goat, GOAT3D_OPT_SAVEXML, 1); @@ -44,6 +46,7 @@ void goat3d_free(struct goat3d *g) { + delete g->search_path; delete g->scn; delete g; } @@ -70,6 +73,24 @@ return -1; } + /* if the filename contained any directory components, keep the prefix + * to use it as a search path for external mesh file loading + */ + g->search_path = new char[strlen(fname) + 1]; + strcpy(g->search_path, fname); + + char *slash = strrchr(g->search_path, '/'); + if(slash) { + *slash = 0; + } else { + if((slash = strrchr(g->search_path, '\\'))) { + *slash = 0; + } else { + delete [] g->search_path; + g->search_path = 0; + } + } + int res = goat3d_load_file(g, fp); fclose(fp); return res;