debugged procedural meshes

This commit is contained in:
Anselme 2016-04-29 12:03:59 +02:00
parent 1ffba313fe
commit 2b191afd9f
3 changed files with 17 additions and 16 deletions

View File

@ -257,9 +257,9 @@ struct VertexComparator
return (mesh->positions3D[vertId1].z < mesh->positions3D[vertId2].z);
if(!mesh->texCoords.empty())
{
if(mesh->texCoords[vertId1].x != mesh->texCoords[vertId2].x)
if(mesh->texCoords[vertId1].x - floor(mesh->texCoords[vertId1].x) != mesh->texCoords[vertId2].x - floor(mesh->texCoords[vertId2].x))
return (mesh->texCoords[vertId1].x < mesh->texCoords[vertId2].x);
if(mesh->texCoords[vertId1].y != mesh->texCoords[vertId2].y)
if(mesh->texCoords[vertId1].y - floor(mesh->texCoords[vertId1].y) != mesh->texCoords[vertId2].y - floor(mesh->texCoords[vertId2].y))
return (mesh->texCoords[vertId1].y < mesh->texCoords[vertId2].y);
}
if(!mesh->normals.empty())

View File

@ -67,12 +67,12 @@ Mesh* MeshGenerator::generateGeodesicMesh(Material* mat, int n, float size)
int bottom = 7;
int offset = (i+1)%5;
// top cap
m_mesh->addTriangle(0, top+i, top+offset);
m_mesh->addTriangle(0, top+offset, top+i);
// bottom cap
m_mesh->addTriangle(6, bottom+offset, bottom+i);
m_mesh->addTriangle(6, bottom+i, bottom+offset);
// middle ribbon
m_mesh->addTriangle(top+i, bottom+i, top+offset);
m_mesh->addTriangle(top+offset, bottom+i, bottom+offset);
m_mesh->addTriangle(top+i, top+offset, bottom+i);
m_mesh->addTriangle(top+offset, bottom+offset, bottom+i);
}
// geodesic subdivisions :
@ -99,15 +99,16 @@ int MeshGenerator::getEdge(int a, int b)
{
vid = m_mesh->positions3D.size();
// creating subdivision vertex
glm::vec3 pos = glm::normalize(m_mesh->positions3D[a] + m_mesh->positions3D[b] / 2.f);
// u/v sphériques, cohérents sur toute la sphère sauf des artefacts au niveau des u==0
glm::vec3 pos = glm::normalize((m_mesh->positions3D[a] + m_mesh->positions3D[b]) / 2.f);
float newU = (pos.x < 0 ? 1.5f : 1.f) + atan(pos.z/pos.x)/(2*M_PI);
float newV = acos(pos.y)/M_PI;
createVertex(newU - floor(newU), newV);
// alternative, u/v moyennés :
//v.texCoord = (v0.texCoord + v1.texCoord)/2.f;
/*float newU = (m_mesh->texCoords[a].x + m_mesh->texCoords[b].x) / 2.f;
float newV = (m_mesh->texCoords[a].y + m_mesh->texCoords[b].y) / 2.f;*/
createVertex(-(newU - floor(newU)), newV);
// inserting the new vertex in the edge collection
if(current->b == -1)
{

View File

@ -55,7 +55,7 @@ class GridGenerator : public MeshGenerator
{
public:
virtual glm::vec3 evalUV(float u, float v)
{return glm::vec3(u-0.5f, 0, v-0.5f);}
{return glm::vec3(u*2-1, 0, v*2-1);}
};
/**
@ -65,17 +65,17 @@ class CylinderGenerator : public MeshGenerator
{
public:
virtual glm::vec3 evalUV(float u, float v)
{return glm::vec3(cos(u*6.2832f), v-0.5f, sin(u*6.2832f));}
{return glm::vec3(cos(u*6.2832f), v*2-1, sin(u*6.2832f));}
};
/**
* @brief The ConeGenerator class creates an open cone pointing down
* @brief The ConeGenerator class creates an open cone pointing up
*/
class ConeGenerator : public MeshGenerator
{
public:
virtual glm::vec3 evalUV(float u, float v)
{return glm::vec3(cos(u*6.2832f)*v, v, sin(u*6.2832f)*v);}
{return glm::vec3(cos(-u*6.2832f)*v, 1 - v*2, sin(-u*6.2832f)*v);}
};
/**
@ -88,7 +88,7 @@ public:
virtual glm::vec3 evalUV(float u, float v)
{
float r = sin(v*3.1416f);
return glm::vec3(cos(u*6.2832f)*r, cos(v*3.1416f), sin(u*6.2832f)*r);
return glm::vec3(cos(-u*6.2832f)*r, cos(v*3.1416f), sin(-u*6.2832f)*r);
}
};