Commit 002ed37a authored by Thomas Jund's avatar Thomas Jund
Browse files

import de mesh avec texture et normales flat pour la ville

parent d2dc2619
......@@ -43,6 +43,7 @@ add_executable( socialAgentsD
../src/gl2ps.c
../src/ShapeMatching/rigidXfComputation.cpp
../src/shaderCustom.cpp
../src/shaderCustomTex.cpp
${socialAgents_moc}
${socialAgents_ui}
)
......
......@@ -43,6 +43,7 @@ add_executable( socialAgents
../src/gl2ps.c
../src/ShapeMatching/rigidXfComputation.cpp
../src/shaderCustom.cpp
../src/shaderCustomTex.cpp
${socialAgents_moc}
${socialAgents_ui}
)
......
......@@ -32,6 +32,15 @@ class ArticulatedObstacle;
#include "pfp.h"
//#define EXPORTING3
#ifdef EXPORTING3
#include "Utils/Shaders/shaderPhongTexture.h"
#include "Utils/Shaders/shaderSimpleTexture.h"
#include "shaderCustomTex.h"
#include "Algo/Import/importObjTex.h"
#endif
class EnvMap
{
public:
......@@ -52,6 +61,9 @@ public:
EnvMap() ;
void init(unsigned int config, REAL width, REAL height, REAL minSize, REAL maxSize) ;
void initGL();
void draw();
void scale(float val);
void markPedWay() ;
......@@ -112,6 +124,32 @@ public:
void popObstNeighborInCells(Obstacle* o, Dart d);
void find_next(Obstacle* o,Dart * d, CellMarkerMemo<FACE>& cms);
#ifdef EXPORTING3
std::vector<PFP::MAP *> m_map_Export;
std::vector<Algo::Surface::Import::OBJModel<PFP2> *> m_obj_Export;
std::vector<Utils::Texture<2,Geom::Vec3uc>*> m_texture_Export;
std::vector<Utils::VBO*> m_positionVBO_Export;
std::vector<Utils::VBO*> m_normalVBO_Export;
std::vector<Utils::VBO*> m_texcoordVBO_Export;
std::vector<ShaderCustomTex*> m_shaderTex_Export;
std::vector<unsigned int> m_nbIndice_Export;
// PFP2::MAP m_map_Export;
// VertexAttribute<VEC3> position_Export ;
// VertexAttribute<VEC3> normal_Export ;
// Algo::Surface::Import::OBJModel<PFP2> * m_obj_Export;
//
// Utils::Texture<2,Geom::Vec3uc>* m_texture_Export;
// Utils::VBO* m_positionVBO_Export;
// Utils::VBO* m_normalVBO_Export;
// Utils::VBO* m_texcoordVBO_Export;
// ShaderCustomTex* m_shaderTex_Export;
//
// unsigned int m_nbIndice_Export;
#endif
std::vector<Dart> newBuildings ;
......
......@@ -58,8 +58,8 @@ public:
Utils::VBO* m_texcoordVBO;
Utils::ShaderPhongTexture* m_shaderTex;
// Utils::ShaderSimpleTexture* m_shaderTex;
// Utils::ShaderPhongTexture* m_shaderTex;
Utils::ShaderSimpleTexture* m_shaderTex;
Algo::Surface::Import::OBJModel<PFP2> m_obj;
unsigned int m_nbIndices;
#else
......
......@@ -9,6 +9,7 @@ uniform vec4 diffuse;
uniform vec4 ambient;
VARYING_OUT vec4 ColorFS;
VARYING_OUT vec3 N;
VARYING_OUT vec2 texCoord;
void main(void)
{
vec3 v1 = POSITION_IN(1).xyz - POSITION_IN(0).xyz;
......
This image diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -221,6 +221,162 @@ void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, RE
}
}
void EnvMap::initGL()
{
#ifdef EXPORTING3
PFP::MAP * nmap = new PFP::MAP();
std::vector<std::string> attrNames ;
Algo::Surface::Import::OBJModel<PFP2> * obj = new Algo::Surface::Import::OBJModel<PFP2>(*nmap);
obj->import("./meshRessources/cityTex/Building11.obj",attrNames);
VertexAttribute<VEC3> position_Export = nmap->getAttribute<VEC3, VERTEX>(attrNames[0]) ;
TraversorV<PFP2::MAP> tV(*nmap);
for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
{
position_Export[d] *= 100.0f;
position_Export[d] += VEC3(2000,0,0);
}
Utils::VBO * texcoordVBO = new Utils::VBO();
Utils::VBO * positionVBO = new Utils::VBO();
Utils::VBO * normalVBO = new Utils::VBO();
Utils::Texture<2,Geom::Vec3uc> * texture = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);
if (texture->load("./meshRessources/cityTex/AO_Buildings11.png"))
texture->update();
else
std::cout << "problem : loading texture" << std::endl;
texture->setWrapping(GL_CLAMP_TO_EDGE);
ShaderCustomTex * shaderTex = new ShaderCustomTex();
shaderTex->setAttributePosition(positionVBO);
shaderTex->setAttributeTexCoord(texcoordVBO);
shaderTex->setTextureUnit(GL_TEXTURE0);
shaderTex->setTexture(texture);
glEnable(GL_TEXTURE_2D);
nmap->setBrowser(NULL);
if (!obj->hasNormals())
{
VertexAttribute<VEC3> normal = nmap->getAttribute<VEC3, VERTEX>("normal") ;
if(!normal.isValid())
normal = nmap->addAttribute<VEC3, VERTEX>("normal") ;
Algo::Surface::Geometry::computeNormalVertices<PFP2>(*nmap, obj->m_positions, normal) ;
obj->setNormalAttribute(normal);
}
unsigned int nbIndices = obj->createSimpleVBO_PTN(positionVBO,texcoordVBO,normalVBO);
m_map_Export.push_back(nmap);
m_obj_Export.push_back(obj);
m_texture_Export.push_back(texture);
m_texcoordVBO_Export.push_back(texcoordVBO);
m_positionVBO_Export.push_back(positionVBO);
m_normalVBO_Export.push_back(normalVBO);
m_shaderTex_Export.push_back(shaderTex);
m_nbIndice_Export.push_back(nbIndices);
// m_map_Export = new PFP2::MAP();
//
// std::vector<std::string> attrNames ;
// m_obj_Export = new Algo::Surface::Import::OBJModel<PFP2>(m_map_Export);
// m_obj_Export->import("./meshRessources/cityTex/Building11.obj",attrNames);
//
// position_Export = m_map_Export.getAttribute<VEC3, VERTEX>(attrNames[0]) ;
// TraversorV<PFP2::MAP> tV(m_map_Export);
//
// VEC3 bary(0);
// unsigned int count = 0;
// for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
// {
// bary += position_Export[d];
// count++;
// }
// bary /= float(count);
//
// for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
// {
//// position_Export[d] -= bary;
// position_Export[d] *= 100.0f;
// std::cout << position_Export[d] << std::endl;
// position_Export[d] += VEC3(2000,0,0);
// std::cout << position_Export[d] << std::endl;
// }
//
// m_texcoordVBO_Export = new Utils::VBO();
// m_positionVBO_Export = new Utils::VBO();
// m_normalVBO_Export = new Utils::VBO();
//
// m_texture_Export = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);
//
// if (m_texture_Export->load("./meshRessources/cityTex/AO_Buildings11.png"))
// m_texture_Export->update();
// else
// std::cout << "problem : loading texture" << std::endl;
//
// m_texture_Export->setWrapping(GL_CLAMP_TO_EDGE);
//
// m_shaderTex_Export = new ShaderCustomTex();
// m_shaderTex_Export->setAttributePosition(m_positionVBO_Export);
// m_shaderTex_Export->setAttributeTexCoord(m_texcoordVBO_Export);
// m_shaderTex_Export->setTextureUnit(GL_TEXTURE0);
// m_shaderTex_Export->setTexture(m_texture_Export);
//
// glEnable(GL_TEXTURE_2D);
//
// m_map_Export.setBrowser(NULL);
//
// if (!m_obj_Export->hasNormals())
// {
// normal_Export = m_map_Export.getAttribute<VEC3, VERTEX>("normal") ;
// if(!normal_Export.isValid())
// normal_Export = m_map_Export.addAttribute<VEC3, VERTEX>("normal") ;
//
// Algo::Surface::Geometry::computeNormalVertices<PFP2>(m_map_Export, m_obj_Export->m_positions, normal_Export) ;
// m_obj_Export->setNormalAttribute(normal_Export);
// }
//
// m_nbIndice_Export = m_obj_Export->createSimpleVBO_PTN(m_positionVBO_Export,m_texcoordVBO_Export,m_normalVBO_Export);
#endif
}
void EnvMap::draw()
{
#ifdef EXPORTING3
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
for(unsigned int i = 0 ; i < m_obj_Export.size() ; ++i)
{
unsigned int nbIndices = m_obj_Export[i]->createSimpleVBO_PTN( m_positionVBO_Export[i], m_texcoordVBO_Export[i], m_normalVBO_Export[i]);
m_shaderTex_Export[i]->activeTexture();
m_shaderTex_Export[i]->enableVertexAttribs();
// glDrawArrays(GL_TRIANGLES, 0, m_nbIndice_Export[i]);
glDrawArrays(GL_TRIANGLES, 0, nbIndices);
m_shaderTex_Export[i]->disableVertexAttribs();
}
//glDisable(GL_LIGHTING);
// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
//
// unsigned int nbIndices = m_obj_Export->createSimpleVBO_PTN( m_positionVBO_Export, m_texcoordVBO_Export, m_normalVBO_Export);
//
// m_shaderTex_Export->activeTexture();
// m_shaderTex_Export->enableVertexAttribs();
// glDrawArrays(GL_TRIANGLES, 0, m_nbIndice_Export);
// m_shaderTex_Export->disableVertexAttribs();
//
//glEnable(GL_LIGHTING);
#endif
}
void EnvMap::scale(float val)
{
TraversorV<PFP::MAP> tV(map);
......
......@@ -45,6 +45,7 @@ void MovingMesh::initGL()
{
//rendering
m_render = new Algo::Render::GL2::MapRender();
m_positionVBO = new Utils::VBO();
m_normalVBO = new Utils::VBO();
......@@ -60,16 +61,16 @@ void MovingMesh::initGL()
m_texture->setWrapping(GL_CLAMP_TO_EDGE);
m_shaderTex = new Utils::ShaderPhongTexture();
// m_shaderTex = new Utils::ShaderSimpleTexture();
// m_shaderTex = new Utils::ShaderPhongTexture();
m_shaderTex = new Utils::ShaderSimpleTexture();
m_shaderTex->setAttributePosition(m_positionVBO);
m_shaderTex->setAttributeTexCoord(m_texcoordVBO);
m_shaderTex->setAttributeNormal(m_normalVBO);
// m_shaderTex->setAttributeNormal(m_normalVBO);
m_shaderTex->setTextureUnit(GL_TEXTURE0);
m_shaderTex->setTexture(m_texture);
m_shaderTex->setShininess(10.0f);
m_shaderTex->setAmbient(0.1f);
m_shaderTex->setSpecular(Geom::Vec4f(0.5));
// m_shaderTex->setShininess(10.0f);
// m_shaderTex->setAmbient(0.1f);
// m_shaderTex->setSpecular(Geom::Vec4f(0.5));
glEnable(GL_TEXTURE_2D);
......
......@@ -305,6 +305,21 @@ void SocialAgents::initRendering()
registerShader(simulator.movingMeshes_[i]->m_simpleColorShader);
#endif
}
simulator.envMap_.initGL();
#ifdef EXPORTING3
for(unsigned int j = 0 ; j < simulator.envMap_.m_shaderTex_Export.size() ; ++j)
registerShader(simulator.envMap_.m_shaderTex_Export[j]);
#endif
// bb = Algo::Geometry::computeBoundingBox<PFP>(simulator.envMap_.m_map_Export, simulator.envMap_.position_Export) ;
//
// VEC3 gPosObj = bb.center() ;
// float tailleX = bb.size(0) ;
// float tailleY = bb.size(1) ;
// float tailleZ = bb.size(2) ;
// float gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ);///10.0f ;
// setParamObject(gWidthObj, gPosObj.data()) ;
}
void SocialAgents::updateObstacleVBO()
......@@ -488,6 +503,8 @@ void SocialAgents::cb_redraw()
// glDrawArrays(GL_QUADS, 0, 4*N_THETA*N_PHI );
glDrawArrays(GL_POLYGON, 0, 4);
m_Ground_Shader->disableVertexAttribs();
#endif
glDisable(GL_POLYGON_OFFSET_FILL) ;
......@@ -496,6 +513,7 @@ void SocialAgents::cb_redraw()
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
glEnable(GL_LIGHTING);
simulator.envMap_.draw();
dock.check_slide->setRange(0, simulator.envMap_.map.end().index) ;
......
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