Commit b217b3af authored by Sylvain Thery's avatar Sylvain Thery

remove BB of groups in OBJ import

parent a8fb63ca
...@@ -35,7 +35,8 @@ ObjView::ObjView(): ...@@ -35,7 +35,8 @@ ObjView::ObjView():
m_texcoordVBO(NULL), m_texcoordVBO(NULL),
m_shader(NULL), m_shader(NULL),
m_shader2(NULL), m_shader2(NULL),
m_RenderStyle(2) m_RenderStyle(2),
m_currentGroupDrawn(0xffffffff)
{} {}
ObjView::~ObjView() ObjView::~ObjView()
...@@ -69,6 +70,23 @@ void ObjView::cb_keyPress(int k) ...@@ -69,6 +70,23 @@ void ObjView::cb_keyPress(int k)
case 't': case 't':
m_RenderStyle=2; m_RenderStyle=2;
break; break;
case 'o':
m_currentGroupDrawn=0xffffffff;
break;
case 'O':
m_currentGroupDrawn=0;
std::cout << "Group "<< m_obj.objGroupName(m_currentGroupDrawn)<< std::endl;
break;
case '-':
m_currentGroupDrawn--;
std::cout << "Group "<< m_obj.objGroupName(m_currentGroupDrawn)<< std::endl;
break;
case '+':
m_currentGroupDrawn++;
std::cout << "Group "<< m_obj.objGroupName(m_currentGroupDrawn)<< std::endl;
break;
default: default:
break; break;
} }
...@@ -81,6 +99,8 @@ void ObjView::cb_initGL() ...@@ -81,6 +99,8 @@ void ObjView::cb_initGL()
// choose to use GL version 2 // choose to use GL version 2
Utils::GLSLShader::setCurrentOGLVersion(2); Utils::GLSLShader::setCurrentOGLVersion(2);
m_dr = new Utils::Drawer;
// create VBO for position // create VBO for position
m_positionVBO = new Utils::VBO; m_positionVBO = new Utils::VBO;
m_texcoordVBO = new Utils::VBO; m_texcoordVBO = new Utils::VBO;
...@@ -105,22 +125,130 @@ void ObjView::cb_initGL() ...@@ -105,22 +125,130 @@ void ObjView::cb_initGL()
m_obj.createGroupMatVBO_PTN(m_positionVBO,m_texcoordVBO,m_normalVBO); m_obj.createGroupMatVBO_PTN(m_positionVBO,m_texcoordVBO,m_normalVBO);
} }
void ObjView::drawBB( const Geom::BoundingBox<VEC3>& bb)
{
const VEC3& mi = bb.min();
const VEC3& ma = bb.max();
m_dr->newList(GL_COMPILE_AND_EXECUTE);
m_dr->lineWidth(3.0f);
m_dr->begin(GL_LINE_LOOP);
m_dr->color3f(1.0f,1.0f,0.0f);
m_dr->vertex3f(mi[0],mi[1],mi[2]);
m_dr->vertex3f(ma[0],mi[1],mi[2]);
m_dr->vertex3f(ma[0],ma[1],mi[2]);
m_dr->vertex3f(mi[0],ma[1],mi[2]);
m_dr->end();
m_dr->begin(GL_LINE_LOOP);
m_dr->color3f(1.0f,1.0f,0.0f);
m_dr->vertex3f(mi[0],mi[1],ma[2]);
m_dr->vertex3f(ma[0],mi[1],ma[2]);
m_dr->vertex3f(ma[0],ma[1],ma[2]);
m_dr->vertex3f(mi[0],ma[1],ma[2]);
m_dr->end();
m_dr->begin(GL_LINES);
m_dr->color3f(1.0f,1.0f,0.0f);
m_dr->vertex3f(mi[0],mi[1],mi[2]);
m_dr->vertex3f(mi[0],mi[1],ma[2]);
m_dr->vertex3f(mi[0],ma[1],mi[2]);
m_dr->vertex3f(mi[0],ma[1],ma[2]);
m_dr->vertex3f(ma[0],ma[1],mi[2]);
m_dr->vertex3f(ma[0],ma[1],ma[2]);
m_dr->vertex3f(ma[0],mi[1],mi[2]);
m_dr->vertex3f(ma[0],mi[1],ma[2]);
m_dr->end();
m_dr->endList();
}
void ObjView::cb_redraw() void ObjView::cb_redraw()
{ {
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
unsigned int nb = m_obj.nbMatGroups(); unsigned int nb = m_obj.nbObjGroups();
const std::vector<Algo::Surface::Import::MaterialOBJ*>& mats = m_obj.getMaterials(); // const std::vector<Algo::Surface::Import::MaterialOBJ*>& mats = m_obj.getMaterials();
if (m_currentGroupDrawn<(nb-1))
{
std::cout << "Draw Object "<< m_currentGroupDrawn << std::endl;
unsigned int i = m_currentGroupDrawn;
drawBB(m_obj.getGroupBB(i));
std::cout << "BB drawn" << std::endl;
switch(m_RenderStyle)
{
case 0: // MONO
for (unsigned int j=0; j<m_obj.nbSubGroup(i);++j)
{
Geom::Vec4f v(0.2f,1.0f,0.4f,0.0f); // color here green
m_phongShader->setAmbiant(0.2f*v) ;
m_phongShader->setDiffuse(v) ;
m_phongShader->setSpecular(v) ;
m_phongShader->setShininess(10000.0) ;
m_phongShader->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i,j), m_obj.nbIndices(i,j));
m_phongShader->disableVertexAttribs();
}
break;
case 1: // COLOR
for (unsigned int j=0; j<m_obj.nbSubGroup(i);++j)
{
const Algo::Surface::Import::MaterialOBJ* mat = m_obj.materialOf(i,j);
Geom::Vec4f v(mat->diffuseColor[0],mat->diffuseColor[1],mat->diffuseColor[2],0.0f);
m_phongShader->setAmbiant(0.2f*v) ;
m_phongShader->setDiffuse(v) ;
m_phongShader->setSpecular(v) ;
m_phongShader->setShininess(10000.0) ;
m_phongShader->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i,j), m_obj.nbIndices(i,j));
m_phongShader->disableVertexAttribs();
}
default:
for (unsigned int j=0; j<m_obj.nbSubGroup(i);++j)
{
const Algo::Surface::Import::MaterialOBJ* mat = m_obj.materialOf(i,j);
if (mat->textureDiffuse != NULL)
{
m_shader2->setTexture(mat->textureDiffuse);
m_shader2->setShininess(mat->shininess);
m_shader2->setAmbient(0.8f);
m_shader2->activeTexture();
m_shader2->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i,j), m_obj.nbIndices(i,j));
m_shader2->disableVertexAttribs();
}
else
{
Geom::Vec4f v;
v[0] = 0.5f; v[1] = 0.5f; v[2] = 0.5f; v[3] = 0.0f;
m_phongShader->setAmbiant(v) ;
v[0] = mat->diffuseColor[0]; v[1] = mat->diffuseColor[1]; v[2] = mat->diffuseColor[2]; v[3] = 0.0f;
m_phongShader->setDiffuse(v) ;
v[0] = mat->specularColor[0]; v[1] = mat->specularColor[1]; v[2] = mat->specularColor[2]; v[3] = 0.0f;
m_phongShader->setSpecular(v) ;
m_phongShader->setShininess(mat->shininess) ;
m_phongShader->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i,j), m_obj.nbIndices(i,j));
m_phongShader->disableVertexAttribs();
}
}
}
}
else
for (unsigned int i=0; i<nb; ++i) for (unsigned int i=0; i<nb; ++i)
{ {
drawBB(m_obj.getGroupBB(i));
switch(m_RenderStyle) switch(m_RenderStyle)
{ {
case 0: // MONO case 0: // MONO
{ for (unsigned int j=0; j<m_obj.nbSubGroup(i);++j)
{
Geom::Vec4f v(0.2f,1.0f,0.4f,0.0f); // color here green Geom::Vec4f v(0.2f,1.0f,0.4f,0.0f); // color here green
m_phongShader->setAmbiant(0.2f*v) ; m_phongShader->setAmbiant(0.2f*v) ;
m_phongShader->setDiffuse(v) ; m_phongShader->setDiffuse(v) ;
...@@ -128,33 +256,39 @@ void ObjView::cb_redraw() ...@@ -128,33 +256,39 @@ void ObjView::cb_redraw()
m_phongShader->setSpecular(v) ; m_phongShader->setSpecular(v) ;
m_phongShader->setShininess(10000.0) ; m_phongShader->setShininess(10000.0) ;
m_phongShader->enableVertexAttribs(); m_phongShader->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i), m_obj.nbIndices(i)); glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i,j), m_obj.nbIndices(i,j));
m_phongShader->disableVertexAttribs(); m_phongShader->disableVertexAttribs();
} }
break; break;
case 1: // COLOR case 1: // COLOR
{ for (unsigned int j=0; j<m_obj.nbSubGroup(i);++j)
Geom::Vec4f v(mats[i]->diffuseColor[0],mats[i]->diffuseColor[1],mats[i]->diffuseColor[2],0.0f); {
const Algo::Surface::Import::MaterialOBJ* mat = m_obj.materialOf(i,j);
Geom::Vec4f v(mat->diffuseColor[0],mat->diffuseColor[1],mat->diffuseColor[2],0.0f);
m_phongShader->setAmbiant(0.2f*v) ; m_phongShader->setAmbiant(0.2f*v) ;
m_phongShader->setDiffuse(v) ; m_phongShader->setDiffuse(v) ;
// v[0] = 1.0f; v[1] = 1.0f; v[2] = 1.0f; v[3] = 0.0f; // use this for specular effected // v[0] = 1.0f; v[1] = 1.0f; v[2] = 1.0f; v[3] = 0.0f; // use this for specular effected
m_phongShader->setSpecular(v) ; m_phongShader->setSpecular(v) ;
m_phongShader->setShininess(10000.0) ; m_phongShader->setShininess(10000.0) ;
m_phongShader->enableVertexAttribs(); m_phongShader->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i), m_obj.nbIndices(i)); glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i,j), m_obj.nbIndices(i,j));
m_phongShader->disableVertexAttribs(); m_phongShader->disableVertexAttribs();
} }
default: default:
{ for (unsigned int j=0; j<m_obj.nbSubGroup(i);++j)
if (mats[i]->textureDiffuse != NULL) {
const Algo::Surface::Import::MaterialOBJ* mat = m_obj.materialOf(i,j);
if (mat->textureDiffuse != NULL)
{ {
m_shader2->setTexture(mats[i]->textureDiffuse); m_shader2->setTexture(mat->textureDiffuse);
m_shader2->setShininess(mats[i]->shininess); m_shader2->setShininess(mat->shininess);
m_shader2->setAmbient(0.8f); m_shader2->setAmbient(0.8f);
m_shader2->activeTexture(); m_shader2->activeTexture();
m_shader2->enableVertexAttribs(); m_shader2->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i), m_obj.nbIndices(i)); glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i,j), m_obj.nbIndices(i,j));
m_shader2->disableVertexAttribs(); m_shader2->disableVertexAttribs();
} }
else else
...@@ -162,13 +296,13 @@ void ObjView::cb_redraw() ...@@ -162,13 +296,13 @@ void ObjView::cb_redraw()
Geom::Vec4f v; Geom::Vec4f v;
v[0] = 0.5f; v[1] = 0.5f; v[2] = 0.5f; v[3] = 0.0f; v[0] = 0.5f; v[1] = 0.5f; v[2] = 0.5f; v[3] = 0.0f;
m_phongShader->setAmbiant(v) ; m_phongShader->setAmbiant(v) ;
v[0] = mats[i]->diffuseColor[0]; v[1] = mats[i]->diffuseColor[1]; v[2] = mats[i]->diffuseColor[2]; v[3] = 0.0f; v[0] = mat->diffuseColor[0]; v[1] = mat->diffuseColor[1]; v[2] = mat->diffuseColor[2]; v[3] = 0.0f;
m_phongShader->setDiffuse(v) ; m_phongShader->setDiffuse(v) ;
v[0] = mats[i]->specularColor[0]; v[1] = mats[i]->specularColor[1]; v[2] = mats[i]->specularColor[2]; v[3] = 0.0f; v[0] = mat->specularColor[0]; v[1] = mat->specularColor[1]; v[2] = mat->specularColor[2]; v[3] = 0.0f;
m_phongShader->setSpecular(v) ; m_phongShader->setSpecular(v) ;
m_phongShader->setShininess(mats[i]->shininess) ; m_phongShader->setShininess(mat->shininess) ;
m_phongShader->enableVertexAttribs(); m_phongShader->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i), m_obj.nbIndices(i)); glDrawArrays(GL_TRIANGLES, m_obj.beginIndex(i,j), m_obj.nbIndices(i,j));
m_phongShader->disableVertexAttribs(); m_phongShader->disableVertexAttribs();
} }
} }
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
//#include "Utils/Qt/qtSimple.h" //#include "Utils/Qt/qtSimple.h"
#include "Utils/Qt/qtQGLV.h" #include "Utils/Qt/qtQGLV.h"
#include "Utils/textures.h" #include "Utils/textures.h"
#include "Utils/drawer.h"
#include "Utils/Shaders/shaderSimpleTexture.h" #include "Utils/Shaders/shaderSimpleTexture.h"
#include "Utils/Shaders/shaderPhongTexture.h" #include "Utils/Shaders/shaderPhongTexture.h"
#include "Utils/Shaders/shaderPhong.h" #include "Utils/Shaders/shaderPhong.h"
...@@ -66,6 +67,10 @@ public: ...@@ -66,6 +67,10 @@ public:
MAP myMap ; MAP myMap ;
Algo::Surface::Import::OBJModel<PFP> m_obj; Algo::Surface::Import::OBJModel<PFP> m_obj;
Utils::Drawer* m_dr;
unsigned int m_currentGroupDrawn;
void drawBB( const Geom::BoundingBox<VEC3>& bb);
// VBO // VBO
Utils::VBO* m_positionVBO; Utils::VBO* m_positionVBO;
Utils::VBO* m_normalVBO; Utils::VBO* m_normalVBO;
......
...@@ -91,11 +91,18 @@ class OBJModel ...@@ -91,11 +91,18 @@ class OBJModel
protected: protected:
typename PFP::MAP& m_map; typename PFP::MAP& m_map;
// infof of sub-groups (group/material)
std::vector<unsigned int> m_beginIndices; std::vector<unsigned int> m_beginIndices;
std::vector<unsigned int> m_nbIndices; std::vector<unsigned int> m_nbIndices;
std::vector<unsigned int> m_groupIdx; std::vector<unsigned int> m_groupIdx;
std::vector<unsigned int> m_sgMat;
std::vector<unsigned int> m_objGroups; std::vector<unsigned int> m_objGroups;
std::vector<unsigned int> m_groupFirstSub;
std::vector<unsigned int> m_groupNbSub;
std::vector<std::string> m_groupNames; std::vector<std::string> m_groupNames;
std::vector< Geom::BoundingBox<VEC3> > m_groupBBs; std::vector< Geom::BoundingBox<VEC3> > m_groupBBs;
...@@ -123,7 +130,7 @@ protected: ...@@ -123,7 +130,7 @@ protected:
unsigned int m_tagF ; unsigned int m_tagF ;
void updateGroups(const std::vector<Geom::Vec3f>& pos); void computeBB(const std::vector<Geom::Vec3f>& pos);
public: public:
...@@ -256,41 +263,67 @@ public: ...@@ -256,41 +263,67 @@ public:
* @brief nb group of indices created by createGroupMatVBO_XXX * @brief nb group of indices created by createGroupMatVBO_XXX
* @return * @return
*/ */
unsigned int nbMatGroups() { return m_beginIndices.size(); } // unsigned int nbMatGroups() { return m_beginIndices.size(); }
/**
* @brief number of sub-group in group
* @param grp id of group
* @return
*/
inline unsigned int nbSubGroup(unsigned int grp) const { return m_groupNbSub[grp];}
/** /**
* @brief get the begin index of each group in VBOs (for glDrawArrays) * @brief get the begin index of a sub-group in VBOs (for glDrawArrays)
* @param i id of group * @param i id of group
* @param j id of subgroup in group
* @return begin index * @return begin index
*/ */
unsigned int beginIndex(unsigned int i) const { return m_beginIndices[i]; } inline unsigned int beginIndex(unsigned int i, unsigned int j) const { return m_beginIndices[ m_groupFirstSub[i]+j ]; }
/** /**
* @brief get the number of indices of each group in VBOs (for glDrawArrays) * @brief get the number of indices of a sub-group in VBOs (for glDrawArrays)
* @param i id of group * @param i id of group
* @param j id of subgroup in group
* @return number of indices * @return number of indices
*/ */
unsigned int nbIndices(unsigned int i) const { return m_nbIndices[i]; } inline unsigned int nbIndices(unsigned int i, unsigned int j) const { return m_nbIndices[ m_groupFirstSub[i]+j ]; }
/** /**
* @brief get the id of group in OBJ file * @brief material id of a sub-group
* @param i id of group * @param i id of group
* @param j id of subgroup in group
* @return id of material
*/
inline unsigned int materialIdOf(unsigned int i, unsigned int j) const { return m_sgMat[ m_groupFirstSub[i]+j ]; }
/**
* @brief material of a sub-group
* @param i id of group
* @param j id of subgroup in group
* @return material ptr
*/
inline const MaterialOBJ* materialOf(unsigned int i, unsigned int j) const { return m_materials[materialIdOf(i,j)]; }
/**
* @brief get the id of group in OBJ file os sub-group
* @param i id of sub-group
* @return obj group index * @return obj group index
*/ */
unsigned int groupIdx(unsigned int i) const { return m_groupIdx[i]; } inline unsigned int groupIdx(unsigned int i) const { return m_groupIdx[i]; }
/** /**
* @brief get the number of groups in OBJ file * @brief get the number of groups in OBJ file
* @return number of groups * @return number of groups
*/ */
unsigned int nbObjGroups() { return m_objGroups.size()-1; } unsigned int nbObjGroups() { return m_groupFirstSub.size(); }
/** /**
* @brief get the index of first group mat of obj * @brief get the index of first group mat of obj
* @param i id of obj group * @param i id of obj group
* @return id of first group mat * @return id of first group mat
*/ */
unsigned int objGroup(unsigned int i) const { return m_objGroups[i]; } // unsigned int objGroup(unsigned int i) const { return m_objGroups[i]; }
const Geom::BoundingBox<VEC3>& getGroupBB(unsigned int i) const { return m_groupBBs[i];} const Geom::BoundingBox<VEC3>& getGroupBB(unsigned int i) const { return m_groupBBs[i];}
......
This diff is collapsed.
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