From 391470c093f0a7b50ee5bd8b21d3b6a6326f446f Mon Sep 17 00:00:00 2001 From: cignoni Date: Mon, 18 Sep 2006 12:14:38 +0000 Subject: [PATCH] Removed bug in the creation of the material filename --- wrap/io_trimesh/export_obj.h | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/wrap/io_trimesh/export_obj.h b/wrap/io_trimesh/export_obj.h index 3fadba36..225918d9 100644 --- a/wrap/io_trimesh/export_obj.h +++ b/wrap/io_trimesh/export_obj.h @@ -25,6 +25,9 @@ History $Log: not supported by cvs2svn $ + Revision 1.3 2006/03/07 13:19:29 cignoni + First Release with OBJ import support + Revision 1.2 2006/02/28 14:38:09 corsini remove qt include @@ -167,19 +170,20 @@ namespace io { std::vector materials; std::string fn(filename); - int i=fn.size()-1; - while(fn[--i]!='/'); + int LastSlash=fn.size()-1; + while(LastSlash>=0 && fn[LastSlash]!='/') + --LastSlash; FILE *fp; fp = fopen(filename,"w"); if(fp == NULL)return E_CANTOPENFILE; fprintf(fp,"####\n#\n# OBJ File Generated by Meshlab\n#\n####\n"); - fprintf(fp,"# Object %s\n#\n# Vertices: %d\n# Faces: %d\n#\n####\n",fn.substr(i+1).c_str(),m.vert.size(),m.face.size()); + fprintf(fp,"# Object %s\n#\n# Vertices: %d\n# Faces: %d\n#\n####\n",fn.substr(LastSlash+1).c_str(),m.vert.size(),m.face.size()); //library materials if(mask & vcg::tri::io::Mask::IOM_FACECOLOR) - fprintf(fp,"mtllib ./%s.mtl\n\n",fn.substr(i+1).c_str()); + fprintf(fp,"mtllib ./%s.mtl\n\n",fn.substr(LastSlash+1).c_str()); //vertexs + normal VertexIterator vi; @@ -201,10 +205,9 @@ namespace io { //saves vertex fprintf(fp,"v %f %f %f\n",(*vi).P()[0],(*vi).P()[1],(*vi).P()[2]); - if (cb !=NULL) - (*cb)((100*++current)/max, "writing vertices "); - else - { fclose(fp); return E_ABORTED;} + if (cb !=NULL) { + if(*cb)((100*++current)/max, "writing vertices "); + else { fclose(fp); return E_ABORTED;} } } fprintf(fp,"# %d vertices, %d vertices normals\n\n",m.vert.size(),NormalVertex.size()); @@ -272,11 +275,11 @@ namespace io { fprintf(fp," "); else fprintf(fp,"\n"); - } - if (cb !=NULL) - (*cb)((100*++current)/max, "writing faces "); - else - { fclose(fp); return E_ABORTED;} + } + if (cb !=NULL) { + if(*cb)((100*++current)/max, "writing vertices "); + else { fclose(fp); return E_ABORTED;} } + }//for fprintf(fp,"# %d faces, %d coords texture\n\n",m.face.size(),CoordIndexTexture.size());