Removed bug in the creation of the material filename

This commit is contained in:
Paolo Cignoni 2006-09-18 12:14:38 +00:00
parent 7310eb3f58
commit 391470c093
1 changed files with 16 additions and 13 deletions

View File

@ -25,6 +25,9 @@
History History
$Log: not supported by cvs2svn $ $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 Revision 1.2 2006/02/28 14:38:09 corsini
remove qt include remove qt include
@ -167,19 +170,20 @@ namespace io {
std::vector<Material> materials; std::vector<Material> materials;
std::string fn(filename); std::string fn(filename);
int i=fn.size()-1; int LastSlash=fn.size()-1;
while(fn[--i]!='/'); while(LastSlash>=0 && fn[LastSlash]!='/')
--LastSlash;
FILE *fp; FILE *fp;
fp = fopen(filename,"w"); fp = fopen(filename,"w");
if(fp == NULL)return E_CANTOPENFILE; if(fp == NULL)return E_CANTOPENFILE;
fprintf(fp,"####\n#\n# OBJ File Generated by Meshlab\n#\n####\n"); 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 //library materials
if(mask & vcg::tri::io::Mask::IOM_FACECOLOR) 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 //vertexs + normal
VertexIterator vi; VertexIterator vi;
@ -201,10 +205,9 @@ namespace io {
//saves vertex //saves vertex
fprintf(fp,"v %f %f %f\n",(*vi).P()[0],(*vi).P()[1],(*vi).P()[2]); fprintf(fp,"v %f %f %f\n",(*vi).P()[0],(*vi).P()[1],(*vi).P()[2]);
if (cb !=NULL) if (cb !=NULL) {
(*cb)((100*++current)/max, "writing vertices "); if(*cb)((100*++current)/max, "writing vertices ");
else else { fclose(fp); return E_ABORTED;} }
{ fclose(fp); return E_ABORTED;}
} }
fprintf(fp,"# %d vertices, %d vertices normals\n\n",m.vert.size(),NormalVertex.size()); fprintf(fp,"# %d vertices, %d vertices normals\n\n",m.vert.size(),NormalVertex.size());
@ -272,11 +275,11 @@ namespace io {
fprintf(fp," "); fprintf(fp," ");
else else
fprintf(fp,"\n"); fprintf(fp,"\n");
} }
if (cb !=NULL) if (cb !=NULL) {
(*cb)((100*++current)/max, "writing faces "); if(*cb)((100*++current)/max, "writing vertices ");
else else { fclose(fp); return E_ABORTED;} }
{ fclose(fp); return E_ABORTED;}
}//for }//for
fprintf(fp,"# %d faces, %d coords texture\n\n",m.face.size(),CoordIndexTexture.size()); fprintf(fp,"# %d faces, %d coords texture\n\n",m.face.size(),CoordIndexTexture.size());