Commit 277bebb3 by Philipp Adolf

Formatting fixes for mesh.{cpp,h}

parent 84a57269
...@@ -76,8 +76,6 @@ Mesh::MeshEntry::MeshEntry() ...@@ -76,8 +76,6 @@ Mesh::MeshEntry::MeshEntry()
max = QVector3D(-amax,-amax,-amax); max = QVector3D(-amax,-amax,-amax);
} }
void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertices, void Mesh::MeshEntry::init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices){ QVector<unsigned int>& Indices){
this->f = f; this->f = f;
...@@ -293,7 +291,6 @@ Mesh::MeshEntry *Mesh::getMeshEntry(int index){ ...@@ -293,7 +291,6 @@ Mesh::MeshEntry *Mesh::getMeshEntry(int index){
return &entries[index]; return &entries[index];
} }
void Mesh::initNode(const aiScene *scene, aiNode *node, Node &newNode,QString debugoffset){ void Mesh::initNode(const aiScene *scene, aiNode *node, Node &newNode,QString debugoffset){
newNode.name = node->mName.length != 0 ? node->mName.C_Str() : ""; newNode.name = node->mName.length != 0 ? node->mName.C_Str() : "";
newNode.transformation = QMatrix4x4(node->mTransformation[0]); newNode.transformation = QMatrix4x4(node->mTransformation[0]);
...@@ -315,7 +312,6 @@ void Mesh::initNode(const aiScene *scene, aiNode *node, Node &newNode,QString de ...@@ -315,7 +312,6 @@ void Mesh::initNode(const aiScene *scene, aiNode *node, Node &newNode,QString de
newNode.children.push_back(Node()); newNode.children.push_back(Node());
initNode(scene, node->mChildren[i], newNode.children[i],newDebug); initNode(scene, node->mChildren[i], newNode.children[i],newDebug);
} }
} }
void Mesh::initMaterial(QString dir, unsigned int i, const aiMaterial* material) void Mesh::initMaterial(QString dir, unsigned int i, const aiMaterial* material)
...@@ -341,10 +337,8 @@ void Mesh::initMaterial(QString dir, unsigned int i, const aiMaterial* material) ...@@ -341,10 +337,8 @@ void Mesh::initMaterial(QString dir, unsigned int i, const aiMaterial* material)
if (materials[i].Shininess == 0.0){ if (materials[i].Shininess == 0.0){
materials[i].Shininess = 2; materials[i].Shininess = 2;
} }
if (material->GetTextureCount(aiTextureType_DIFFUSE) > 0) { if (material->GetTextureCount(aiTextureType_DIFFUSE) > 0) {
aiString Path; aiString Path;
...@@ -359,18 +353,16 @@ void Mesh::initMaterial(QString dir, unsigned int i, const aiMaterial* material) ...@@ -359,18 +353,16 @@ void Mesh::initMaterial(QString dir, unsigned int i, const aiMaterial* material)
qDebug()<<"Warning No Texture"; qDebug()<<"Warning No Texture";
materials[i].hasTexture = false; materials[i].hasTexture = false;
} }
} }
} }
void Mesh::initMeshEntry(int index, aiMesh * entry){ void Mesh::initMeshEntry(int index, aiMesh * entry) {
QVector<Vertex> Vertices; QVector<Vertex> Vertices;
QVector<unsigned int> Indices; QVector<unsigned int> Indices;
const aiVector3D Zero3D(0.0f, 0.0f, 0.0f); const aiVector3D Zero3D(0.0f, 0.0f, 0.0f);
for (unsigned int i = 0 ; i < entry->mNumVertices ; i++) { for (unsigned int i = 0; i < entry->mNumVertices; i++) {
const aiVector3D* pPos = &(entry->mVertices[i]); const aiVector3D* pPos = &(entry->mVertices[i]);
const aiVector3D* pNormal = &(entry->mNormals[i]); const aiVector3D* pNormal = &(entry->mNormals[i]);
const aiVector3D* pTexCoord = entry->HasTextureCoords(0) ? &(entry->mTextureCoords[0][i]) : &Zero3D; const aiVector3D* pTexCoord = entry->HasTextureCoords(0) ? &(entry->mTextureCoords[0][i]) : &Zero3D;
...@@ -384,7 +376,7 @@ void Mesh::initMeshEntry(int index, aiMesh * entry){ ...@@ -384,7 +376,7 @@ void Mesh::initMeshEntry(int index, aiMesh * entry){
Vertices.push_back(v); Vertices.push_back(v);
} }
for (unsigned int i = 0 ; i < entry->mNumFaces ; i++) { for (unsigned int i = 0; i < entry->mNumFaces; i++) {
const aiFace& face = entry->mFaces[i]; const aiFace& face = entry->mFaces[i];
assert(face.mNumIndices == 3); assert(face.mNumIndices == 3);
Indices.push_back(face.mIndices[0]); Indices.push_back(face.mIndices[0]);
...@@ -392,14 +384,12 @@ void Mesh::initMeshEntry(int index, aiMesh * entry){ ...@@ -392,14 +384,12 @@ void Mesh::initMeshEntry(int index, aiMesh * entry){
Indices.push_back(face.mIndices[2]); Indices.push_back(face.mIndices[2]);
} }
entries[index].name = entry->mName.length != 0 ? entry->mName.C_Str() : ""; entries[index].name = entry->mName.length != 0 ? entry->mName.C_Str() : "";
entries[index].materialIndex = entry->mMaterialIndex; entries[index].materialIndex = entry->mMaterialIndex;
qDebug()<<"Loaded Mesh:"<<entries[index].name<<"HasBones:"<<entry->HasBones(); qDebug()<<"Loaded Mesh:"<<entries[index].name<<"HasBones:"<<entry->HasBones();
entries[index].init(f,Vertices, Indices); entries[index].init(f,Vertices, Indices);
} }
void Mesh::render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P, int subdivision, bool regular){ void Mesh::render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P, int subdivision, bool regular){
...@@ -419,9 +409,6 @@ void Mesh::render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P, int s ...@@ -419,9 +409,6 @@ void Mesh::render(QOpenGLShaderProgram *shader, QMatrix4x4 V,QMatrix4x4 P, int s
f->glDisableVertexAttribArray(positionIndex); f->glDisableVertexAttribArray(positionIndex);
f->glDisableVertexAttribArray(normalIndex); f->glDisableVertexAttribArray(normalIndex);
f->glDisableVertexAttribArray(uvIndex); f->glDisableVertexAttribArray(uvIndex);
} }
void Mesh::renderNode(QOpenGLShaderProgram *shader, Node &node, QMatrix4x4 V,QMatrix4x4 P,QMatrix4x4 M, int subdivision, bool regular){ void Mesh::renderNode(QOpenGLShaderProgram *shader, Node &node, QMatrix4x4 V,QMatrix4x4 P,QMatrix4x4 M, int subdivision, bool regular){
...@@ -498,7 +485,6 @@ void Mesh::findObjectDimension(Node node, QMatrix4x4 transform, QVector3D &min, ...@@ -498,7 +485,6 @@ void Mesh::findObjectDimension(Node node, QMatrix4x4 transform, QVector3D &min,
transform *= node.transformation; transform *= node.transformation;
for (int i = 0; i < node.meshes.size(); i++) { for (int i = 0; i < node.meshes.size(); i++) {
QVector4D temp = transform*QVector4D(entries[node.meshes[i]].min,1.0); QVector4D temp = transform*QVector4D(entries[node.meshes[i]].min,1.0);
min.setX(qMin(min.x(),temp.x())); min.setX(qMin(min.x(),temp.x()));
min.setY(qMin(min.y(),temp.y())); min.setY(qMin(min.y(),temp.y()));
...@@ -520,6 +506,3 @@ void Mesh::findObjectDimension(Node node, QMatrix4x4 transform, QVector3D &min, ...@@ -520,6 +506,3 @@ void Mesh::findObjectDimension(Node node, QMatrix4x4 transform, QVector3D &min,
findObjectDimension(node.children[i], transform, min, max); findObjectDimension(node.children[i], transform, min, max);
} }
} }
...@@ -46,16 +46,15 @@ QDebug operator<< (QDebug d, const Vertex &v); ...@@ -46,16 +46,15 @@ QDebug operator<< (QDebug d, const Vertex &v);
class Mesh 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(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, int subdivision, bool regular); void render(QOpenGLShaderProgram *shader, QMatrix4x4 V, QMatrix4x4 P, int subdivision, bool regular);
const aiScene *scene; const aiScene *scene;
bool debug = true; bool debug = true;
struct SubdivEntry{ struct SubdivEntry{
SubdivEntry(); SubdivEntry();
~SubdivEntry(); ~SubdivEntry();
GLuint VB_handle; GLuint VB_handle;
...@@ -69,9 +68,9 @@ public: ...@@ -69,9 +68,9 @@ public:
QOpenGLFunctions_4_3_Core *f; QOpenGLFunctions_4_3_Core *f;
void init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertices, void init(QOpenGLFunctions_4_3_Core *f, QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices_irregular); QVector<unsigned int>& Indices_irregular);
void init(QOpenGLFunctions_4_3_Core *f,GLuint VB_handle,QVector<Vertex>& Vertices, void init(QOpenGLFunctions_4_3_Core *f, GLuint VB_handle, QVector<Vertex>& Vertices,
QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches); QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches);
void updateIndices(); void updateIndices();
}; };
...@@ -80,9 +79,7 @@ public: ...@@ -80,9 +79,7 @@ public:
MeshEntry(); MeshEntry();
~MeshEntry(); ~MeshEntry();
void init(QOpenGLFunctions_4_3_Core *f,QVector<Vertex>& Vertices, void init(QOpenGLFunctions_4_3_Core *f, QVector<Vertex>& Vertices, QVector<unsigned int>& Indices);
QVector<unsigned int>& Indices);
void update(GLuint VB_handle, QVector<Vertex>& Vertices, QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches); void update(GLuint VB_handle, QVector<Vertex>& Vertices, QVector<unsigned int>& Indices_irregular, QVector<unsigned int>& patches);
QString name; QString name;
...@@ -117,15 +114,12 @@ public: ...@@ -117,15 +114,12 @@ public:
QVector<Node> children; QVector<Node> children;
bool getFirstMeshIndex(int& index);//false if no mesh entry found bool getFirstMeshIndex(int& index);//false if no mesh entry found
}; };
Mesh::Node getRootNode(); Mesh::Node getRootNode();
Mesh::MeshEntry *getMeshEntry(int index); Mesh::MeshEntry *getMeshEntry(int index);
private: private:
Assimp::Importer importer; Assimp::Importer importer;
QMatrix4x4 globalInverseTransform; QMatrix4x4 globalInverseTransform;
QMatrix4x4 screenTransform; QMatrix4x4 screenTransform;
...@@ -137,17 +131,14 @@ private: ...@@ -137,17 +131,14 @@ private:
QOpenGLFunctions_4_3_Core *f; QOpenGLFunctions_4_3_Core *f;
bool loaded; bool loaded;
void initMeshEntry(int i,aiMesh * entry); void initMeshEntry(int i, aiMesh * entry);
void initMaterial(QString dir, unsigned int i, const aiMaterial* material); void initMaterial(QString dir, unsigned int i, const aiMaterial* material);
void initNode(const aiScene *scene, aiNode *node, Node &newNode, QString debugoffset); void initNode(const aiScene *scene, aiNode *node, Node &newNode, QString debugoffset);
void renderNode(QOpenGLShaderProgram *shader, Node &node, QMatrix4x4 V, QMatrix4x4 P, QMatrix4x4 M, int subdivision, bool regular);
void renderNode(QOpenGLShaderProgram *shader, Node &node, QMatrix4x4 V,QMatrix4x4 P,QMatrix4x4 M, int subdivision, bool regular);
void renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision, bool regular); void renderMesh(QOpenGLShaderProgram *shader, int index, int subdivision, bool regular);
void findObjectDimension(Node node, QMatrix4x4 transform, QVector3D &min, QVector3D &max); void findObjectDimension(Node node, QMatrix4x4 transform, QVector3D &min, QVector3D &max);
}; };
#endif // MESH_H #endif // MESH_H
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