goat3d
changeset 32:d24f63e8031e
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 30 Sep 2013 05:17:29 +0300 |
parents | 4058337fbb92 |
children | 8471225a460c |
files | src/goat3d.cc |
diffstat | 1 files changed, 21 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- a/src/goat3d.cc Mon Sep 30 04:26:21 2013 +0300 1.2 +++ b/src/goat3d.cc Mon Sep 30 05:17:29 2013 +0300 1.3 @@ -15,6 +15,7 @@ 1.4 struct goat3d { 1.5 Scene *scn; 1.6 unsigned int flags; 1.7 + char *search_path; 1.8 }; 1.9 1.10 struct goat3d_material : public Material {}; 1.11 @@ -36,6 +37,7 @@ 1.12 { 1.13 goat3d *goat = new goat3d; 1.14 goat->flags = 0; 1.15 + goat->search_path = 0; 1.16 goat->scn = new Scene; 1.17 1.18 goat3d_setopt(goat, GOAT3D_OPT_SAVEXML, 1); 1.19 @@ -44,6 +46,7 @@ 1.20 1.21 void goat3d_free(struct goat3d *g) 1.22 { 1.23 + delete g->search_path; 1.24 delete g->scn; 1.25 delete g; 1.26 } 1.27 @@ -70,6 +73,24 @@ 1.28 return -1; 1.29 } 1.30 1.31 + /* if the filename contained any directory components, keep the prefix 1.32 + * to use it as a search path for external mesh file loading 1.33 + */ 1.34 + g->search_path = new char[strlen(fname) + 1]; 1.35 + strcpy(g->search_path, fname); 1.36 + 1.37 + char *slash = strrchr(g->search_path, '/'); 1.38 + if(slash) { 1.39 + *slash = 0; 1.40 + } else { 1.41 + if((slash = strrchr(g->search_path, '\\'))) { 1.42 + *slash = 0; 1.43 + } else { 1.44 + delete [] g->search_path; 1.45 + g->search_path = 0; 1.46 + } 1.47 + } 1.48 + 1.49 int res = goat3d_load_file(g, fp); 1.50 fclose(fp); 1.51 return res;