Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

Commit 11531b8a authored by Thomas Jund's avatar Thomas Jund
Browse files

ajout affichage d'obj texture pour agents

parent dc7ea6b5
......@@ -7,7 +7,10 @@
#include "env_map.h"
#include "spatialHashing.h"
//#define SECURED
#define EXPORTING_AGENT
//#define EXPORTING_OBJ
#ifdef SECURED
#include "Algo/MovingObjects/particle_cell_2D_secured.h"
......@@ -15,6 +18,19 @@
#include "Algo/MovingObjects/particle_cell_2D.h"
#endif
#ifdef EXPORTING_AGENT
#include "Utils/vbo.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#endif
#ifdef EXPORTING_OBJ
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/vbo.h"
#include "Algo/Import/importObjTex.h"
#include "shaderCustomTex.h"
#endif
class Simulator ;
class Agent
......@@ -24,6 +40,8 @@ public:
Agent(Simulator* sim, const VEC3& position, const VEC3& goals) ;
void init(const VEC3& start, const VEC3& goal);
void initGL();
void draw();
VEC3 getPosition() ;
......@@ -50,6 +68,32 @@ public:
std::vector<std::pair<float, Obstacle*> > obstacleNeighbors_ ;
std::vector<std::pair<float, Obstacle*> > movingObstacleNeighbors_;
#ifdef EXPORTING_AGENT
static const int m_ghost_nb = 500;
std::list<VEC3> m_ghost_previousPos;
Utils::VBO * m_ghost_VBO;
Utils::ShaderSimpleColor * m_ghost_shader;
#endif
#ifdef EXPORTING_OBJ
PFP2::MAP map;
VertexAttribute<VEC3> position;
VertexAttribute<VEC3> normal;
VEC3 previousPos;
float previousRot;
Algo::Render::GL2::MapRender* m_render;
Utils::VBO* m_positionVBO;
Utils::VBO* m_normalVBO;
Utils::Texture<2,Geom::Vec3uc>* m_texture;
Utils::VBO* m_texcoordVBO;
ShaderCustomTex* m_shaderTex;
Algo::Surface::Import::OBJModel<PFP2> m_obj;
unsigned int m_nbIndices;
#endif
#ifdef SPATIAL_HASHING
VEC3 pos ;
#else
......
......@@ -8,6 +8,15 @@
#include <set>
#include "Algo/MovingObjects/particle_cell_2D_memo.h"
//#define EXPORTING_BOXES
#ifdef EXPORTING_BOXES
#include "Algo/Render/GL2/mapRender.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderFlat.h"
#include "Utils/vbo.h"
#endif
using namespace std;
PFP::VEC3 rotate (PFP::VEC3 pos1, PFP::VEC3 center, float angle);
float get_angle (PFP::VEC3 v1, PFP::VEC3 v2);
......@@ -19,6 +28,10 @@ class MovingObstacle
{
public:
MovingObstacle(Simulator* sim, int index, std::vector<PFP::VEC3> pos, std::vector<VEC3> goals, bool rigid, bool spin, Dart d=NIL, ArticulatedObstacle * art=NULL, int indParent=-1);
void initGL();
void draw();
bool test_opposition(VEC3 o, VEC3 p1, VEC3 p2);
// void contournerBatiment();
void updateAgentNeighbors() ;
......@@ -57,6 +70,13 @@ public:
Dart groundFace;
#ifdef EXPORTING_BOXES
Algo::Render::GL2::MapRender* m_render;
Utils::VBO* m_positionVBO;
Utils::VBO* m_normalVBO;
Utils::ShaderSimpleColor* m_shader;
#endif
//vector de détails pour la deformation
// std::vector<PFP::VEC3> verticesDeformation;
......
......@@ -4,9 +4,10 @@ PRECISON;
uniform sampler2D textureUnit;
in vec3 N;
in vec2 fragTexCoord;
uniform vec4 ambient;
FRAG_OUT_DEF;
void main()
{
gl_FragData[0] = texture2D(textureUnit,fragTexCoord);
gl_FragData[0] = ambient*texture2D(textureUnit,fragTexCoord);
gl_FragData[1] = vec4( 0.5*normalize(N)+vec3(0.5), 1.0 );
}
\ No newline at end of file
......@@ -21,6 +21,7 @@ protected:
CGoGNGLuint m_unif_unit;
int m_unit;
Geom::Vec4f m_col;
Utils::GTexture* m_tex_ptr;
Utils::VBO* m_vboPos;
......@@ -54,6 +55,8 @@ public:
unsigned int setAttributePosition(Utils::VBO* vbo);
unsigned int setAttributeTexCoord(Utils::VBO* vbo);
void setBaseColor(Geom::Vec4f col);
};
#endif
This image diff could not be displayed because it is too large. You can view the blob instead.
......@@ -27,6 +27,9 @@ float Agent::rangeSq_ = range_ * range_ ;
unsigned int Agent::cptAgent = 0 ;
Agent::Agent(Simulator* sim, const VEC3& start, const VEC3& goal, Dart d) :
#ifdef EXPORTING_OBJ
m_obj(map),
#endif
#ifdef SPATIAL_HASHING
pos(position),
#else
......@@ -44,6 +47,9 @@ Agent::Agent(Simulator* sim, const VEC3& start, const VEC3& goal, Dart d) :
}
Agent::Agent(Simulator* sim, const VEC3& start, const VEC3& goal) :
#ifdef EXPORTING_OBJ
m_obj(map),
#endif
#ifdef SPATIAL_HASHING
pos(position),
#else
......@@ -62,6 +68,12 @@ Agent::Agent(Simulator* sim, const VEC3& start, const VEC3& goal) :
void Agent::init(const VEC3& start, const VEC3& goal)
{
#ifdef EXPORTING_OBJ
std::vector<std::string> attrNames ;
m_obj.import("./meshRessources/Mexicainlowres.obj",attrNames);
position = map.getAttribute<VEC3, VERTEX>(attrNames[0]) ;
#endif
#ifdef SPATIAL_HASHING
sim->envMap_.addAgentInGrid(this) ;
#endif
......@@ -82,6 +94,92 @@ void Agent::init(const VEC3& start, const VEC3& goal)
agentNo = cptAgent++ ;
}
void Agent::initGL()
{
#ifdef EXPORTING_AGENT
m_ghost_shader = new Utils::ShaderSimpleColor();
m_ghost_shader->setColor(Geom::Vec4f(1.,0.,0.,0.));
// m_ghost_shader->setAmbiant(Geom::Vec4f(1.,1.,0.,0.)) ;
// m_ghost_shader->setDiffuse(Geom::Vec4f(1.,1.,0.,0.));
m_ghost_VBO = new Utils::VBO();
m_ghost_VBO->setDataSize(3);
m_ghost_VBO->allocate(m_ghost_nb);
m_ghost_shader->setAttributePosition(m_ghost_VBO);
// registerShader(m_ghost_shader);
#endif
#ifdef EXPORTING_OBJ
m_texcoordVBO = new Utils::VBO();
m_positionVBO = new Utils::VBO();
m_normalVBO = new Utils::VBO();
m_texture = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);
if (m_texture->load("./meshRessources/sombrero2lowres_grp.png"))
m_texture->update();
else
std::cout << "problem : loading texture" << std::endl;
m_texture->setWrapping(GL_CLAMP_TO_EDGE);
m_shaderTex = new ShaderCustomTex();
m_shaderTex->setAttributePosition(m_positionVBO);
m_shaderTex->setAttributeTexCoord(m_texcoordVBO);
m_shaderTex->setTextureUnit(GL_TEXTURE0);
m_shaderTex->setTexture(m_texture);
glEnable(GL_TEXTURE_2D);
if (!m_obj.hasNormals())
{
normal = map.getAttribute<VEC3, VERTEX>("normal") ;
if(!normal.isValid())
normal = map.addAttribute<VEC3, VERTEX>("normal") ;
Algo::Surface::Geometry::computeNormalVertices<PFP2>(map, m_obj.m_positions, normal) ;
m_obj.setNormalAttribute(normal);
}
map.setBrowser(NULL);
m_nbIndices = m_obj.createSimpleVBO_PTN(m_positionVBO,m_texcoordVBO,m_normalVBO);
previousPos = VEC3(0,0,0);
#endif
}
void Agent::draw()
{
#ifdef EXPORTING_AGENT
PFP::VEC3* data = static_cast<PFP::VEC3*>(m_ghost_VBO->lockPtr());
unsigned int i = 0;
for(std::list<VEC3>::iterator it = m_ghost_previousPos.begin() ; it != m_ghost_previousPos.end() ; ++it, ++i)
{
data[i] = *it;
}
m_ghost_VBO->releasePtr();
m_ghost_shader->enableVertexAttribs();
glDrawArrays(GL_LINE_STRIP, 0, m_ghost_previousPos.size());
m_ghost_shader->disableVertexAttribs();
#endif
#ifdef EXPORTING_OBJ
Algo::Surface::Geometry::computeNormalVertices<PFP2>(map, m_obj.m_positions, normal) ;
m_nbIndices = m_obj.createSimpleVBO_PTN(m_positionVBO,m_texcoordVBO,m_normalVBO);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
m_shaderTex->activeTexture();
m_shaderTex->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES, 0, m_nbIndices);
m_shaderTex->disableVertexAttribs();
#endif
}
//-----------------------------------------------------------------
......@@ -210,7 +308,7 @@ void Agent::updateObstacleNeighbors()
if ((obstacleNeighbors_.size() < maxMovingObstacles_|| distSq < maxDistObst)
&& distSq < rangeSq_)
{
// if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT)
if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT)
{
if (distSq > maxDistObst)
......@@ -229,7 +327,7 @@ void Agent::updateObstacleNeighbors()
if ((movingObstacleNeighbors_.size() < maxMovingObstacles_ || distSq < maxDistMovingObst)
&& distSq < rangeSq_)
{
// if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT)
if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT)
{
if (distSq > maxDistMovingObst)
......@@ -267,7 +365,7 @@ void Agent::updateObstacleNeighbors()
if ((movingObstacleNeighbors_.size() < maxNeighbors_ || distSq < maxDistMovingObst)
&&distSq < rangeSq_)
{
// if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT)
if (Geom::testOrientation2D(part_.getPosition(), (*it)->p1, (*it)->p2) == Geom::RIGHT)
{
if (distSq > maxDistMovingObst) maxDistMovingObst = distSq ;
......@@ -336,6 +434,12 @@ void Agent::update()
if(target != part_.getPosition())
std::cout << "Problem agent " << agentNo << " (position : " << part_.getPosition() << ") time " << sim_->nbSteps_ << std::endl;
#endif
#ifdef EXPORTING_AGENT
m_ghost_previousPos.push_back(target);
if(m_ghost_previousPos.size()>m_ghost_nb)
m_ghost_previousPos.pop_front();
#endif
#endif
meanDirection_.set(0) ;
......@@ -346,6 +450,27 @@ void Agent::update()
meanVelocity_[3] = velocity_ ;
meanDirection_.normalize() ;
}
#ifdef EXPORTING_OBJ
VEC3 dir = meanDirection_ ;
VEC3 base(0, -1, 0) ;
VEC3 axisRot = base ^ dir ;
int sign = axisRot[2] > 0 ? 1 : -1 ;
//57,2957795 : conversion from radian to degree
float myRot = acos(-dir[1])+M_PI;
const VEC3 displ = -previousPos+getPosition();
TraversorV<PFP2::MAP> tV(map);
for(Dart d = tV.begin() ; d != tV.end() ; d = tV.next())
{
position[d] += rotate(position[d], previousPos, -previousRot);
position[d] = position[d]+displ;
position[d] += rotate(position[d], getPosition(), myRot);
}
previousPos = getPosition();
previousRot = myRot;
#endif
}
//-----------------------------------------------------------------
......
......@@ -258,6 +258,9 @@ void EnvMap::initGL()
std::sort(filenames.begin(), filenames.end());
std::sort(texturenames.begin(), texturenames.end());
std::reverse(filenames.begin(), filenames.end());
std::reverse(texturenames.begin(), texturenames.end());
// filenames.push_back(std::string("./meshRessources/cityTex/Building11.obj"));
// texturenames.push_back(std::string("./meshRessources/cityTex/AO_Buildings11.png"));
......@@ -267,6 +270,8 @@ void EnvMap::initGL()
for(unsigned int i = 0 ; i < filenames.size() ; ++i)
{
std::cout << "file " << filenames[i] << std::endl;
PFP::MAP * nmap = new PFP::MAP();
std::vector<std::string> attrNames ;
......@@ -308,6 +313,13 @@ void EnvMap::initGL()
shaderTex->setTextureUnit(GL_TEXTURE0);
shaderTex->setTexture(texture);
if(filenames[i].find("ground.obj")!=string::npos)
shaderTex->setBaseColor(Geom::Vec4f(0.6,0.8,0.6,0));
else if(filenames[i].find("road.obj")!=string::npos)
shaderTex->setBaseColor(Geom::Vec4f(0.6,0.6,0.6,0));
else if(filenames[i].find("pedway.obj")!=string::npos)
shaderTex->setBaseColor(Geom::Vec4f(0.9,0.9,0.9,0));
glEnable(GL_TEXTURE_2D);
nmap->setBrowser(NULL);
......@@ -414,8 +426,12 @@ void EnvMap::draw()
#ifdef EXPORTING3
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_POLYGON_OFFSET_FILL) ;
for(unsigned int i = 0 ; i < m_obj_Export.size() ; ++i)
{
glPolygonOffset( std::max(0.2f*i,-0.75f),std::max(0.2f*i,-0.75f)) ;
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();
......@@ -424,6 +440,9 @@ void EnvMap::draw()
glDrawArrays(GL_TRIANGLES, 0, nbIndices);
m_shaderTex_Export[i]->disableVertexAttribs();
}
glDisable(GL_POLYGON_OFFSET_FILL) ;
//glDisable(GL_LIGHTING);
// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
//
......@@ -452,54 +471,56 @@ void EnvMap::scale(float val)
void EnvMap::markPedWay()
{
//split all pedway with 3 roads intersection (to avoid spikes)
CellMarker<FACE> treat(map) ;
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (!treat.isMarked(d))
{
treat.mark(d) ;
Dart dd = d ;
do
//intern face for intersection
if(map.faceDegree(d)==3)
{
Dart ddd = dd ;
Dart dd = d;
do
{
if (obstacleMark.isMarked(dd))
{
pedWayMark.mark(d) ;
break ;
}
ddd = map.alpha1(ddd) ;
} while (ddd != dd) ;
dd = map.phi1(dd) ;
} while (dd != d) ;
//get "corner" quadrangular faces around and split them
Dart dSplit = map.alpha1(map.alpha1(dd));
map.splitFace(map.phi1(dSplit), map.phi_1(dSplit));
treat.mark(dSplit);
treat.mark(map.phi2(map.phi1(dSplit)));
dd = map.phi1(dd);
} while (dd != d);
}
}
}
treat.unmarkAll() ;
treat.unmarkAll();
for (Dart d = map.begin(); d != map.end(); map.next(d))
{
if (!treat.isMarked(d))
{
treat.mark(d) ;
//check around the face
Dart dd = d ;
do
{
if (pedWayMark.isMarked(map.phi2(dd)) && pedWayMark.isMarked(map.phi2(map.phi1(dd)))
&& !pedWayMark.isMarked(map.phi2(map.phi1(map.phi1(dd))))
&& !pedWayMark.isMarked(map.phi2(map.phi1(map.phi1(map.phi1(dd))))))
//if any vertex
Dart ddd = dd ;
do
{
pedWayMark.mark(d) ;
break ;
}
dd = map.phi1(dd) ;
//is an obstacle
if (obstacleMark.isMarked(ddd))
{
//then mark as pedway
pedWayMark.mark(d) ;
break;
}
ddd = map.alpha1(ddd) ;
} while(ddd != dd);
} while (dd != d) ;
dd = map.phi1(dd);
} while (dd != d);
}
}
}
......
......@@ -132,14 +132,14 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
center += pos[i];
}
//extrude face to build a cage
// compute edgeLength for mass-spring
Algo::Surface::Modelisation::extrudeFace<PFP>(map, position, groundFace, -5.0f) ;
map.fillHole(groundFace);
groundFace = map.phi2(groundFace);
if(!rigid_)
{
//extrude face to build a cage
// compute edgeLength for mass-spring
Algo::Surface::Modelisation::extrudeFace<PFP>(map, position, groundFace, 25.0f) ;
map.fillHole(groundFace);
groundFace = map.phi2(groundFace);
Algo::Surface::Modelisation::EarTriangulation<PFP> et(map);
et.triangule();
......@@ -174,6 +174,11 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
{
position[i]+=rotate(position[i], center, angle);
#ifdef EXPORTING_BOXES
Dart d(i);
position[map.phi<211>(d)] += rotate(position[map.phi<211>(d)], center, -angle);
#endif
}
angle=0;
}
......@@ -202,6 +207,43 @@ MovingObstacle::MovingObstacle(Simulator* sim, int ind, std::vector<VEC3> pos, s
// obstacle_range = 15.0f * 15.0f;
}
void MovingObstacle::initGL()
{
#ifdef EXPORTING_BOXES
m_render = new Algo::Render::GL2::MapRender();
m_positionVBO = new Utils::VBO();
// using simple shader with color
m_shader = new Utils::ShaderSimpleColor();
m_shader->setAttributePosition(m_positionVBO);
m_shader->setColor(Geom::Vec4f(0.,1.,0.,0.));
// m_shader->setAmbiant(Geom::Vec4f(0.,1.,0.,0.));
// m_shader->setDiffuse(Geom::Vec4f(0.,1.,0.,0.));
m_positionVBO->updateData(position) ;
m_render->initPrimitives<PFP>(map, Algo::Render::GL2::LINES,false) ;
m_render->initPrimitives<PFP>(map, Algo::Render::GL2::TRIANGLES,false) ;
// registerShader(m_shader);
#endif
}
void MovingObstacle::draw()
{
#ifdef EXPORTING_BOXES
// m_render->initPrimitives<PFP>(map, Algo::Render::GL2::LINES,false) ;
// m_render->initPrimitives<PFP>(map, Algo::Render::GL2::TRIANGLES,false) ;
m_positionVBO->updateData(position);
m_shader->setColor(Geom::Vec4f(1.,0.,0.,0.));
m_render->draw(m_shader, Algo::Render::GL2::TRIANGLES);
m_shader->setColor(Geom::Vec4f(0.,0.,0.,0.));
m_render->draw(m_shader, Algo::Render::GL2::LINES);
#endif
}
VEC3 MovingObstacle::getDilatedPosition(unsigned int ind)
{
Dart d(ind); //WARNING : works only for one face created at start !
......@@ -574,6 +616,11 @@ void MovingObstacle::update()
position[d] += rotate(position[d], center, abs_angle*rotor);
position[d] += (velocity_ * sim_->timeStep_);
#ifdef EXPORTING_BOXES
position[map.phi<211>(d)] += rotate(position[map.phi<211>(d)], center, abs_angle*rotor);
position[map.phi<211>(d)] += (velocity_ * sim_->timeStep_);
#endif
// position[map.phi<211>(d)] += (velocity_ * sim_->timeStep_);
bary += position[d];
......
......@@ -53,7 +53,8 @@
// "}";
ShaderCustomTex::ShaderCustomTex()
ShaderCustomTex::ShaderCustomTex() :
m_col(1)
{
m_nameVS = "ShaderCustomTex_vs";
m_nameFS = "ShaderCustomTex_fs";
......@@ -72,6 +73,8 @@ ShaderCustomTex::ShaderCustomTex()
loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_TRIANGLES, GL_TRIANGLE_STRIP, 3);
m_unif_unit = glGetUniformLocation(this->program_handler(), "textureUnit");
setBaseColor(m_col);
}
void ShaderCustomTex::setTextureUnit(GLenum texture_unit)
......@@ -87,6 +90,17 @@ void ShaderCustomTex::setTexture(Utils::GTexture* tex)
m_tex_ptr = tex;
}
void ShaderCustomTex::setBaseColor(Geom::Vec4f col)
{
m_col = col;
bind();
CGoGNGLuint m_unif_ambiant;
*m_unif_ambiant = glGetUniformLocation(program_handler(),"ambient");
glUniform4fv(*m_unif_ambiant, 1, m_col.data());
unbind();
}
void ShaderCustomTex::activeTexture()
{
glActiveTexture(GL_TEXTURE0 + m_unit);
......
......@@ -813,24 +813,6 @@ void Simulator::addPathToObstacle(MovingObstacle * mo, Dart dStart, Dart dGoal)
mo->goals_.push_back(dest) ;
}
// if(((mo->front-mo->center)*(mo->goals_[mo->curGoal_]-mo->center))<0)
// {
// std::cout << __FILE__ << " " << __LINE__ << " rotate limace" << std::endl;
//
// Geom::Matrix44f m;
// m.identity();
// rotateZ(180.0f,m);
//
// TraversorV<PFP::MAP> tv(mo->map);
// for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
// {
// mo->position[d] -= mo->center;
// mo->position[d] = Geom::transform(mo->position[d],m);
// mo->position[d] += mo->center;
// mo->position[d][2] += 10.0f;
// }
// }
}