Commit ab3ab9ab authored by Romain Pacanowski's avatar Romain Pacanowski

Working version of the ply loader

parent 869271ce
......@@ -17,6 +17,16 @@ Viewer::Viewer()
Viewer::Viewer(std::string const &full_path_to_mesh)
: _winWidth(0), _winHeight(0), _theta(0), _rotate(false), _meshIsInitialized(false)
{
//CPU Data of the PLY File
std::vector<mrf::math::Vec3f> _vertices;
std::vector<mrf::math::Vec3f> _normals;
std::vector<mrf::math::Vec3f> _tangents;
std::vector<mrf::math::Vec3f> _uvs;
std::vector<mrf::math::Vec3f> _color_per_vertex;
std::string ext = full_path_to_mesh.substr(full_path_to_mesh.size() - 3, 3);
if (ext != "ply")
......@@ -29,15 +39,15 @@ Viewer::Viewer(std::string const &full_path_to_mesh)
_vboCPU.clear();
try
{
mrf::io::loadPLY<mrf::math::Vec3d>(full_path_to_mesh, _vertices, _normals, _uvs, _color_per_vertex, _index_faces);
mrf::io::loadPLY(full_path_to_mesh, _vertices, _normals, _uvs, _color_per_vertex, _index_faces);
if( _normals.size() != _vertices.size() )
{
mrf::geom::_Mesh<mrf::math::Vec3d>::computeNormals(_vertices, _index_faces, _normals );
mrf::geom::_Mesh<mrf::math::Vec3f>::computeNormals(_vertices, _index_faces, _normals );
}
mrf::geom::_Mesh<mrf::math::Vec3d>::computeTangents(_vertices, _normals, _tangents);
mrf::geom::_Mesh<mrf::math::Vec3f>::computeTangents(_vertices, _normals, _tangents);
std::cout << _index_faces[0] << " " << _index_faces[1] << " " << _index_faces[2] << std::endl;
......@@ -57,7 +67,7 @@ Viewer::Viewer(std::string const &full_path_to_mesh)
}
if( _color_per_vertex.size() == _vertices.size() )
if (_color_per_vertex.size() == _vertices.size() )
{
_vboCPU.push_back(_color_per_vertex[i] );
}
......@@ -90,6 +100,13 @@ Viewer::Viewer(std::string const &full_path_to_mesh)
std::cerr << " Problem while loading PLY file. Aborting" << std::endl;
}
//Clean the data that do not go on GPU
_vertices.clear();
_normals.clear();
_uvs.clear();
_tangents.clear();
//_index_faces.clear();
_color_per_vertex.clear();
}
Viewer::~Viewer()
......@@ -290,7 +307,7 @@ void Viewer::initVBA()
_meshIsInitialized = true;
std::cout << " INITI VBA COMPLETED" << std::endl;
std::cout << " INITI VBA COMPLETED... Proceeding to OpenGL Rendering" << std::endl;
checkError();
}
......@@ -327,44 +344,51 @@ Viewer::draw(Shader const & shd)
{
checkError();
glVertexAttribPointer(normal_loc, 3, GL_FLOAT, GL_FALSE, sizeof(mrf::math::Vec3f), (void*)sizeof(mrf::math::Vec3f));
glVertexAttribPointer(normal_loc, 3, GL_FLOAT, GL_FALSE, _nb_bytes_between_two_vertex, (void *)sizeof(mrf::math::Vec3f));
glEnableVertexAttribArray(normal_loc);
}
int tangent_loc = shd.getAttribLocation("vtx_tangent");
if (tangent_loc >= 0)
{
glVertexAttribPointer(tangent_loc, 3, GL_FLOAT, GL_FALSE, sizeof(mrf::math::Vec3f), (void *)(2*sizeof(mrf::math::Vec3f)));
glVertexAttribPointer(tangent_loc, 3, GL_FLOAT, GL_FALSE, _nb_bytes_between_two_vertex, (void *)(2 * sizeof(mrf::math::Vec3f)));
glEnableVertexAttribArray(tangent_loc);
}
int color_loc = -1;
if (_color_per_vertex.size() == _vertices.size())
{
// if (_color_per_vertex.size() == _vertices.size())
// {
color_loc = shd.getAttribLocation("vtx_color");
if (color_loc >= 0)
{
glVertexAttribPointer(color_loc, 3, GL_FLOAT, GL_FALSE, sizeof(mrf::math::Vec3f), (void *)(3 * sizeof(mrf::math::Vec3f)));
glVertexAttribPointer(color_loc, 3, GL_FLOAT, GL_FALSE, _nb_bytes_between_two_vertex, (void *)(3 * sizeof(mrf::math::Vec3f)));
glEnableVertexAttribArray(color_loc);
}
}
//}
int texcoord_loc = -1;
if (_uvs.size() == _vertices.size())
{
// if (_uvs.size() == _vertices.size())
// {
texcoord_loc = shd.getAttribLocation("vtx_texcoord");
if (texcoord_loc >= 0)
{
glVertexAttribPointer(texcoord_loc, 2, GL_FLOAT, GL_FALSE, sizeof(mrf::math::Vec3f), (void *)(4 * sizeof(mrf::math::Vec3f)));
glVertexAttribPointer(texcoord_loc, 2, GL_FLOAT, GL_FALSE, _nb_bytes_between_two_vertex, (void *)(4 * sizeof(mrf::math::Vec3f)));
glEnableVertexAttribArray(texcoord_loc);
}
}
// }
// send the geometry
// glDrawElements(GL_TRIANGLES, 3*mFaces.size(), GL_UNSIGNED_INT, 0);
// if( _index_faces.size() > MAX_FACES_PER_DRAW_CALL )
// {
// for (unsigned int i = 0; i < NB_DRAW_CALL_REQUIRED; i++)
// {
// }
// }
glDrawElements(GL_TRIANGLES, _index_faces.size(), GL_UNSIGNED_INT, 0);
// at this point the mesh has been drawn and raserized into the framebuffer!
// at this point the mesh has been drawn and raserized into the framebuffer!
glDisableVertexAttribArray(vertex_loc);
......@@ -372,18 +396,18 @@ Viewer::draw(Shader const & shd)
if (tangent_loc >= 0) glDisableVertexAttribArray(tangent_loc);
if (_color_per_vertex.size() == _vertices.size())
{
// if (_color_per_vertex.size() == _vertices.size())
// {
if (color_loc >= 0)
glDisableVertexAttribArray(color_loc);
}
//}
if (_uvs.size() == _vertices.size())
{
// if (_uvs.size() == _vertices.size())
// {
if (texcoord_loc >= 0)
glDisableVertexAttribArray(texcoord_loc);
}
//}
checkError();
}
\ No newline at end of file
......@@ -47,18 +47,11 @@ private:
//MRF Mesh
//std::shared_ptr<mrf::geom::Mesh> _mesh;
//CPU Data of the PLY File
std::vector<mrf::math::Vec3d> _vertices;
std::vector<mrf::math::Vec3d> _normals;
std::vector<mrf::math::Vec3d> _tangents;
std::vector<mrf::math::Vec3d> _uvs;
std::vector<mrf::math::Vec3d> _color_per_vertex;
std::vector<unsigned int> _index_faces;
std::vector<unsigned int> _index_faces;
unsigned int _nb_bytes_between_two_vertex;
///CPU version of the data that goes to GPU
std::vector< mrf::math::Vec3f > _vboCPU;
......
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