void GLMesh::fillBuffers(const std::vector<Eigen::Vector3f>& colors) { vertices.resize(3*(mesh.faces.size() - mesh.boundaries.size())); for (FaceCIter f = mesh.faces.begin(); f != mesh.faces.end(); f++) { if (!f->isBoundary()) { int i = 0; int fIdx = 3*f->index; HalfEdgeCIter h = f->he; do { VertexCIter v = h->vertex; // set vertex vertices[fIdx+i].position = v->position.cast<float>(); vertices[fIdx+i].normal = v->normal().cast<float>(); vertices[fIdx+i].color = colors[f->index]; vertices[fIdx+i].uv = v->uv.cast<float>(); i++; h = h->next; } while (h != f->he); // set barycenters vertices[fIdx+0].barycenter = Eigen::Vector3f(1.0, 0.0, 0.0); vertices[fIdx+1].barycenter = Eigen::Vector3f(0.0, 1.0, 0.0); vertices[fIdx+2].barycenter = Eigen::Vector3f(0.0, 0.0, 1.0); } } }
void GLMesh::fillPickBuffers() { int tris = (int)(mesh.faces.size() - mesh.boundaries.size()); // add faces int i = 0; pickVertices.resize(3*tris); for (FaceCIter f = mesh.faces.begin(); f != mesh.faces.end(); f++) { if (!f->isBoundary()) { int j = 0; Eigen::Vector3f color = elementColor(f->index); HalfEdgeCIter h = f->he; do { // set vertex pickVertices[3*i+j].position = h->vertex->position.cast<float>(); pickVertices[3*i+j].color = color; j++; h = h->next; } while (h != f->he); i++; } } // add vertex faces int verts = 0; for (VertexCIter v = mesh.vertices.begin(); v != mesh.vertices.end(); v++) { verts += v->degree(); if (v->isBoundary()) verts -= 1; } pickVertices.resize(3*(tris + verts)); for (VertexCIter v = mesh.vertices.begin(); v != mesh.vertices.end(); v++) { Eigen::Vector3d n = 0.0015*v->normal(); Eigen::Vector3f p1 = (v->position + n).cast<float>(); Eigen::Vector3f color = elementColor(tris + v->index); HalfEdgeCIter h = v->he; do { if (!h->onBoundary) { Eigen::Vector3f p2 = (h->next->vertex->position + n).cast<float>(); Eigen::Vector3f p3 = (h->next->next->vertex->position + n).cast<float>(); pickVertices[3*i+0].position = p1; pickVertices[3*i+1].position = p1 + 0.125*(p2 - p1); pickVertices[3*i+2].position = p1 + 0.125*(p3 - p1); pickVertices[3*i+0].color = pickVertices[3*i+1].color = pickVertices[3*i+2].color = color; i++; } h = h->flip->next; } while (h != v->he); } }