Commit 09221660 authored by Jan Möbius's avatar Jan Möbius
Browse files

Fix for face colors on wrong faces by Christopher.

Tested by Isaak and Jan

closes #2028

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@18273 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 1c1d1e24
......@@ -564,7 +564,7 @@ DrawMeshT<Mesh>::rebuild()
if (hh.is_valid())
{
vertices_[i].vcol = getVertexColor(mesh_.to_vertex_handle(hh));
vertices_[i].fcol = getFaceColor(mesh_.face_handle(hh));
vertices_[i].fcol = 0;
}
else
{
......@@ -576,6 +576,25 @@ DrawMeshT<Mesh>::rebuild()
}
}
// copy face colors to provoking id
for (int i = 0; i < (int)numTris_; ++i)
{
const int provokingId = meshComp_->getProvokingVertex();
assert(provokingId >= 0 && provokingId < 3);
int idx = meshComp_->getIndex(i*3+provokingId);
int faceId = meshComp_->mapToOriginalFaceID(i);
unsigned int fcolor = getFaceColor(mesh_.face_handle(faceId));
// debug check
assert(vertices_[idx].fcol == 0 || vertices_[idx].fcol == fcolor);
vertices_[idx].fcol = fcolor;
}
//////////////////////////////////////////////////////////////////////////
// copy to GPU
......
......@@ -174,6 +174,9 @@ public:
*/
GLuint getIBO();
/** \brief get mesh compiler used to create the draw mesh
*/
MeshCompiler* getMeshCompiler() {return meshComp_;}
/** \brief get vertex declaration used for per-vertex color rendering
*/
......
......@@ -3202,6 +3202,56 @@ int MeshCompiler::getAdjVertexFace( int _vertexID, int _k ) const
return adjacencyVert_.num ? adjacencyVert_.getAdj(_vertexID, _k) : faceInput_->getVertexAdjFace(_vertexID, _k);
}
bool MeshCompiler::isTriangleMesh() const
{
return maxFaceSize_ == 3;
}
bool MeshCompiler::isFaceEdge( const int _triID, const int _edge ) const
{
assert(_edge >= 0);
assert(_edge < 3);
if (maxFaceSize_ <= 3) return true;
// brute force: search for triangle edge in input face
const int faceID = mapToOriginalFaceID(_triID);
const int fsize = getFaceSize(faceID);
// get all draw vertices of face
std::vector<int> FaceVerts(fsize);
for (int i = 0; i < fsize; ++i)
FaceVerts[i] = mapToDrawVertexID(faceID, i);
int edgeStart = -1;
int edgeEnd = -1;
switch (_edge)
{
case 0: edgeStart = 0; edgeEnd = 1; break;
case 1: edgeStart = 1; edgeEnd = 2; break;
case 2: edgeStart = 2; edgeEnd = 0; break;
default: break;
}
// access index buffer of triangle
edgeStart = getIndex(_triID * 3 + edgeStart);
edgeEnd = getIndex(_triID * 3 + edgeEnd);
// search for edge in face vertices
for (int e = 0; e < fsize; ++e)
{
if (FaceVerts[e] == edgeStart && FaceVerts[(e+1)%fsize] == edgeEnd)
return true;
if (FaceVerts[e] == edgeEnd && FaceVerts[(e+1)%fsize] == edgeStart)
return true;
}
return false;
}
void MeshCompilerDefaultFaceInput::dbgWriteToObjFile(FILE* _file, int _posAttrID, int _normalAttrID, int _texcAttrID)
{
for (int i = 0; i < numFaces_; ++i)
......
......@@ -467,6 +467,12 @@ public:
*/
void setProvokingVertex(int _v);
/** See glProvokingVertex()
*
* @return provoking vertex id
*/
int getProvokingVertex() const {return provokingVertex_;}
/** \brief Get vertex buffer ready for rendering.
*
......@@ -562,6 +568,27 @@ public:
/** @} */
//===========================================================================
/** @name Triangulation properties
* @{ */
//===========================================================================
/** Test if the input mesh consists of triangles only.
*/
bool isTriangleMesh() const;
/** Test if a triangle edge is a face edge from the input buffer.
*
* When a convex n-poly is subdivided into (n-2) triangles, new edges are created which do not exist in the input mesh.
* This function identifies if an edge was already existant in the input mesh or added during triangulation.
* @param _triID triangle ID in draw buffer
* @param _edge edge of triangle, edge ordering: v0-v1, v1-v2, v2-v0
* @return true if the edge is an edge from an input face, false otherwise
*/
bool isFaceEdge(const int _triID, const int _edge) const;
/** @} */
......
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