Commit f7fcf8dc authored by Thomas Jund's avatar Thomas Jund
Browse files

texture sur les limaces

parent b7b5b383
......@@ -13,15 +13,21 @@
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Qt/qtSimple.h"
using namespace std;
#include "Utils/Shaders/shaderPhongTexture.h"
#include "Utils/Shaders/shaderSimpleTexture.h"
#include "Algo/Import/importObjTex.h"
using namespace std;
#define EXPORTING2
class MovingMesh
{
public:
MovingMesh(EnvMap& envMap, Dart d, std::string filename);
void initGL();
void linkWithObstacle(MovingObstacle * mo);
void transform(Geom::Matrix44f m);
......@@ -40,14 +46,25 @@ public:
PFP::MAP& motherMap;
VertexAttribute<VEC3>& motherPosition;
PFP::MAP map;
PFP2::MAP map;
VertexAttribute<VEC3> position;
VertexAttribute<VEC3> normal;
Algo::Render::GL2::MapRender* m_render;
Utils::VBO* m_positionVBO;
Utils::VBO* m_normalVBO;
#ifdef EXPORTING2
Utils::Texture<2,Geom::Vec3uc>* m_texture;
Utils::VBO* m_texcoordVBO;
Utils::ShaderPhongTexture* m_shaderTex;
// Utils::ShaderSimpleTexture* m_shaderTex;
Algo::Surface::Import::OBJModel<PFP2> m_obj;
unsigned int m_nbIndices;
#else
Utils::ShaderSimpleColor* m_simpleColorShader;
#endif
float scaleValue;
......
......@@ -24,6 +24,13 @@ struct PFP : public PFP_STANDARD
typedef NoMathIONameAttribute<std::pair<bool, bool> > BOOLATTRIB ;
} ;
struct PFP2 : public PFP_STANDARD
{
// definition de la carte
// typedef EmbeddedMap2 MAP ;
typedef Algo::Surface::IHM::ImplicitHierarchicalMap MAP ;
} ;
typedef PFP::VEC3 VEC3 ;
typedef PFP::REAL REAL ;
......
......@@ -73,56 +73,57 @@ float SmoothAt( int x, int y )
void main()
{
const int AO_RADIUS_MIN = 8;
const int AO_RADIUS_MAX = 50;
float AO = 1.0;
// const int AO_RADIUS_MIN = 8;
// const int AO_RADIUS_MAX = 50;
//
// float AO = 1.0;
float edgeEnhancement;
//
//
// // if( gl_TexCoord[0].x > 0.5 )
// // {
// // edgeEnhancement = 1.0 - SobelAt(0,0);
// // }
// // else
// // {
edgeEnhancement = SmoothAt(0,0);
//
// float d = fetchDepth(0,0);
// if( d < 1.0 )
// {
// float weightSum = 0.0;
// vec3 centreNor = fetchNor(0,0);
//
//
// float AORadius = d*AO_RADIUS_MIN + (1.0-d)*AO_RADIUS_MAX;
// float AOStep = AORadius / 10;
// if( AOStep < 1.0 )
// AOStep = 1.0;
//
// for( float i=-AORadius; i<=AORadius; i+=AOStep )
// for( float j=-AORadius; j<=AORadius; j+=AOStep )
// {
// float distToCenter = sqrt( i*i + j*j );
// if( distToCenter>=1.0 && distToCenter<=AORadius && fetchDepth(j,i)<1.0 )
// {
// float weight = 1.0 / distToCenter;
// vec3 nor = fetchNor(j,i);
// weightSum += weight;
// AO += weight * max( dot(centreNor,nor), 0.0 );
// }
// }
//
// AO /= weightSum;
// // AO = 0.5*AO + 0.5;
// }
// // }
//
//
//
// // edgeEnhancement = SmoothAt(0,0);
// if( gl_TexCoord[0].x > 0.5 )
// {
// edgeEnhancement = 1.0 - SobelAt(0,0);
// }
// gl_FragColor = vec4( (0.5 + 0.5*AO*edgeEnhancement) * texture2D(u_FrameBufferColor,gl_TexCoord[0]).xyz, 1.0 );
// else
// {
edgeEnhancement = SmoothAt(0,0);
float d = fetchDepth(0,0);
if( d < 1.0 )
{
float weightSum = 0.0;
vec3 centreNor = fetchNor(0,0);
float AORadius = d*AO_RADIUS_MIN + (1.0-d)*AO_RADIUS_MAX;
float AOStep = AORadius / 10;
if( AOStep < 1.0 )
AOStep = 1.0;
for( float i=-AORadius; i<=AORadius; i+=AOStep )
for( float j=-AORadius; j<=AORadius; j+=AOStep )
{
float distToCenter = sqrt( i*i + j*j );
if( distToCenter>=1.0 && distToCenter<=AORadius && fetchDepth(j,i)<1.0 )
{
float weight = 1.0 / distToCenter;
vec3 nor = fetchNor(j,i);
weightSum += weight;
AO += weight * max( dot(centreNor,nor), 0.0 );
}
}
AO /= weightSum;
// AO = 0.5*AO + 0.5;
}
// }
// edgeEnhancement = SmoothAt(0,0);
if( gl_TexCoord[0].x > 0.5 )
gl_FragColor = vec4( (0.5 + 0.5*AO*edgeEnhancement) * texture2D(u_FrameBufferColor,gl_TexCoord[0]).xyz, 1.0 );
else
// gl_FragColor = vec4( (0.5+0.5*edgeEnhancement) * texture2D(u_FrameBufferColor,gl_TexCoord[0]).xyz, 1.0 );
gl_FragColor = vec4( (0.5+0.5*edgeEnhancement) * texture2D(u_FrameBufferColor,gl_TexCoord[0]).xyz, 1.0 );
}
......@@ -73,56 +73,57 @@ float SmoothAt( int x, int y )
void main()
{
const int AO_RADIUS_MIN = 10;
const int AO_RADIUS_MAX = 50;
float AO = 1.0;
// const int AO_RADIUS_MIN = 8;
// const int AO_RADIUS_MAX = 50;
//
// float AO = 1.0;
float edgeEnhancement;
//
//
// // if( gl_TexCoord[0].x > 0.5 )
// // {
edgeEnhancement = 1.0 - SobelAt(0,0);
// // }
// // else
// // {
// edgeEnhancement = SmoothAt(0,0);
//
// float d = fetchDepth(0,0);
// if( d < 1.0 )
// {
// float weightSum = 0.0;
// vec3 centreNor = fetchNor(0,0);
//
//
// float AORadius = d*AO_RADIUS_MIN + (1.0-d)*AO_RADIUS_MAX;
// float AOStep = AORadius / 10;
// if( AOStep < 1.0 )
// AOStep = 1.0;
//
// for( float i=-AORadius; i<=AORadius; i+=AOStep )
// for( float j=-AORadius; j<=AORadius; j+=AOStep )
// {
// float distToCenter = sqrt( i*i + j*j );
// if( distToCenter>=1.0 && distToCenter<=AORadius && fetchDepth(j,i)<1.0 )
// {
// float weight = 1.0 / distToCenter;
// vec3 nor = fetchNor(j,i);
// weightSum += weight;
// AO += weight * max( dot(centreNor,nor), 0.0 );
// }
// }
//
// AO /= weightSum;
// // AO = 0.5*AO + 0.5;
// }
// // }
//
//
//
// // edgeEnhancement = SmoothAt(0,0);
// if( gl_TexCoord[0].x > 0.5 )
// {
// edgeEnhancement = 1.0 - SobelAt(0,0);
// }
// gl_FragColor = vec4( (0.5 + 0.5*AO*edgeEnhancement) * texture2D(u_FrameBufferColor,gl_TexCoord[0]).xyz, 1.0 );
// else
// {
edgeEnhancement = SmoothAt(0,0);
float d = fetchDepth(0,0);
if( d < 1.0 )
{
float weightSum = 0.0;
vec3 centreNor = fetchNor(0,0);
float AORadius = d*AO_RADIUS_MIN + (1.0-d)*AO_RADIUS_MAX;
float AOStep = AORadius / 10;
if( AOStep < 1.0 )
AOStep = 1.0;
for( float i=-AORadius; i<=AORadius; i+=AOStep )
for( float j=-AORadius; j<=AORadius; j+=AOStep )
{
float distToCenter = sqrt( i*i + j*j );
if( distToCenter>=1.0 && distToCenter<=AORadius && fetchDepth(j,i)<1.0 )
{
float weight = 1.0 / distToCenter;
vec3 nor = fetchNor(j,i);
weightSum += weight;
AO += weight * max( dot(centreNor,nor), 0.0 );
}
}
AO /= weightSum;
// AO = 0.5*AO + 0.5;
}
// }
// edgeEnhancement = SmoothAt(0,0);
if( gl_TexCoord[0].x > 0.5 )
gl_FragColor = vec4( (0.5 + 0.5*AO*edgeEnhancement) * texture2D(u_FrameBufferColor,gl_TexCoord[0]).xyz, 1.0 );
else
// gl_FragColor = vec4( (0.5+0.5*edgeEnhancement) * texture2D(u_FrameBufferColor,gl_TexCoord[0]).xyz, 1.0 );
gl_FragColor = vec4( (0.5+0.5*edgeEnhancement) * texture2D(u_FrameBufferColor,gl_TexCoord[0]).xyz, 1.0 );
}
......@@ -13,6 +13,8 @@
#include "Algo/Import/importSvg.h"
#include "Algo/BooleanOperator/mergeVertices.h"
#include "Topology/generic/mapBrowser.h"
#include "env_generator.h"
using namespace CGoGN ;
......@@ -181,7 +183,7 @@ void EnvMap::init(unsigned int config, REAL width, REAL height, REAL minSize, RE
//subdivision to create footpath
MapBrowserSelector mbs(map, SelectorDartNoBoundary<PFP::MAP>(map));
map.setBrowser(mbs);
map.setBrowser(&mbs);
Algo::Surface::Modelisation::TwoNPlusOneSubdivision<PFP,PFP::TVEC3, VEC3>(map,position);
map.setBrowser(NULL);
markPedWay();
......
......@@ -4,24 +4,30 @@
MovingMesh::MovingMesh(EnvMap& envMap, Dart d, std::string filename):
motherMap(envMap.map),
motherPosition(envMap.position),
#ifdef EXPORTING2
m_obj(map),
#endif
constrainedV(map)
{
std::vector<std::string> attrNames ;
if(!Algo::Surface::Import::importMesh<PFP>(map, filename.c_str(), attrNames))
#ifdef EXPORTING2
m_obj.import(filename,attrNames);
#else
if(!Algo::Surface::Import::importMesh<PFP2>(map, filename.c_str(), attrNames))
{
CGoGNerr << "could not import " << filename << CGoGNendl ;
return;
}
normal = map.addAttribute<VEC3, VERTEX>("normal") ;
#endif
position = map.getAttribute<VEC3, VERTEX>(attrNames[0]) ;
normal = map.addAttribute<VEC3, VERTEX>("normal");
float area = Algo::Surface::Geometry::convexFaceArea<PFP>(envMap.map, d, envMap.position);
scaleValue = std::max(area/1400.0f,10.0f);
std::cout << "scaleVal " << scaleValue << std::endl;
// scaleValue = 4.0f;
scale(scaleValue/1.8f);
// scale(2.5f);
// scale(0.5f);
// Geom::Matrix44f m;
// m.identity();
......@@ -31,29 +37,63 @@ constrainedV(map)
VEC3 v = Algo::Surface::Geometry::faceCentroid<PFP>(motherMap, d, motherPosition) ;
translate(v);
// translate(VEC3(0,0,5));
// TraversorV<PFP::MAP> tv(map);
// std::vector<Dart> obstDarts;
// for(Dart dd = tv.begin() ; dd != tv.end() ; dd = tv.next())
// {
// obstDarts.push_back(dd);
// }
//
// smg = new ShapeMatchingQuadratic<PFP>(map,position,obstDarts,0.5f);
// smg->initialize();
map.enableQuickTraversal<VERTEX>();
}
void MovingMesh::initGL()
{
//rendering
m_render = new Algo::Render::GL2::MapRender();
m_positionVBO = new Utils::VBO();
m_normalVBO = new Utils::VBO();
#ifdef EXPORTING2
m_texcoordVBO = new Utils::VBO();
m_texture = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE);
if (m_texture->load("./meshRessources/limace.png"))
m_texture->update();
else
std::cout << "problem : loading texture" << std::endl;
m_texture->setWrapping(GL_CLAMP_TO_EDGE);
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->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));
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);
#else
m_simpleColorShader = new Utils::ShaderSimpleColor();
m_simpleColorShader->setAttributePosition(m_positionVBO);
m_simpleColorShader->setColor(Geom::Vec4f(0.,1.,0.,0.));
m_positionVBO->updateData(position) ;
#endif
m_normalVBO->updateData(normal) ;
}
......@@ -64,7 +104,7 @@ void MovingMesh::linkWithObstacle(MovingObstacle * mo)
void MovingMesh::transform(Geom::Matrix44f m)
{
TraversorV<PFP::MAP> tv(map);
TraversorV<PFP2::MAP> tv(map);
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
{
position[d] = Geom::transform(position[d],m);
......@@ -73,7 +113,7 @@ void MovingMesh::transform(Geom::Matrix44f m)
void MovingMesh::translate(VEC3 v)
{
TraversorV<PFP::MAP> tv(map);
TraversorV<PFP2::MAP> tv(map);
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
{
position[d] += v;
......@@ -82,7 +122,7 @@ void MovingMesh::translate(VEC3 v)
void MovingMesh::scale(float val)
{
TraversorV<PFP::MAP> tv(map);
TraversorV<PFP2::MAP> tv(map);
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
{
position[d] *= val;
......@@ -102,7 +142,7 @@ void MovingMesh::moveInFace(PFP::MAP& motherMap, Dart d, VertexAttribute<VEC3> p
Geom::rotate(axis, -angle, rot) ;
Geom::translate(b[0],b[1],b[2],rot);
TraversorV<PFP::MAP> tv(map);
TraversorV<PFP2::MAP> tv(map);
for(Dart dd = tv.begin() ; dd != tv.end() ; dd = tv.next())
{
position[dd] = Geom::transform(position[dd],rot);
......@@ -124,23 +164,11 @@ void MovingMesh::moveInFace(PFP::MAP& motherMap, Dart d, VertexAttribute<VEC3> p
void MovingMesh::move()
{
std::cout << "move squeleton" << std::endl;
std::cout << "compute deformation with SM-Quad" << std::endl;
std::cout << "apply to mesh" << std::endl;
std::cout << "project bottom points in plane ?" << std::endl;
std::cout << "apply to moving object" << std::endl;
std::cout << "register moving object" << std::endl;
}
void MovingMesh::animate()
{
smg->animate();
// TraversorV<typename PFP::MAP> tv(map);
// for(Dart dd = tv.begin() ; dd != tv.end() ; dd = tv.next())
// {
// if(!constrainedV.isMarked(dd))
// position[dd] = smg->goal[dd];
// }
for(std::vector<Dart>::iterator it = smg->m_darts.begin() ; it != smg->m_darts.end() ; ++it)
{
......@@ -151,20 +179,32 @@ void MovingMesh::animate()
void MovingMesh::draw()
{
#ifdef EXPORTING2
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();
#else
m_positionVBO->updateData(position) ;
m_render->initPrimitives<PFP>(map, Algo::Render::GL2::TRIANGLES) ;
m_render->initPrimitives<PFP>(map, Algo::Render::GL2::LINES) ;
m_render->initPrimitives<PFP2>(map, Algo::Render::GL2::TRIANGLES) ;
m_render->initPrimitives<PFP2>(map, Algo::Render::GL2::LINES) ;
m_simpleColorShader->setColor(Geom::Vec4f(1.0,0.627,0.0,0.));
m_render->draw(m_simpleColorShader, Algo::Render::GL2::TRIANGLES);
m_simpleColorShader->setColor(Geom::Vec4f(0.0,0.0,0.0,0.));
m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES);
// m_simpleColorShader->setColor(Geom::Vec4f(0.0,0.0,0.0,0.));
// m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES);
#endif
}
std::vector<VEC3> MovingMesh::computeProjectedPointSet(float maxHeight)
{
std::vector<VEC3> points;
TraversorV<PFP::MAP> tv(map);
TraversorV<PFP2::MAP> tv(map);
for(Dart dd = tv.begin() ; dd != tv.end() ; dd = tv.next())
{
if(position[dd][2]<maxHeight)
......
......@@ -694,7 +694,7 @@ void resetPartSubdiv(Obstacle* o)
if (mo != NULL)
{
VEC3 pos =mo->registering_part->getPosition();
mo->registering_part->CGoGN::Algo::Surface::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::faceCentroid<PFP>(mo->sim_->envMap_.map, mo->registering_part->d, mo->sim_->envMap_.position)) ;
mo->registering_part->CGoGN::Algo::MovingObjects::ParticleBase<PFP>::move(Algo::Surface::Geometry::faceCentroid<PFP>(mo->sim_->envMap_.map, mo->registering_part->d, mo->sim_->envMap_.position)) ;
mo->registering_part->setState(FACE) ;
mo->registering_part->move(pos) ;
......@@ -914,7 +914,7 @@ void MovingObstacle::attachMesh(MovingMesh* mm)
mvc_ = mm->map.getAttribute<NoMathIONameAttribute<std::vector<PFP::REAL> >, VERTEX>("mvc");
if(!mvc_.isValid())
mvc_ = mm->map.addAttribute<NoMathIONameAttribute<std::vector<PFP::REAL> >, VERTEX>("mvc");
TraversorV<PFP::MAP> t(mm_->map);
TraversorV<PFP2::MAP> t(mm_->map);
for(Dart it = t.begin(); it != t.end(); it = t.next())
computePointMVC(mm->position[it], mvc_[it]);
}
......@@ -928,7 +928,7 @@ void MovingObstacle::updateMesh()
{
if(mm_)
{
TraversorV<PFP::MAP> t(mm_->map);
TraversorV<PFP2::MAP> t(mm_->map);
for(Dart it = t.begin(); it != t.end(); it = t.next())
{
PFP::VEC3 newPos;
......
......@@ -685,7 +685,7 @@ void Simulator::addMovingObstacle(Dart d, unsigned int obstType)
break;
case 1 :
{
mm = new MovingMesh(envMap_, d, "meshRessources/Limace_2.obj");
mm = new MovingMesh(envMap_, d, "./meshRessources/Limace_2.obj");
movingMeshes_.push_back(mm);
vPos = mm->computeProjectedPointSet(maxHeight);
}
......@@ -714,7 +714,7 @@ void Simulator::addMovingObstacle(Dart d, unsigned int obstType)
float angle = get_angle(mid - bary,front - bary);
TraversorV<PFP::MAP> tv(mm->map);
TraversorV<PFP2::MAP> tv(mm->map);
for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
{
mm->position[d] += rotate(mm->position[d], bary, angle);
......
......@@ -297,7 +297,14 @@ void SocialAgents::initRendering()
#endif
for(unsigned int i = 0 ; i < simulator.movingMeshes_.size() ; ++i)
registerShader(simulator.movingMeshes_[i]->m_simpleColorShader);
{
#ifdef EXPORTING2
simulator.movingMeshes_[i]->initGL();
registerShader(simulator.movingMeshes_[i]->m_shaderTex);
#else
// registerShader(simulator.movingMeshes_[i]->m_simpleColorShader);
#endif
}
}
void SocialAgents::updateObstacleVBO()
......
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