From 843c6d172cdd2b01f34d60fd95ae50e935ad23b9 Mon Sep 17 00:00:00 2001 From: cignoni Date: Fri, 15 Feb 2008 09:51:36 +0000 Subject: [PATCH] corrected bug in the management of of multiple solid ascii stl files --- wrap/io_trimesh/import_stl.h | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/wrap/io_trimesh/import_stl.h b/wrap/io_trimesh/import_stl.h index a1c84841..ea903b6a 100644 --- a/wrap/io_trimesh/import_stl.h +++ b/wrap/io_trimesh/import_stl.h @@ -25,6 +25,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.15 2007/05/24 06:56:54 cignoni +Corrected gcc warning + Revision 1.14 2006/06/10 12:49:05 mariolatronico file length is now computed using fseek and ftell @@ -223,19 +226,35 @@ static int OpenBinary( OpenMeshType &m, const char * filename, CallBackPos *cb=0 STLFacet f; int cnt=0; - + int ret; /* Read a single facet from an ASCII .STL file */ while(!feof(fp)) { if((++cnt)%1000) cb( (ftell(fp)*100)/fileLen, "STL Mesh Loading"); - fscanf(fp, "%*s %*s %f %f %f\n", &f.n.X(), &f.n.Y(), &f.n.Z()); - fscanf(fp, "%*s %*s"); - fscanf(fp, "%*s %f %f %f\n", &f.v[0].X(), &f.v[0].Y(), &f.v[0].Z()); - fscanf(fp, "%*s %f %f %f\n", &f.v[1].X(), &f.v[1].Y(), &f.v[1].Z()); - fscanf(fp, "%*s %f %f %f\n", &f.v[2].X(), &f.v[2].Y(), &f.v[2].Z()); - fscanf(fp, "%*s"); // end loop - fscanf(fp, "%*s"); // end facet + ret=fscanf(fp, "%*s %*s %f %f %f\n", &f.n.X(), &f.n.Y(), &f.n.Z()); + if(ret!=3) + { + // we could be in the case of a multiple solid object, where after a endfaced instead of another facet we have to skip two lines: + // endloop + // endfacet + //endsolid <- continue on ret==0 will skip this line + //solid ascii <- and this one. + // facet normal 0.000000e+000 7.700727e-001 -6.379562e-001 + continue; + } + ret=fscanf(fp, "%*s %*s"); + ret=fscanf(fp, "%*s %f %f %f\n", &f.v[0].X(), &f.v[0].Y(), &f.v[0].Z()); + if(ret!=3) + return E_UNESPECTEDEOF; + ret=fscanf(fp, "%*s %f %f %f\n", &f.v[1].X(), &f.v[1].Y(), &f.v[1].Z()); + if(ret!=3) + return E_UNESPECTEDEOF; + ret=fscanf(fp, "%*s %f %f %f\n", &f.v[2].X(), &f.v[2].Y(), &f.v[2].Z()); + if(ret!=3) + return E_UNESPECTEDEOF; + ret=fscanf(fp, "%*s"); // end loop + ret=fscanf(fp, "%*s"); // end facet if(feof(fp)) break; FaceIterator fi=Allocator::AddFaces(m,1); VertexIterator vi=Allocator::AddVertices(m,3);