Commit 34cc0a48 authored by Romain Pacanowski's avatar Romain Pacanowski

WORkin progress to use MRF Mesh and ply loader

parent 5042655e
......@@ -2,21 +2,29 @@
#include "camera.h"
#include "SOIL2.h"
#include "mrf/io/ply_loader.hpp"
using namespace Eigen;
Viewer::Viewer()
: _winWidth(0), _winHeight(0), _theta(0), _rotate(true)
{
if (!_mesh.load(DATA_DIR "/models/earth.obj"))
std::exit(1);
// if (!_mesh.load(DATA_DIR "/models/earth.obj"))
// std::exit(1);
}
Viewer::Viewer(std::string const &full_path_to_mesh)
: _winWidth(0), _winHeight(0), _theta(0), _rotate(true)
{
std::string ext = full_path_to_mesh.substr(full_path_to_mesh.size() - 3, 3);
if (ext != "ply")
{
throw std::runtime_error(" OTHER THAN PLY FILE IS NOT SUPPORTED");
}
mrf::io::loadMeshFromPLY( full_path_to_mesh, _mesh );
if (!_mesh.load( full_path_to_mesh.c_str() ) )
std::exit(1);
}
Viewer::~Viewer()
......@@ -34,7 +42,7 @@ void Viewer::init(int w, int h){
loadShaders();
_mesh.initVBA();
//_mesh.initVBA();
reshape(w,h);
_cam.setPerspective(M_PI/3,0.1f,20000.0f);
......@@ -182,3 +190,27 @@ void Viewer::keyPressed(int key, int action, int /*mods*/)
void Viewer::charPressed(int /*key*/)
{
}
// Private
void Viewer::initVBA()
{
// create the BufferObjects and copy the related data into them.
// create a VBO identified by a unique index:
glGenBuffers(1, & mVertexBufferId);
// activate the VBO:
glBindBuffer(GL_ARRAY_BUFFER, mVertexBufferId);
// copy the data from host's RAM to GPU's video memory:
glBufferData(GL_ARRAY_BUFFER, sizeof(mrf::math::Vec3f) * mVertices.size(), mVertices[0].position.data(), GL_STATIC_DRAW);
glGenBuffers(1, &mIndexBufferId);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBufferId);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Vector3i) * mFaces.size(), mFaces[0].data(), GL_STATIC_DRAW);
glGenVertexArrays(1, &mVertexArrayId);
mIsInitialized = true;
}
\ No newline at end of file
......@@ -5,10 +5,13 @@
#include "shader.h"
#include "camera.h"
#include "trackball.h"
#include "mesh.h"
//#include "mesh.h"
#include "mrf/geometry/mesh.hpp"
#include <iostream>
#include "mrf/io/ply_loader.hpp"
class Viewer{
public:
//! Constructor
......@@ -36,7 +39,14 @@ private:
Camera _cam;
Shader _shader;
Mesh _mesh;
// Mesh _mesh;
//MRF Mesh
std::shared_ptr<mrf::geom::Mesh> _mesh;
GLuint mVertexBufferId;
GLuint mIndexBufferId;
float _theta;
bool _rotate;
......@@ -51,6 +61,12 @@ private:
TrackMode _trackingMode = TM_NO_TRACK;
Trackball _trackball;
Eigen::Vector2i _lastMousePos;
private:
void initVBA();
};
#endif
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