diff --git a/wrap/io_trimesh/import_off.h b/wrap/io_trimesh/import_off.h index 143dda63..05eb4f86 100644 --- a/wrap/io_trimesh/import_off.h +++ b/wrap/io_trimesh/import_off.h @@ -458,12 +458,10 @@ namespace vcg { for (int j = 0; j < 3; j++) { - // Go to next line when needed - if (k == tokens.size()) // if EOL + if (k == tokens.size()) // if EOL // Go to next line when needed { TokenizeNextLine(stream, tokens); - if (tokens.size() == 0) // if EOF - return InvalidFile; + if (tokens.size() == 0) return InvalidFile; // if EOF k = 0; } @@ -477,38 +475,58 @@ namespace vcg unsigned int trigs = vert_per_face-3; // number of extra faces to add nFaces += trigs; Allocator::AddFaces(mesh, trigs); - int *vertIndices = new int[vert_per_face]; - + std::vector vertIndices(vert_per_face); for (int j=0; j < vert_per_face; j++) { - // Go to next line when needed - if (k == tokens.size()) // if EOL + if (k == tokens.size()) // if EOL // Go to next line when needed { TokenizeNextLine(stream, tokens); - if (tokens.size() == 0) // if EOF - return InvalidFile; - k = 0; + if (tokens.size() == 0) return InvalidFile; // if EOF + k = 0; } - vertIndices[j] = atoi(tokens[k].c_str()); k++; } + if(vert_per_face==4) + { // To well triangulate the quad: + // if the quad is flat and convex we use the shortest diag , + // else we should use the diag that makes the smallest + + const CoordType &P0=mesh.vert[vertIndices[0]].cP(); + const CoordType &P1=mesh.vert[vertIndices[1]].cP(); + const CoordType &P2=mesh.vert[vertIndices[2]].cP(); + const CoordType &P3=mesh.vert[vertIndices[3]].cP(); - for (int j=0; j<=vert_per_face-3; j++) - { - mesh.face[f+j].V(0) = &(mesh.vert[ vertIndices[0 ] ]); - mesh.face[f+j].V(1) = &(mesh.vert[ vertIndices[1+j] ]); - mesh.face[f+j].V(2) = &(mesh.vert[ vertIndices[2+j] ]); - if (tri::HasPerFaceFlags(mesh)) { - // tag internal polygnal edges as "faux" - if (j>0) mesh.face[f+j].SetF(0); - if (j M_PI/2.0) && (Angle0Rad 0) mesh.face[f+j].SetF(0); + if (j