Handle objs without faces(Thanks to Bruno Dutailly)
git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@476 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
@@ -280,7 +280,7 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
|
|||||||
std::vector<Vec2f> face_texcoords;
|
std::vector<Vec2f> face_texcoords;
|
||||||
std::vector<VertexHandle> vertexHandles;
|
std::vector<VertexHandle> vertexHandles;
|
||||||
|
|
||||||
std::string matname;
|
std::string matname;
|
||||||
|
|
||||||
|
|
||||||
while( _in && !_in.eof() )
|
while( _in && !_in.eof() )
|
||||||
@@ -359,13 +359,13 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
|
|||||||
if ( !stream.fail() )
|
if ( !stream.fail() )
|
||||||
{
|
{
|
||||||
vertexHandles.push_back(_bi.add_vertex(OpenMesh::Vec3f(x,y,z)));
|
vertexHandles.push_back(_bi.add_vertex(OpenMesh::Vec3f(x,y,z)));
|
||||||
stream >> r; stream >> g; stream >> b;
|
stream >> r; stream >> g; stream >> b;
|
||||||
|
|
||||||
if ( !stream.fail() )
|
if ( !stream.fail() )
|
||||||
{
|
{
|
||||||
_opt += Options::VertexColor;
|
_opt += Options::VertexColor;
|
||||||
colors.push_back(OpenMesh::Vec3uc((unsigned char)r,(unsigned char)g,(unsigned char)b));
|
colors.push_back(OpenMesh::Vec3uc((unsigned char)r,(unsigned char)g,(unsigned char)b));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,8 +487,8 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
|
|||||||
}
|
}
|
||||||
// Obj counts from 1 and not zero .. array counts from zero therefore -1
|
// Obj counts from 1 and not zero .. array counts from zero therefore -1
|
||||||
vhandles.push_back(VertexHandle(value-1));
|
vhandles.push_back(VertexHandle(value-1));
|
||||||
if (_opt.vertex_has_color())
|
if (_opt.vertex_has_color())
|
||||||
_bi.set_color(vhandles.back(), colors[value-1]);
|
_bi.set_color(vhandles.back(), colors[value-1]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: // texture coord
|
case 1: // texture coord
|
||||||
@@ -589,6 +589,29 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we do not have any faces,
|
||||||
|
// assume this is a point cloud and read the normals and colors directly
|
||||||
|
if (_bi.n_faces()==0)
|
||||||
|
{
|
||||||
|
int i=0;
|
||||||
|
// add normal per vertex
|
||||||
|
if ( normals.size() == _bi.n_vertices() )
|
||||||
|
for (std::vector<VertexHandle>::iterator it = vertexHandles.begin();
|
||||||
|
it != vertexHandles.end(); ++it, i++) {
|
||||||
|
_bi.set_normal( *it, normals[i] );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// add color per vertex
|
||||||
|
i=0;
|
||||||
|
if ( colors.size() >= _bi.n_vertices() )
|
||||||
|
for (std::vector<VertexHandle>::iterator it = vertexHandles.begin();
|
||||||
|
it != vertexHandles.end(); ++it, i++) {
|
||||||
|
_bi.set_color( *it, colors[i] );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user