Corrected triangulation bug in off file.
This commit is contained in:
parent
c72396e6f7
commit
45b736926a
|
|
@ -404,11 +404,12 @@ namespace vcg
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The face must be triangulate
|
// The face must be triangulated
|
||||||
unsigned int trigs = vert_per_face-3; // number of extra faces to add
|
unsigned int trigs = vert_per_face-3; // number of extra faces to add
|
||||||
nFaces += trigs;
|
nFaces += trigs;
|
||||||
Allocator<MESH_TYPE>::AddFaces(mesh, trigs);
|
Allocator<MESH_TYPE>::AddFaces(mesh, trigs);
|
||||||
std::vector<int> vertIndices(vert_per_face);
|
std::vector<int> vertIndices(vert_per_face);
|
||||||
|
std::vector<vcg::Point3f > polygonVect(vert_per_face); // vec of polygon loops used for the triangulation of polygonal face
|
||||||
for (int j=0; j < vert_per_face; j++)
|
for (int j=0; j < vert_per_face; j++)
|
||||||
{
|
{
|
||||||
if (k == tokens.size()) // if EOL // Go to next line when needed
|
if (k == tokens.size()) // if EOL // Go to next line when needed
|
||||||
|
|
@ -418,6 +419,7 @@ namespace vcg
|
||||||
k = 0;
|
k = 0;
|
||||||
}
|
}
|
||||||
vertIndices[j] = atoi(tokens[k].c_str());
|
vertIndices[j] = atoi(tokens[k].c_str());
|
||||||
|
polygonVect[j] = mesh.vert[ vertIndices[j] ].P();
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
if(vert_per_face==4)
|
if(vert_per_face==4)
|
||||||
|
|
@ -428,9 +430,8 @@ namespace vcg
|
||||||
BitQuad<MESH_TYPE>::QuadTriangulate(q);
|
BitQuad<MESH_TYPE>::QuadTriangulate(q);
|
||||||
for(int qqi=0;qqi<4;++qqi)
|
for(int qqi=0;qqi<4;++qqi)
|
||||||
vertIndices[qqi] = q[qqi]- & mesh.vert[0];
|
vertIndices[qqi] = q[qqi]- & mesh.vert[0];
|
||||||
}
|
// build a two face fan
|
||||||
// standard fan triangulation (we hope the polygon is convex...)
|
for (int j=0; j<2; j++)
|
||||||
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(0) = &(mesh.vert[ vertIndices[0 ] ]);
|
||||||
mesh.face[f+j].V(1) = &(mesh.vert[ vertIndices[1+j] ]);
|
mesh.face[f+j].V(1) = &(mesh.vert[ vertIndices[1+j] ]);
|
||||||
|
|
@ -442,6 +443,27 @@ namespace vcg
|
||||||
loadmask |= Mask::IOM_BITPOLYGONAL;
|
loadmask |= Mask::IOM_BITPOLYGONAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else // standard fan triangulation (we hope the polygon is convex...)
|
||||||
|
{
|
||||||
|
std::vector<int> indexTriangulatedVect;
|
||||||
|
// TessellatePlanarPolygon3(polygonVect,indexTriangulatedVect);
|
||||||
|
std::vector< std::vector<Point3f> > loopVect;
|
||||||
|
loopVect.push_back(polygonVect);
|
||||||
|
#ifdef __gl_h_
|
||||||
|
//qDebug("OK: using opengl tessellation for a polygon of %i vertices",vertexesPerFace);
|
||||||
|
vcg::glu_tesselator::tesselate<vcg::Point3f>(loopVect, indexTriangulatedVect);
|
||||||
|
#else
|
||||||
|
//qDebug("Warning: using fan tessellation for a polygon of %i vertices",vertexesPerFace);
|
||||||
|
InternalFanTessellator(loopVect, indexTriangulatedVect);
|
||||||
|
#endif
|
||||||
|
for (int j=0; j<indexTriangulatedVect.size(); j+=3)
|
||||||
|
{
|
||||||
|
mesh.face[f+j/3].V(0) = &(mesh.vert[ vertIndices[ indexTriangulatedVect[j+0] ] ]);
|
||||||
|
mesh.face[f+j/3].V(1) = &(mesh.vert[ vertIndices[ indexTriangulatedVect[j+1] ] ]);
|
||||||
|
mesh.face[f+j/3].V(2) = &(mesh.vert[ vertIndices[ indexTriangulatedVect[j+2] ] ]);
|
||||||
|
}
|
||||||
|
}
|
||||||
f+=trigs;
|
f+=trigs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -540,7 +562,7 @@ namespace vcg
|
||||||
std::string line;
|
std::string line;
|
||||||
do
|
do
|
||||||
std::getline(stream, line, '\n');
|
std::getline(stream, line, '\n');
|
||||||
while (line[0] == '#' || line.length()==0);
|
while (line[0] == '#' || line.length()==0 || line[0]=='\r');
|
||||||
|
|
||||||
size_t from = 0;
|
size_t from = 0;
|
||||||
size_t to = 0;
|
size_t to = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue