Commit 5858c94b by Philipp Adolf

Add hacky way of creating a new Mesh object

parent f5b67cfe
...@@ -177,6 +177,50 @@ Mesh::Mesh(QOpenGLFunctions_4_3_Core *f,QString fileName) ...@@ -177,6 +177,50 @@ Mesh::Mesh(QOpenGLFunctions_4_3_Core *f,QString fileName)
} }
} }
Mesh::Mesh(QOpenGLFunctions_4_3_Core *f, Mesh *mesh, QVector<Vertex> &vertex_buffer, QVector<GLuint> &index_buffer)
{
loaded = false;
this->f = mesh->f;
scene = mesh->scene;
//Init Materials
for (int i = 0; i < mesh->materials.size(); i++) {
materials.push_back(mesh->materials[i]);
}
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);
rootNode.name = mesh->rootNode.name;
rootNode.transformation = mesh->rootNode.transformation;
rootNode.meshes.resize(1);
rootNode.meshes[0] = 0;
globalInverseTransform = rootNode.transformation.inverted();
double amax = std::numeric_limits<float>::max();
QVector3D min = QVector3D(amax,amax,amax);
QVector3D max = QVector3D(-amax,-amax,-amax);
findObjectDimension(rootNode,QMatrix4x4(),min,max);
qDebug()<<"AABB"<<min<<max;
float dist = qMax(max.x() - min.x(), qMax(max.y()-min.y(), max.z() - min.z()));
float sc = 100.0/dist;
QVector3D center = (max - min)/2;
QVector3D trans = -(max - center);
// Apply the scale and translation to a matrix
screenTransform.setToIdentity();
screenTransform.scale(sc);
screenTransform.translate(trans);
loaded = true;
}
Mesh::~Mesh() Mesh::~Mesh()
{ {
entries.clear(); entries.clear();
......
...@@ -48,6 +48,7 @@ class Mesh ...@@ -48,6 +48,7 @@ class Mesh
{ {
public: public:
Mesh(QOpenGLFunctions_4_3_Core *f,QString filename); Mesh(QOpenGLFunctions_4_3_Core *f,QString filename);
Mesh(QOpenGLFunctions_4_3_Core *f, Mesh *mesh, QVector<Vertex> &vertex_buffer, QVector<GLuint> &index_buffer);
~Mesh(); ~Mesh();
void render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P); void render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P);
......
...@@ -58,7 +58,7 @@ Mesh *Subdivision::subdivide(Mesh *mesh) { ...@@ -58,7 +58,7 @@ Mesh *Subdivision::subdivide(Mesh *mesh) {
Tables tables = precomputeTables(input); Tables tables = precomputeTables(input);
Result result = runShader(input, tables); Result result = runShader(input, tables);
return NULL; return new Mesh(f, mesh, result.vertex_buffer, tables.index_buffer);
} }
/** /**
......
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