Commit 89c9bfac by Philipp Adolf

Add sharp edges to mesh

parent 2d463f33
......@@ -33,18 +33,25 @@ void Mesh::SubdivEntry::updateIndices() {
}
void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices_irregular){
QVector<unsigned int>& Indices_irregular,
QMap<Edge,unsigned int>& sharp_edges){
f->glGenBuffers(1, &VB_handle);
f->glBindBuffer(GL_ARRAY_BUFFER, VB_handle);
f->glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * Vertices.size(), &Vertices[0], GL_STATIC_DRAW);
QVector<unsigned int> patches;
this->init(f, VB_handle, Vertices, Vertices, Indices_irregular, patches,patches);
this->init(f, VB_handle, Vertices, Vertices, Indices_irregular, patches, patches, sharp_edges);
}
void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVector<Vertex>& Vertices, QVector<Vertex>& Vertices_irregular,
QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches,QVector<unsigned int>& Indices_extra){
void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f,
GLuint VB_handle,
QVector<Vertex>& Vertices,
QVector<Vertex>& Vertices_irregular,
QVector<unsigned int>& Indices_irregular,
QVector<unsigned int>& patches,
QVector<unsigned int>& Indices_extra,
QMap<Edge,unsigned int>& sharp_edges){
this->f = f;
this->VB_handle = VB_handle;
......@@ -52,12 +59,14 @@ void Mesh::SubdivEntry::init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVe
indices_irregular = Indices_irregular;
indices_regular = patches;
indices_extra = Indices_extra;
m_sharp_edges = sharp_edges;
qCDebug(log_mesh) << "Vertices" << vertices.length();
qCDebug(log_mesh) << "Vertices Irregular" << Vertices_irregular.length();
qCDebug(log_mesh) << "Indices irregular" << indices_irregular.length();
qCDebug(log_mesh) << "Indices patches" << patches.length();
qCDebug(log_mesh) << "Indices extra" << Indices_extra.length();
qCDebug(log_mesh) << "Sharp Edges " << m_sharp_edges.size();
f->glGenBuffers(1, &VB_handle_irregular);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VB_handle_irregular);
......@@ -90,12 +99,20 @@ Mesh::MeshEntry::MeshEntry()
}
void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices){
QVector<unsigned int>& Indices, bool fakeSharpness){
this->f = f;
buffers.resize(1);
QMap<Edge,unsigned int> sharpEdges;
if (fakeSharpness){
for (int i = 0; i < Indices.size(); i+= 3){
sharpEdges.insert(Edge(Indices[i],Indices[i+1]),2);
sharpEdges.insert(Edge(Indices[i+1],Indices[i+2]),2);
sharpEdges.insert(Edge(Indices[i+2],Indices[i]),2);
}
}
buffers[0].reset(new SubdivEntry);
buffers[0]->init(f,Vertices,Indices);
buffers[0]->init(f,Vertices,Indices, sharpEdges);
//calc AABB
for (int i = 0; i < Vertices.size(); ++i) {
......@@ -110,10 +127,16 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
}
}
void Mesh::MeshEntry::update(GLuint VB_handle, QVector<Vertex>& Vertices,QVector<Vertex>& Vertices_Irregular, QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches,QVector<unsigned int>& Indices_extra) {
void Mesh::MeshEntry::update(GLuint VB_handle,
QVector<Vertex>& Vertices,
QVector<Vertex>& Vertices_Irregular,
QVector<unsigned int>& Indices_irregular,
QMap<Edge,unsigned int>& sharp_edges,
QVector<unsigned int>& patches,
QVector<unsigned int>& Indices_extra) {
SubdivEntry *entry = new SubdivEntry;
buffers.push_back(std::shared_ptr<SubdivEntry>(entry));
entry->init(f, VB_handle, Vertices, Vertices_Irregular,Indices_irregular,patches, Indices_extra);
entry->init(f, VB_handle, Vertices, Vertices_Irregular, Indices_irregular, patches, Indices_extra, sharp_edges);
}
Mesh::MeshEntry::~MeshEntry()
......@@ -261,7 +284,7 @@ Mesh::Mesh(QOpenGLFunctions_4_3_Core *f, Mesh *mesh, QVector<Vertex> &vertex_buf
entries.resize(1);
entries[0].name = mesh->entries[0].name;
entries[0].materialIndex = mesh->entries[0].materialIndex;
entries[0].init(f, vertex_buffer, index_buffer);
entries[0].init(f, vertex_buffer, index_buffer, false);
rootNode.name = mesh->rootNode.name;
rootNode.transformation = mesh->rootNode.transformation;
......@@ -402,7 +425,7 @@ void Mesh::initMeshEntry(int index, aiMesh * entry) {
qCDebug(log_mesh) << "Loaded Mesh:" << entries[index].name << "HasBones:" << entry->HasBones();
entries[index].init(f,Vertices, Indices);
entries[index].init(f,Vertices, Indices, true);
}
void Mesh::render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P, int subdivision, bool regular){
......
......@@ -28,6 +28,8 @@ public:
const aiScene *scene;
bool debug = true;
struct SubdivEntry{
SubdivEntry();
~SubdivEntry();
......@@ -44,13 +46,15 @@ public:
QVector<unsigned int> indices_irregular;
QVector<unsigned int> indices_regular;
QVector<unsigned int> indices_extra;
QMap<Edge,unsigned int> m_sharp_edges;
QOpenGLFunctions_4_3_Core *f;
void init(QOpenGLFunctions_4_3_Core *f, QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices_irregular);
QVector<unsigned int>& Indices_irregular, QMap<Edge,unsigned int>& sharp_edges);
void init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVector<Vertex>& Vertices, QVector<Vertex>& Vertices_irregular,
QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches,QVector<unsigned int>& Indices_extra);
QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches,QVector<unsigned int>& Indices_extra,
QMap<Edge,unsigned int>& sharp_edges);
void updateIndices();
};
......@@ -58,8 +62,17 @@ public:
MeshEntry();
~MeshEntry();
void init(QOpenGLFunctions_4_3_Core *f, QVector<Vertex>& Vertices, QVector<unsigned int>& Indices);
void update(GLuint VB_handle, QVector<Vertex>& Vertices, QVector<Vertex>& Vertices_Irregular, QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches,QVector<unsigned int>& Indices_extra);
void init(QOpenGLFunctions_4_3_Core *f,
QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices,
bool fakeSharpness = false);
void update(GLuint VB_handle,
QVector<Vertex>& Vertices,
QVector<Vertex>& Vertices_Irregular,
QVector<unsigned int>& Indices_irregular,
QMap<Edge,unsigned int>& sharp_edges,
QVector<unsigned int>& patches,
QVector<unsigned int>& Indices_extra);
QString name;
......
......@@ -119,7 +119,8 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
getPatchIndexBuffer(regular, neighbors, patches);
qCDebug(log_subdiv) << "patches" << patches.length();
current_mesh->update(result.vb_handle, result.vertex_buffer, result.vertex_buffer_irregular, irregular_ib, patches,tables.extra_triangles);
QMap<Edge, unsigned int> sharpEdges;
current_mesh->update(result.vb_handle, result.vertex_buffer, result.vertex_buffer_irregular, irregular_ib, sharpEdges, patches,tables.extra_triangles);
qCDebug(log_timing) << "subdivide done:" << formatTimeMeasurement(timer.elapsed());
}
......
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