Commit 9b1ff7eb authored by Romain Pacanowski's avatar Romain Pacanowski

handling the case were no normals are provided in ply file. fixed some warnings as well

parent e8f98f4e
......@@ -76,8 +76,9 @@ inline void loadMeshFromPLY(std::string const &ply_filename, std::shared_ptr< mr
catch (const std::exception &e)
{
// FIX ME ! Allow to construct a mesh even without normals... recompute them
std::cerr << "Caught tinyply exception: " << e.what() << std::endl;
throw std::runtime_error( std::string("Caught tinyply exception NO NORMALS")+e.what() );
std::cout << "No normals per vertex " << std::endl;
// throw std::runtime_error( std::string("Caught tinyply exception NO NORMALS")+e.what() );
tiny_normals = nullptr;
}
try
......@@ -105,8 +106,7 @@ inline void loadMeshFromPLY(std::string const &ply_filename, std::shared_ptr< mr
if (tiny_vertices)
std::cout << "\tRead vertices:" << tiny_vertices->count;
if (tiny_normals)
std::cout << "\tRead normals:" << tiny_normals->count;
if (tiny_texcoords)
std::cout << "\tRead texcoords:" << tiny_texcoords->count;
if (tiny_faces)
......@@ -114,21 +114,17 @@ inline void loadMeshFromPLY(std::string const &ply_filename, std::shared_ptr< mr
const size_t numVerticesBytes = tiny_vertices->buffer.size_bytes();
vertices.resize(tiny_vertices->count);
std::memcpy(vertices.data(), tiny_vertices->buffer.get(), numVerticesBytes);
const size_t numNormalsBytes = tiny_normals->buffer.size_bytes();
normals.resize(tiny_normals->count);
std::memcpy(normals.data(), tiny_normals->buffer.get(), numNormalsBytes);
std::memcpy( (void *) vertices.data(), (const void *) tiny_vertices->buffer.get(), (size_t) numVerticesBytes);
if (tiny_texcoords)
{
const size_t numUVsBytes = tiny_texcoords->buffer.size_bytes();
uvs.resize(tiny_texcoords->count);
std::memcpy(uvs.data(), tiny_texcoords->buffer.get(), numUVsBytes);
std::memcpy((void *) uvs.data(), (const void *) tiny_texcoords->buffer.get(), (size_t) numUVsBytes);
}
else
{
uvs.resize(normals.size(), mrf::math::Vec3f());
uvs.resize(vertices.size(), mrf::math::Vec3f());
}
if (tiny_faces->t != tinyply::Type::UINT32 && tiny_faces->t != tinyply::Type::INT32)
......@@ -163,7 +159,21 @@ inline void loadMeshFromPLY(std::string const &ply_filename, std::shared_ptr< mr
enforced_materials.resize(index_faces.size() / 3);
std::fill(enforced_materials.begin(), enforced_materials.end(), current_material_index);
a_mesh = std::make_shared< mrf::geom::_Mesh<VEC3_TYPE> >( mrf::geom::_Mesh<VEC3_TYPE>(vertices, normals, uvs, index_faces, enforced_materials));
if (tiny_normals)
{
std::cout << "\tRead normals:" << tiny_normals->count;
const size_t numNormalsBytes = tiny_normals->buffer.size_bytes();
normals.resize(tiny_normals->count);
std::memcpy( (void *) normals.data(), (const void *) tiny_normals->buffer.get(), (size_t) numNormalsBytes);
a_mesh = std::make_shared< mrf::geom::_Mesh<VEC3_TYPE> >( mrf::geom::_Mesh<VEC3_TYPE>(vertices, normals, uvs, index_faces, enforced_materials));
}
else // No normals provided
{
a_mesh = std::make_shared< mrf::geom::_Mesh<VEC3_TYPE> >( mrf::geom::_Mesh<VEC3_TYPE>(vertices, index_faces, enforced_materials));
}
}
catch (const std::exception &e)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment