Commit abf7bef2 by Alisa Jung

started precomputation of subdiv table

parent 0c6f77a7
......@@ -107,7 +107,8 @@ void MainWidget::initializeGL(){
// Shader
subdevisionShader = initShaderProgram();
loadNewMesh( "../Models/demon_head.3ds");
//loadNewMesh( "../Models/demon_head.3ds");
loadNewMesh( "../Models/box.obj");
}
void MainWidget::loadNewMesh(){
......
......@@ -5,8 +5,8 @@ Mesh::MeshEntry::MeshEntry()
{
materialIndex = 0xFFFFFFFF;
numIndex = 0;
VB = 0xFFFFFFFF;
IB = 0xFFFFFFFF;
VB_handle = 0xFFFFFFFF;
IB_handle = 0xFFFFFFFF;
double amax = std::numeric_limits<float>::max();
min = QVector3D(amax,amax,amax);
max = QVector3D(-amax,-amax,-amax);
......@@ -17,14 +17,17 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
this->f = f;
numIndex = Indices.size();
f->glGenBuffers(1, &VB);
f->glBindBuffer(GL_ARRAY_BUFFER, VB);
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);
f->glGenBuffers(1, &IB);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IB);
f->glGenBuffers(1, &IB_handle);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IB_handle);
f->glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * numIndex, &Indices[0], GL_STATIC_DRAW);
indices = Indices;
vertices = Vertices;
//calc AABB
for (int i = 0; i < Vertices.size(); ++i) {
Vertex v = Vertices[i];
......@@ -40,8 +43,8 @@ void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertice
Mesh::MeshEntry::~MeshEntry()
{
f->glDeleteBuffers(1, &VB);
f->glDeleteBuffers(1, &IB);
f->glDeleteBuffers(1, &VB_handle);
f->glDeleteBuffers(1, &IB_handle);
}
Mesh::MaterialInfo::MaterialInfo()
......@@ -62,6 +65,19 @@ Mesh::Node::Node()
children.clear();
}
bool Mesh::Node::getFirstMeshIndex(int &index){
if (meshes.length()>0){
index = meshes[0];
return true;
}
for (int i = 0; i < children.length(); i++){
if (children[i].getFirstMeshIndex(index)){
return true;
}
}
return false;
}
Mesh::Mesh(QOpenGLFunctions_4_3_Core *f,QString fileName)
{
loaded = false;
......@@ -161,12 +177,23 @@ Mesh::~Mesh()
materials.clear();
}
Mesh::Node Mesh::getRootNode(){
return rootNode;
}
Mesh::MeshEntry Mesh::getMeshEntry(int index){
return entries[index];
}
QVector<unsigned int> Mesh::MeshEntry::getIndexBuffer(){
return indices;
}
void Mesh::initNode(const aiScene *scene, aiNode *node, Node &newNode,QString debugoffset){
newNode.name = node->mName.length != 0 ? node->mName.C_Str() : "";
newNode.transformation = QMatrix4x4(node->mTransformation[0]);
newNode.meshes.resize(node->mNumMeshes);
bool debug = false;
if(debug) qDebug()<<debugoffset.toStdString().c_str() << "NodeName" << newNode.name;
if(debug) qDebug()<<debugoffset.toStdString().c_str() << " NumMeshes" << newNode.meshes.size();
......@@ -331,12 +358,12 @@ void Mesh::renderMesh(QOpenGLShaderProgram *shader, int index)
// Draw Vertex Array
f->glBindBuffer(GL_ARRAY_BUFFER, entries[index].VB);
f->glBindBuffer(GL_ARRAY_BUFFER, entries[index].VB_handle);
f->glVertexAttribPointer(positionIndex, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
f->glVertexAttribPointer(normalIndex, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)12); //12
f->glVertexAttribPointer(uvIndex, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)24); // 12+12
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, entries[index].IB);
f->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, entries[index].IB_handle);
f->glPatchParameteri(GL_PATCH_VERTICES, 3);
f->glDrawElements(GL_PATCHES, entries[index].numIndex, GL_UNSIGNED_INT, 0);
......
......@@ -38,19 +38,22 @@ public:
void render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P);
const aiScene *scene;
private:
bool debug = true;
struct MeshEntry{
MeshEntry();
~MeshEntry();
QVector<unsigned int> getIndexBuffer();
void init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices);
QString name;
GLuint VB;
GLuint IB;
GLuint VB_handle;
GLuint IB_handle;
QVector<unsigned int> indices;
QVector<Vertex> vertices;
int numIndex;
int materialIndex;
......@@ -78,9 +81,17 @@ private:
QMatrix4x4 transformation;
QVector<int> meshes;
QVector<Node> children;
bool getFirstMeshIndex(int& index);//false if no mesh entry found
};
Mesh::Node getRootNode();
Mesh::MeshEntry getMeshEntry(int index);
private:
Assimp::Importer importer;
QMatrix4x4 globalInverseTransform;
QMatrix4x4 screenTransform;
......
......@@ -16,6 +16,54 @@ Mesh *Subdivision::subdivide(Mesh *mesh) {
}
void Subdivision::precomputeTables(Mesh *mesh) {
Mesh::Node root = mesh->getRootNode();
int firstMeshEntryIndex = -1;
bool meshExists = root.getFirstMeshIndex(firstMeshEntryIndex);
if (!meshExists){
qDebug()<<"No Mesh found. Abort subdiv table precomputation.";
return;
}
qDebug()<<"Mesh found. Index:"<<firstMeshEntryIndex;
//die drei zeilen machen das bild schwarz. wenn man davor returnt tuts.
Mesh::MeshEntry firstMeshEntry = mesh->getMeshEntry(firstMeshEntryIndex);
QVector<unsigned int> ib = firstMeshEntry.getIndexBuffer();
qDebug()<<"Index Buffer: "<<ib;
return;
//todo find adjacent triangles:
/*
for (int i = 0; i < ib.length(); i+=3){
//schaue alle dreiecke an
unsigned int x, y, z;
x_index = ib[i];
y_index = ib[i+1];
z_index = ib[i+2];
//get vertices x,y,z from vertex buffer
for (int j = i+3; j < ib.length(); j+= 3){
//search all following triangles for common edge
a_index = ib[j];
b_index = ib[j+1];
c_index = in[j+2];
//get vertices for a,b,c from vertex buffer
//for xy
//for yz
//for zx
}
}
*
* */
}
void Subdivision::runShader(Mesh *mesh) {
......
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