]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
moved all ModelClasses to SubDirectory Model
authorPeter Schaefer <schaeferpm@gmail.com>
Thu, 23 Apr 2015 09:05:23 +0000 (11:05 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Thu, 23 Apr 2015 09:05:23 +0000 (11:05 +0200)
created Model.h as Header for all Models
included winrar.bat (zip game files only)

23 files changed:
Weave/Game.cpp
Weave/Graphix/IMesh.cpp [deleted file]
Weave/Graphix/IMesh.h [deleted file]
Weave/Graphix/IMetaMesh.cpp [deleted file]
Weave/Graphix/IMetaMesh.h [deleted file]
Weave/Graphix/Model.cpp [deleted file]
Weave/Graphix/Model.h
Weave/Graphix/Model/BBox.cpp [new file with mode: 0644]
Weave/Graphix/Model/BBox.h [new file with mode: 0644]
Weave/Graphix/Model/IMesh.cpp [new file with mode: 0644]
Weave/Graphix/Model/IMesh.h [new file with mode: 0644]
Weave/Graphix/Model/IMetaMesh.cpp [new file with mode: 0644]
Weave/Graphix/Model/IMetaMesh.h [new file with mode: 0644]
Weave/Graphix/Model/Model.cpp [new file with mode: 0644]
Weave/Graphix/Model/Model.h [new file with mode: 0644]
Weave/Graphix/Model/SkyBox.cpp [new file with mode: 0644]
Weave/Graphix/Model/SkyBox.h [new file with mode: 0644]
Weave/Graphix/SceneObject.cpp
Weave/Graphix/SkyBox.cpp [deleted file]
Weave/Graphix/SkyBox.h [deleted file]
Weave/Weave.vcxproj
Weave/Weave.vcxproj.filters
winrar.bat [new file with mode: 0644]

index 544514014607cdc83ee821544c27947bd1245f3e..a44fbbde80cca03c466b6f5951292d77d8c81e02 100644 (file)
@@ -18,8 +18,6 @@
 #include "Fps.h"
 #include "Events.h"
 
-#include "Graphix\SkyBox.h"
-
 #include "Graphix\Model.h"
 
 #include "Message.h"
diff --git a/Weave/Graphix/IMesh.cpp b/Weave/Graphix/IMesh.cpp
deleted file mode 100644 (file)
index 3bd5fb9..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-#include "IMesh.h"
-
-#include <GL/glew.h>
-#include <assimp/Importer.hpp>
-#include <assimp/scene.h>
-#include <assimp/postprocess.h>
-
-#include "Shader.h"
-#include "Texture.h"
-#include "../Message.h"
-
-#include "Graphix.h"
-
-
-
-IMesh::IMesh(const string& _modelpath, uint _mindex)
-{
-
-       float *vertex = nullptr, *normals = nullptr, *uvs = nullptr;
-       uint *index = nullptr;
-
-       import(_modelpath, numvertices, numfaces, vertex, uvs, normals, index, _mindex);
-
-       genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
-       genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);
-       genBuffer(uvBuffer, numvertices * 2 * sizeof(float), (void*)uvs);
-       genBuffer(indexBuffer, numfaces * 3 * sizeof(uint), (void*)index);
-
-       delete vertex, normals, uvs, index;
-
-}
-
-IMesh::IMesh(const aiMesh* _mesh)
-{
-
-       float *vertex = nullptr, *normals = nullptr, *uvs = nullptr;
-       uint *index = nullptr;
-
-       import(_mesh, numvertices, numfaces, vertex, uvs, normals, index);
-
-       genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
-       genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);
-       genBuffer(uvBuffer, numvertices * 2 * sizeof(float), (void*)uvs);
-       genBuffer(indexBuffer, numfaces * 3 * sizeof(uint), (void*)index);
-
-       delete vertex, normals, uvs, index;
-
-}
-
-
-IMesh::~IMesh()
-{
-       glDeleteBuffers(1, &vertexBuffer);
-       glDeleteBuffers(1, &indexBuffer);
-       glDeleteBuffers(1, &normalBuffer);
-       glDeleteBuffers(1, &uvBuffer);
-}
-
-
-
-//void IMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
-//{
-//
-//}
-
-//void IMesh::bindShader(Shader* _shader)
-//{
-//
-//}
-
-
-bool IMesh::import(const string& _modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, uint _mindex) const
-{
-       Assimp::Importer importer;
-
-       const aiScene* scene = importer.ReadFile("../models/" + _modelpath, aiProcess_GenUVCoords | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType);           //aiProcess_PreTransformVertices
-       if (!scene)
-       {
-               Message::error("The file " + _modelpath + " couldn't be read.\n" + importer.GetErrorString());
-               return false;
-       }
-
-       if (!scene->HasMeshes() || scene->mNumMeshes <= _mindex)
-       {
-               Message::error("The file " + _modelpath + " doesn't contain any nodes.");
-               return false;
-       }
-
-       return import(scene->mMeshes[_mindex], numvertices, numfaces, vertex, uvs, normals, index);
-}
-
-bool IMesh::import(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index) const
-{
-
-       numvertices = mesh->mNumVertices;
-       numfaces = mesh->mNumFaces;
-       vertex = new float[numvertices * 3];
-       uvs = new float[numvertices * 2];
-       index = new uint[numfaces * 3];
-       normals = new float[numvertices * 3];
-       //aiFace* faces = mesh->mFaces;
-
-
-       //load vertices from Mesh
-       for (uint i = 0; i < numvertices; i++)
-       {
-               vertex[3 * i] = mesh->mVertices[i].x;
-               vertex[3 * i + 1] = mesh->mVertices[i].y;
-               vertex[3 * i + 2] = mesh->mVertices[i].z;
-       }
-
-       //load UVs from Mesh
-       for (uint i = 0; i < numvertices; i++)
-       {
-               uvs[2 * i] = mesh->mTextureCoords[0][i].x;//[i]->x;
-               uvs[2 * i + 1] = mesh->mTextureCoords[0][i].y;//[i]->y;
-       }
-
-       //load indices from Mesh
-       for (uint i = 0; i < numfaces; i++)
-       {
-               index[3 * i] = mesh->mFaces[i].mIndices[0];
-               index[3 * i + 1] = mesh->mFaces[i].mIndices[1];
-               index[3 * i + 2] = mesh->mFaces[i].mIndices[2];
-       }
-
-       //load normals from Mesh
-       for (uint i = 0; i < numvertices; i++)
-       {
-               normals[3 * i] = mesh->mNormals[i].x;
-               normals[3 * i + 1] = mesh->mNormals[i].y;
-               normals[3 * i + 2] = mesh->mNormals[i].z;
-       }
-
-       return true;
-}
diff --git a/Weave/Graphix/IMesh.h b/Weave/Graphix/IMesh.h
deleted file mode 100644 (file)
index c090379..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-#pragma once
-
-#include <string>
-#include "GLM.h"
-
-#include "Model.h"
-
-using std::string;
-
-class Shader;
-class Texture;
-struct aiMesh;
-
-class IMesh : public Model
-{
-public:
-       IMesh(const string& modelpath, uint index=0);
-       IMesh(const aiMesh* mesh);
-
-       virtual ~IMesh();
-
-       //void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;
-
-       //void bindShader(Shader* shader);
-
-protected:
-
-       // Mesh Speichern?
-       bool import(const string& modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index , uint mindex = 0) const;
-       bool import(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index) const;
-
-
-
-       
-
-};
-
diff --git a/Weave/Graphix/IMetaMesh.cpp b/Weave/Graphix/IMetaMesh.cpp
deleted file mode 100644 (file)
index 811c5ab..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-#include "IMetaMesh.h"
-
-#include <assimp/Importer.hpp>
-#include <assimp/scene.h>
-#include <assimp/postprocess.h>
-
-#include "IMesh.h"
-#include "Shader.h"
-#include "../Message.h"
-
-
-IMetaMesh::IMetaMesh(const string& _modelpath)
-{
-       Assimp::Importer importer;
-
-       const aiScene* scene = importer.ReadFile("../models/" + _modelpath, aiProcess_GenUVCoords | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType | aiProcess_PreTransformVertices);
-       if (!scene)
-       {
-               Message::error("The file " + _modelpath + " couldn't be read.\n" + importer.GetErrorString());
-               return;
-       }
-
-       if (scene->HasMeshes())// && scene->mNumMeshes > mindex)
-       {
-               for (unsigned int i = 0; i < scene->mNumMeshes; i++)
-               {
-                       models.push_back(new IMesh(scene->mMeshes[i]));
-               }       
-               
-       }
-       else
-       {
-               Message::error("The file " + _modelpath + " doesn't contain any nodes.");
-               return;
-       }
-
-}
-
-IMetaMesh::~IMetaMesh()
-{
-       for (auto i = models.begin(); i != models.end(); ++i)
-       {
-               delete (*i);
-       }
-}
-
-void IMetaMesh::bindShader(Shader* _shader)
-{
-       for (auto i = models.begin(); i != models.end(); ++i)
-       {
-               (*i)->bindShader(_shader);
-       }
-}
-
-void IMetaMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
-{
-       for (auto i = models.begin(); i != models.end(); ++i)
-       {
-               (*i)->drawModel(_shader,_texture,_modelMat);
-       }
-}
-
-
diff --git a/Weave/Graphix/IMetaMesh.h b/Weave/Graphix/IMetaMesh.h
deleted file mode 100644 (file)
index c88e4eb..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-#pragma once
-
-#include "Model.h"
-
-#include <string>
-#include <list>
-#include "GLM.h"
-
-using std::string;
-
-class IMesh;
-class Shader;
-class Texture;
-
-class IMetaMesh : public Model
-{
-public:
-       IMetaMesh(const string& modelpath);
-       ~IMetaMesh();
-
-       void bindShader(Shader* shader);
-
-       void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;
-
-protected:
-       std::list<IMesh*> models;
-};
-
diff --git a/Weave/Graphix/Model.cpp b/Weave/Graphix/Model.cpp
deleted file mode 100644 (file)
index 05b13b5..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-#include "Model.h"
-
-#include <GL/glew.h>
-#include "../Message.h"
-
-#include "Shader.h"
-#include "Texture.h"
-
-#include "Graphix.h"
-
-Model::Model() :
-       numfaces(0),
-       numvertices(0),
-       vertexBuffer(-1),
-       normalBuffer(-1),
-       uvBuffer(-1),
-       indexBuffer(-1)
-{
-}
-
-
-Model::~Model()
-{
-       for (auto i = shader_map.begin(); i != shader_map.end(); ++i){
-               glDeleteVertexArrays(1, &(i->second));
-       }
-}
-
-void Model::bindShader(Shader* _shader)
-{
-       //Message::info("bindShader");
-       //Graphix::getGlError();
-       //Message::info("Do Stuff");
-
-       if (indexBuffer == (uint)-1)
-       {
-               Message::error("Model: IndexBuffer wurde nicht geladen.");
-               return;
-       }
-
-       uint vao;
-       glGenVertexArrays(1, &vao);
-       glBindVertexArray(vao);
-
-       //Message::info("bindVAO");
-       //Graphix::getGlError();
-       if (vertexBuffer != (uint)-1)
-               bindBuffer(vertexBuffer, _shader->getAttribLocation("aPosition"));
-       //Message::info("aPosition");
-       //Graphix::getGlError();
-       if (uvBuffer != (uint)-1)
-               bindBuffer(uvBuffer, _shader->getAttribLocation("aUV"), 2);
-       //Message::info("aUV");
-       //Graphix::getGlError();
-       if (normalBuffer != (uint)-1)
-               bindBuffer(normalBuffer, _shader->getAttribLocation("aNormal"));
-       //Message::info("aNormal");
-       //Graphix::getGlError();
-
-       glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
-       //Message::info("bindIndexBuffer");
-       //Graphix::getGlError();
-
-       glBindVertexArray(0);
-
-       glBindBuffer(GL_ARRAY_BUFFER, 0);
-       glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
-
-       shader_map[*_shader] = vao;
-
-       //Message::info("cleanUp");
-       //Graphix::getGlError();
-       //Message::info("Done");
-}
-
-void Model::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
-{
-       //Message::info("Error from before?");
-       //Graphix::getGlError();
-       useModel(_shader);
-       //Message::info("IMesh loading Coordinates");
-       //Graphix::getGlError();
-       useTexture(_texture, _shader);
-       //Message::info("IMesh loading Texture");
-       //Graphix::getGlError();
-       useModelMat(_modelMat, _shader);
-       //Message::info("IMesh loading MMatrix");
-       //Graphix::getGlError();
-       glDrawElements(GL_TRIANGLES, numfaces * 3, GL_UNSIGNED_INT, 0);
-       //Message::info("IMesh drawing Elements");
-       //Graphix::getGlError();
-       glBindVertexArray(0);
-       //system("pause");
-}
-
-void Model::drawBBox() const
-{
-}
-
-void Model::updateBB(const vec3& _min, const vec3& _max)
-{
-       BBsize = _max - _min;
-       BBposition = (_min + _max) / 2.f;
-}
-
-void Model::genBuffer(uint &buffer, uint size, void* value)
-{
-       glGenBuffers(1, &buffer);
-       glBindBuffer(GL_ARRAY_BUFFER, buffer);
-       glBufferData(GL_ARRAY_BUFFER, size, value, GL_STATIC_DRAW);
-       glBindBuffer(GL_ARRAY_BUFFER, 0);
-}
-
-void Model::bindBuffer(const uint &buffer, const uint index, const uint dim)
-{
-       //Falls index nicht gefunden werden konnte
-       if (index == (uint)-1)
-       {
-               Message::info("Model: BindBuffer wird ausgelassen da index fehlerhaft ist.");
-               return;
-       }
-
-       glBindBuffer(GL_ARRAY_BUFFER, buffer);
-       glEnableVertexAttribArray(index);
-       glVertexAttribPointer(index, dim, GL_FLOAT, GL_FALSE, 0, 0);
-       glBindBuffer(GL_ARRAY_BUFFER, 0);
-}
-
-void Model::useModel(Shader* _shader) const
-{
-       _shader->useShader();
-       uint vao = -1;
-       auto i = shader_map.find(*_shader);
-       if (i == shader_map.end())
-               Message::error("The Shader wasn't bind to the Model.\n");
-       else
-               vao = i->second;
-
-       glBindVertexArray(vao);
-
-}
-
-void Model::useTexture(Texture* _texture, Shader* _shader) const
-{
-       if (_texture != nullptr)
-       {
-               auto tmp = _shader->getUniformLocation("uColorTexture");
-               if (tmp < 0){
-                       return;
-               }
-               int unit = 0;
-               _texture->bind(unit);
-               glUniform1i(tmp, unit);
-       }
-}
-
-void Model::useModelMat(const mat4& _model, Shader* _shader) const
-{
-       int tmp = _shader->getUniformLocation("uModel");
-       if (tmp >= 0)
-               glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model));
-}
index 8d8292700137f32cb0f108f1db03115d33f9a9ad..0a8570198f2672779ddae100c1eaa196cd060a2d 100644 (file)
@@ -1,45 +1,6 @@
 #pragma once
 
-#include "GLM.h"
-#include <unordered_map>
-
-class Shader;
-class Texture;
-
-typedef unsigned int uint;
-
-class Model
-{
-public:
-       Model();
-       virtual ~Model();
-
-       /* Binds Model to the Model*/
-       virtual void bindShader(Shader* shader);
-
-       /* Draws Model */
-       virtual void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;
-
-       /* Draws a BoundingBox around the Model */
-       virtual void drawBBox() const;
-
-protected:
-       uint numvertices, numfaces;
-       uint vertexBuffer, indexBuffer, normalBuffer, uvBuffer;
-
-       std::unordered_map<uint, uint> shader_map;
-
-       void updateBB(const vec3& min, const vec3& max);
-
-       void genBuffer(uint &buffer, uint size, void* value);
-       void bindBuffer(const uint &buffer, const uint index, const uint dim = 3);
-
-       virtual void useModel(Shader* shader) const;
-       virtual void useTexture(Texture* texture, Shader* shader) const;
-       virtual void useModelMat(const mat4& model, Shader* shader) const;
-
-private:
-       vec3 BBsize, BBposition;
-
-};
-
+#include "Model\Model.h"
+#include "Model\IMetaMesh.h"
+#include "Model\SkyBox.h"
+#include "Model\BBox.h"
\ No newline at end of file
diff --git a/Weave/Graphix/Model/BBox.cpp b/Weave/Graphix/Model/BBox.cpp
new file mode 100644 (file)
index 0000000..af07531
--- /dev/null
@@ -0,0 +1,32 @@
+#include "BBox.h"
+#include "GL\glew.h"
+
+uint indexL1[4]{ 0, 1, 2, 3 },
+indexL2[4]{ 4, 5, 6, 7},
+indexS1[8]{0, 4, 1, 5, 2, 6, 3, 7};
+
+BBox::BBox()
+{
+       numvertices = 4;
+       numfaces = 2;
+
+       float vertex[] { -.5f, -.5f, -.5f, .5f, -.5f, -.5f, .5f, .5f, -.5f, -.5f, .5f, -.5f, -.5f, -.5f, .5f, .5f, -.5f, .5f, .5f, .5f, .5f, -.5f, .5f, .5f };
+
+       //import("skybox.dae", numvertices, numfaces, vertex, uvs, normals, index, 0);
+
+       genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
+
+}
+
+
+BBox::~BBox()
+{
+}
+
+void BBox::drawModel() const
+{
+       glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indexL1);
+       glDrawElements(GL_LINE_LOOP, 4, GL_UNSIGNED_INT, indexL2);
+       glDrawElements(GL_LINE_STRIP, 8, GL_UNSIGNED_INT, indexS1);
+       glBindVertexArray(0);
+}
\ No newline at end of file
diff --git a/Weave/Graphix/Model/BBox.h b/Weave/Graphix/Model/BBox.h
new file mode 100644 (file)
index 0000000..c56c518
--- /dev/null
@@ -0,0 +1,13 @@
+#pragma once
+#include "Model.h"
+class BBox :
+       public Model
+{
+public:
+       BBox();
+       ~BBox();
+
+       void drawModel() const;
+
+};
+
diff --git a/Weave/Graphix/Model/IMesh.cpp b/Weave/Graphix/Model/IMesh.cpp
new file mode 100644 (file)
index 0000000..bcb2bfe
--- /dev/null
@@ -0,0 +1,136 @@
+#include "IMesh.h"
+
+#include <GL/glew.h>
+#include <assimp/Importer.hpp>
+#include <assimp/scene.h>
+#include <assimp/postprocess.h>
+
+#include "../Shader.h"
+#include "../Texture.h"
+#include "../../Message.h"
+
+#include "../Graphix.h"
+
+
+
+IMesh::IMesh(const string& _modelpath, uint _mindex)
+{
+
+       float *vertex = nullptr, *normals = nullptr, *uvs = nullptr;
+       uint *index = nullptr;
+
+       import(_modelpath, numvertices, numfaces, vertex, uvs, normals, index, _mindex);
+
+       genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
+       genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);
+       genBuffer(uvBuffer, numvertices * 2 * sizeof(float), (void*)uvs);
+       genBuffer(indexBuffer, numfaces * 3 * sizeof(uint), (void*)index);
+
+       delete vertex, normals, uvs, index;
+
+}
+
+IMesh::IMesh(const aiMesh* _mesh)
+{
+
+       float *vertex = nullptr, *normals = nullptr, *uvs = nullptr;
+       uint *index = nullptr;
+
+       import(_mesh, numvertices, numfaces, vertex, uvs, normals, index);
+
+       genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
+       genBuffer(normalBuffer, numvertices * 3 * sizeof(float), (void*)normals);
+       genBuffer(uvBuffer, numvertices * 2 * sizeof(float), (void*)uvs);
+       genBuffer(indexBuffer, numfaces * 3 * sizeof(uint), (void*)index);
+
+       delete vertex, normals, uvs, index;
+
+}
+
+
+IMesh::~IMesh()
+{
+       glDeleteBuffers(1, &vertexBuffer);
+       glDeleteBuffers(1, &indexBuffer);
+       glDeleteBuffers(1, &normalBuffer);
+       glDeleteBuffers(1, &uvBuffer);
+}
+
+
+
+//void IMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
+//{
+//
+//}
+
+//void IMesh::bindShader(Shader* _shader)
+//{
+//
+//}
+
+
+bool IMesh::import(const string& _modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, uint _mindex) const
+{
+       Assimp::Importer importer;
+
+       const aiScene* scene = importer.ReadFile("../models/" + _modelpath, aiProcess_GenUVCoords | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType);           //aiProcess_PreTransformVertices
+       if (!scene)
+       {
+               Message::error("The file " + _modelpath + " couldn't be read.\n" + importer.GetErrorString());
+               return false;
+       }
+
+       if (!scene->HasMeshes() || scene->mNumMeshes <= _mindex)
+       {
+               Message::error("The file " + _modelpath + " doesn't contain any nodes.");
+               return false;
+       }
+
+       return import(scene->mMeshes[_mindex], numvertices, numfaces, vertex, uvs, normals, index);
+}
+
+bool IMesh::import(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index) const
+{
+
+       numvertices = mesh->mNumVertices;
+       numfaces = mesh->mNumFaces;
+       vertex = new float[numvertices * 3];
+       uvs = new float[numvertices * 2];
+       index = new uint[numfaces * 3];
+       normals = new float[numvertices * 3];
+       //aiFace* faces = mesh->mFaces;
+
+
+       //load vertices from Mesh
+       for (uint i = 0; i < numvertices; i++)
+       {
+               vertex[3 * i] = mesh->mVertices[i].x;
+               vertex[3 * i + 1] = mesh->mVertices[i].y;
+               vertex[3 * i + 2] = mesh->mVertices[i].z;
+       }
+
+       //load UVs from Mesh
+       for (uint i = 0; i < numvertices; i++)
+       {
+               uvs[2 * i] = mesh->mTextureCoords[0][i].x;//[i]->x;
+               uvs[2 * i + 1] = mesh->mTextureCoords[0][i].y;//[i]->y;
+       }
+
+       //load indices from Mesh
+       for (uint i = 0; i < numfaces; i++)
+       {
+               index[3 * i] = mesh->mFaces[i].mIndices[0];
+               index[3 * i + 1] = mesh->mFaces[i].mIndices[1];
+               index[3 * i + 2] = mesh->mFaces[i].mIndices[2];
+       }
+
+       //load normals from Mesh
+       for (uint i = 0; i < numvertices; i++)
+       {
+               normals[3 * i] = mesh->mNormals[i].x;
+               normals[3 * i + 1] = mesh->mNormals[i].y;
+               normals[3 * i + 2] = mesh->mNormals[i].z;
+       }
+
+       return true;
+}
diff --git a/Weave/Graphix/Model/IMesh.h b/Weave/Graphix/Model/IMesh.h
new file mode 100644 (file)
index 0000000..fa025ba
--- /dev/null
@@ -0,0 +1,37 @@
+#pragma once
+
+#include <string>
+#include "../GLM.h"
+
+#include "Model.h"
+
+using std::string;
+
+class Shader;
+class Texture;
+struct aiMesh;
+
+class IMesh : public Model
+{
+public:
+       IMesh(const string& modelpath, uint index=0);
+       IMesh(const aiMesh* mesh);
+
+       virtual ~IMesh();
+
+       //void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;
+
+       //void bindShader(Shader* shader);
+
+protected:
+
+       // Mesh Speichern?
+       bool import(const string& modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index , uint mindex = 0) const;
+       bool import(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index) const;
+
+
+
+       
+
+};
+
diff --git a/Weave/Graphix/Model/IMetaMesh.cpp b/Weave/Graphix/Model/IMetaMesh.cpp
new file mode 100644 (file)
index 0000000..d094020
--- /dev/null
@@ -0,0 +1,63 @@
+#include "IMetaMesh.h"
+
+#include <assimp/Importer.hpp>
+#include <assimp/scene.h>
+#include <assimp/postprocess.h>
+
+#include "IMesh.h"
+#include "../Shader.h"
+#include "../../Message.h"
+
+
+IMetaMesh::IMetaMesh(const string& _modelpath)
+{
+       Assimp::Importer importer;
+
+       const aiScene* scene = importer.ReadFile("../models/" + _modelpath, aiProcess_GenUVCoords | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType | aiProcess_PreTransformVertices);
+       if (!scene)
+       {
+               Message::error("The file " + _modelpath + " couldn't be read.\n" + importer.GetErrorString());
+               return;
+       }
+
+       if (scene->HasMeshes())// && scene->mNumMeshes > mindex)
+       {
+               for (unsigned int i = 0; i < scene->mNumMeshes; i++)
+               {
+                       models.push_back(new IMesh(scene->mMeshes[i]));
+               }       
+               
+       }
+       else
+       {
+               Message::error("The file " + _modelpath + " doesn't contain any nodes.");
+               return;
+       }
+
+}
+
+IMetaMesh::~IMetaMesh()
+{
+       for (auto i = models.begin(); i != models.end(); ++i)
+       {
+               delete (*i);
+       }
+}
+
+void IMetaMesh::bindShader(Shader* _shader)
+{
+       for (auto i = models.begin(); i != models.end(); ++i)
+       {
+               (*i)->bindShader(_shader);
+       }
+}
+
+void IMetaMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
+{
+       for (auto i = models.begin(); i != models.end(); ++i)
+       {
+               (*i)->drawModel(_shader,_texture,_modelMat);
+       }
+}
+
+
diff --git a/Weave/Graphix/Model/IMetaMesh.h b/Weave/Graphix/Model/IMetaMesh.h
new file mode 100644 (file)
index 0000000..bb3bbdd
--- /dev/null
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "Model.h"
+
+#include <string>
+#include <list>
+#include "../GLM.h"
+
+using std::string;
+
+class IMesh;
+class Shader;
+class Texture;
+
+class IMetaMesh : public Model
+{
+public:
+       IMetaMesh(const string& modelpath);
+       ~IMetaMesh();
+
+       void bindShader(Shader* shader);
+
+       void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;
+
+protected:
+       std::list<IMesh*> models;
+};
+
diff --git a/Weave/Graphix/Model/Model.cpp b/Weave/Graphix/Model/Model.cpp
new file mode 100644 (file)
index 0000000..408d571
--- /dev/null
@@ -0,0 +1,163 @@
+#include "Model.h"
+
+#include <GL/glew.h>
+#include "../../Message.h"
+
+#include "../Shader.h"
+#include "../Texture.h"
+
+#include "../Graphix.h"
+
+Model::Model() :
+       numfaces(0),
+       numvertices(0),
+       vertexBuffer(-1),
+       normalBuffer(-1),
+       uvBuffer(-1),
+       indexBuffer(-1)
+{
+}
+
+
+Model::~Model()
+{
+       for (auto i = shader_map.begin(); i != shader_map.end(); ++i){
+               glDeleteVertexArrays(1, &(i->second));
+       }
+}
+
+void Model::bindShader(Shader* _shader)
+{
+       //Message::info("bindShader");
+       //Graphix::getGlError();
+       //Message::info("Do Stuff");
+
+       uint vao;
+       glGenVertexArrays(1, &vao);
+       glBindVertexArray(vao);
+
+       //Message::info("bindVAO");
+       //Graphix::getGlError();
+       if (vertexBuffer != (uint)-1)
+               bindBuffer(vertexBuffer, _shader->getAttribLocation("aPosition"));
+       //Message::info("aPosition");
+       //Graphix::getGlError();
+       if (uvBuffer != (uint)-1)
+               bindBuffer(uvBuffer, _shader->getAttribLocation("aUV"), 2);
+       //Message::info("aUV");
+       //Graphix::getGlError();
+       if (normalBuffer != (uint)-1)
+               bindBuffer(normalBuffer, _shader->getAttribLocation("aNormal"));
+       //Message::info("aNormal");
+       //Graphix::getGlError();
+
+       if (indexBuffer != (uint)-1)
+               glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
+       //Message::info("bindIndexBuffer");
+       //Graphix::getGlError();
+
+       glBindVertexArray(0);
+
+       glBindBuffer(GL_ARRAY_BUFFER, 0);
+       glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+
+       shader_map[*_shader] = vao;
+
+       //Message::info("cleanUp");
+       //Graphix::getGlError();
+       //Message::info("Done");
+}
+
+void Model::drawModel() const
+{
+       glDrawElements(GL_TRIANGLES, numfaces * 3, GL_UNSIGNED_INT, 0);
+       glBindVertexArray(0);
+}
+
+void Model::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
+{
+       //Message::info("Error from before?");
+       //Graphix::getGlError();
+       useModel(_shader);
+       //Message::info("IMesh loading Coordinates");
+       //Graphix::getGlError();
+       useTexture(_texture, _shader);
+       //Message::info("IMesh loading Texture");
+       //Graphix::getGlError();
+       useModelMat(_modelMat, _shader);
+       //Message::info("IMesh loading MMatrix");
+       //Graphix::getGlError();
+       drawModel();
+       //Message::info("IMesh drawing Elements");
+       //Graphix::getGlError();
+       //system("pause");
+}
+
+void Model::drawBBox() const
+{
+
+}
+
+void Model::updateBB(const vec3& _min, const vec3& _max)
+{
+       BBsize = _max - _min;
+       BBposition = (_min + _max) / 2.f;
+}
+
+void Model::genBuffer(uint &buffer, uint size, void* value)
+{
+       glGenBuffers(1, &buffer);
+       glBindBuffer(GL_ARRAY_BUFFER, buffer);
+       glBufferData(GL_ARRAY_BUFFER, size, value, GL_STATIC_DRAW);
+       glBindBuffer(GL_ARRAY_BUFFER, 0);
+}
+
+void Model::bindBuffer(const uint &buffer, const uint index, const uint dim)
+{
+       //Falls index nicht gefunden werden konnte
+       if (index == (uint)-1)
+       {
+               Message::info("Model: BindBuffer wird ausgelassen da index fehlerhaft ist.");
+               return;
+       }
+
+       glBindBuffer(GL_ARRAY_BUFFER, buffer);
+       glEnableVertexAttribArray(index);
+       glVertexAttribPointer(index, dim, GL_FLOAT, GL_FALSE, 0, 0);
+       glBindBuffer(GL_ARRAY_BUFFER, 0);
+}
+
+void Model::useModel(Shader* _shader) const
+{
+       _shader->useShader();
+       uint vao = -1;
+       auto i = shader_map.find(*_shader);
+       if (i == shader_map.end())
+               Message::error("The Shader wasn't bind to the Model.\n");
+       else
+               vao = i->second;
+
+       glBindVertexArray(vao);
+
+}
+
+void Model::useTexture(Texture* _texture, Shader* _shader) const
+{
+       if (_texture != nullptr)
+       {
+               auto tmp = _shader->getUniformLocation("uColorTexture");
+               if (tmp < 0){
+                       return;
+               }
+               int unit = 0;
+               _texture->bind(unit);
+               glUniform1i(tmp, unit);
+       }
+}
+
+void Model::useModelMat(const mat4& _model, Shader* _shader) const
+{
+       int tmp = _shader->getUniformLocation("uModel");
+       if (tmp >= 0)
+               glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model));
+}
diff --git a/Weave/Graphix/Model/Model.h b/Weave/Graphix/Model/Model.h
new file mode 100644 (file)
index 0000000..19b7a93
--- /dev/null
@@ -0,0 +1,46 @@
+#pragma once
+
+#include "../GLM.h"
+#include <unordered_map>
+
+class Shader;
+class Texture;
+
+typedef unsigned int uint;
+
+class Model
+{
+public:
+       Model();
+       virtual ~Model();
+
+       /* Binds Model to the Model*/
+       virtual void bindShader(Shader* shader);
+
+       /* Draws Model */
+       virtual void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;
+
+       /* Draws a BoundingBox around the Model */
+       virtual void drawBBox() const;
+
+protected:
+       uint numvertices, numfaces;
+       uint vertexBuffer, indexBuffer, normalBuffer, uvBuffer;
+
+       std::unordered_map<uint, uint> shader_map;
+
+       void updateBB(const vec3& min, const vec3& max);
+
+       void genBuffer(uint &buffer, uint size, void* value);
+       void bindBuffer(const uint &buffer, const uint index, const uint dim = 3);
+
+       virtual void useModel(Shader* shader) const;
+       virtual void useTexture(Texture* texture, Shader* shader) const;
+       virtual void useModelMat(const mat4& model, Shader* shader) const;
+       virtual void drawModel() const;
+
+private:
+       vec3 BBsize, BBposition;
+
+};
+
diff --git a/Weave/Graphix/Model/SkyBox.cpp b/Weave/Graphix/Model/SkyBox.cpp
new file mode 100644 (file)
index 0000000..7cb2708
--- /dev/null
@@ -0,0 +1,44 @@
+#include "SkyBox.h"
+
+#include "GL/glew.h"
+#include "../Graphix.h"
+
+
+SkyBox::SkyBox()
+{
+       numvertices = 4;
+       numfaces = 2;
+
+       float vertex[] { -1.f, - 1.f, 0.f, 1.f, - 1.f, 0.f, - 1.f, 1.f, 0.f, 1.f, 1.f, 0.f };
+       uint index[] { 1,3,2,0,1,2};
+
+       //import("skybox.dae", numvertices, numfaces, vertex, uvs, normals, index, 0);
+
+       genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
+       genBuffer(indexBuffer, numfaces * 3 * sizeof(uint), (void*)index);
+
+//     delete vertex, index;
+}
+
+
+SkyBox::~SkyBox()
+{
+}
+
+void SkyBox::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
+{
+       glDisable(GL_DEPTH_TEST);
+       Model::drawModel(_shader, _texture, _modelMat);
+       glEnable(GL_DEPTH_TEST);
+}
+
+void SkyBox::useModelMat(const mat4& _model, Shader* _shader) const
+{
+
+}
+
+void SkyBox::useTexture(Texture* _texture, Shader* _shader) const
+{
+
+}
+
diff --git a/Weave/Graphix/Model/SkyBox.h b/Weave/Graphix/Model/SkyBox.h
new file mode 100644 (file)
index 0000000..be5e88b
--- /dev/null
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "Model.h"
+
+class SkyBox :
+       public Model
+{
+public:
+       SkyBox();
+       ~SkyBox();
+
+       void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;
+
+       //uncommend following lines to use default Loaders
+       void useModelMat(const mat4& model, Shader* shader) const;
+       void useTexture(Texture* texture, Shader* shader) const;
+
+};
+
index e74437e15f6f7798f66805dbeb20128f0b8d099d..8201e5f1ecb68723ea2fcf4dbd0b1add4f8be6f5 100644 (file)
@@ -12,8 +12,7 @@
 #include "Scene.h"
 #include "Texture.h"
 
-#include "IMesh.h"
-#include "IMetaMesh.h"
+#include "Model.h"
 
 #include "Graphix.h"
 
diff --git a/Weave/Graphix/SkyBox.cpp b/Weave/Graphix/SkyBox.cpp
deleted file mode 100644 (file)
index 8e85a03..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "SkyBox.h"
-
-#include "GL/glew.h"
-#include "Graphix.h"
-
-
-SkyBox::SkyBox()
-{
-       numvertices = 4;
-       numfaces = 2;
-
-       float vertex[] { -1.f, - 1.f, 0.f, 1.f, - 1.f, 0.f, - 1.f, 1.f, 0.f, 1.f, 1.f, 0.f };
-       uint index[] { 1,3,2,0,1,2};
-
-       //import("skybox.dae", numvertices, numfaces, vertex, uvs, normals, index, 0);
-
-       genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
-       genBuffer(indexBuffer, numfaces * 3 * sizeof(uint), (void*)index);
-
-//     delete vertex, index;
-}
-
-
-SkyBox::~SkyBox()
-{
-}
-
-void SkyBox::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
-{
-       glDisable(GL_DEPTH_TEST);
-       Model::drawModel(_shader, _texture, _modelMat);
-       glEnable(GL_DEPTH_TEST);
-}
-
-void SkyBox::useModelMat(const mat4& model, Shader* shader) const
-{
-
-}
-
diff --git a/Weave/Graphix/SkyBox.h b/Weave/Graphix/SkyBox.h
deleted file mode 100644 (file)
index d6f6963..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#pragma once
-
-#include "Model.h"
-
-class SkyBox :
-       public Model
-{
-public:
-       SkyBox();
-       ~SkyBox();
-
-       void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;
-
-       void useModelMat(const mat4& model, Shader* shader) const;
-
-};
-
index d21a26d5fe1b2cf5b0bafc69fb7091e3449766da..9f0dd6ac696229f15108b1d66e44ce5bd0e1ee32 100644 (file)
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
-    <ClCompile Include="Graphix\Model.cpp" />
+    <ClCompile Include="Graphix\Model\BBox.cpp" />
+    <ClCompile Include="Graphix\Model\Model.cpp" />
     <ClCompile Include="Events.cpp" />
     <ClCompile Include="Fps.cpp" />
     <ClCompile Include="Game.cpp" />
     <ClCompile Include="Graphix\Drawable.cpp" />
     <ClCompile Include="Graphix\GLM.cpp" />
     <ClCompile Include="Graphix\Graphix.cpp" />
-    <ClCompile Include="Graphix\IMesh.cpp" />
+    <ClCompile Include="Graphix\Model\IMesh.cpp" />
     <ClCompile Include="Graphix\Scene.cpp" />
     <ClCompile Include="Graphix\SceneObject.cpp" />
     <ClCompile Include="Graphix\Shader.cpp" />
-    <ClCompile Include="Graphix\SkyBox.cpp" />
+    <ClCompile Include="Graphix\Model\SkyBox.cpp" />
     <ClCompile Include="Graphix\Texture.cpp" />
     <ClCompile Include="Graphix\ViewPort.cpp" />
     <ClCompile Include="main.cpp" />
     <ClCompile Include="Message.cpp" />
-    <ClCompile Include="Graphix\IMetaMesh.cpp" />
+    <ClCompile Include="Graphix\Model\IMetaMesh.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Average.h" />
     <ClInclude Include="Graphix\Model.h" />
+    <ClInclude Include="Graphix\Model\BBox.h" />
+    <ClInclude Include="Graphix\Model\Model.h" />
     <ClInclude Include="Events.h" />
     <ClInclude Include="Fps.h" />
     <ClInclude Include="Game.h" />
     <ClInclude Include="Graphix\Drawable.h" />
     <ClInclude Include="Graphix\GLM.h" />
     <ClInclude Include="Graphix\Graphix.h" />
-    <ClInclude Include="Graphix\IMesh.h" />
+    <ClInclude Include="Graphix\Model\IMesh.h" />
     <ClInclude Include="Graphix\Scene.h" />
     <ClInclude Include="Graphix\SceneObject.h" />
     <ClInclude Include="Graphix\Shader.h" />
-    <ClInclude Include="Graphix\SkyBox.h" />
+    <ClInclude Include="Graphix\Model\SkyBox.h" />
     <ClInclude Include="Graphix\Texture.h" />
     <ClInclude Include="Graphix\ViewPort.h" />
     <ClInclude Include="Message.h" />
-    <ClInclude Include="Graphix\IMetaMesh.h" />
+    <ClInclude Include="Graphix\Model\IMetaMesh.h" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
index 4820f10a8ed1566b4400b1b3823139ad03eaa158..8c9156fc7eeec72206372ee2958375613eef8f2f 100644 (file)
     <ClCompile Include="Graphix\SceneObject.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="Graphix\IMesh.cpp">
+    <ClCompile Include="Graphix\Model\IMesh.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="Graphix\Model.cpp">
+    <ClCompile Include="Graphix\Model\IMetaMesh.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="Graphix\IMetaMesh.cpp">
+    <ClCompile Include="Graphix\Model\BBox.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="Graphix\SkyBox.cpp">
+    <ClCompile Include="Graphix\Model\Model.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Graphix\Model\SkyBox.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
   </ItemGroup>
     <ClInclude Include="Graphix\SceneObject.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="Graphix\IMesh.h">
+    <ClInclude Include="Graphix\Model\IMesh.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="Graphix\Model.h">
+    <ClInclude Include="Graphix\Model\IMetaMesh.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Graphix\Model\BBox.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Graphix\Model\Model.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="Graphix\IMetaMesh.h">
+    <ClInclude Include="Graphix\Model\SkyBox.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="Graphix\SkyBox.h">
+    <ClInclude Include="Graphix\Model.h">
       <Filter>Header Files</Filter>
     </ClInclude>
   </ItemGroup>
diff --git a/winrar.bat b/winrar.bat
new file mode 100644 (file)
index 0000000..9ae18d0
--- /dev/null
@@ -0,0 +1,5 @@
+@echo off
+
+C:\Programme\WinRar\rar a -r -x*.blend -x*.blend* -x*.pdb -x*.psb -x*.psd CGUE.zip textures models shader bin
+
+#pause
\ No newline at end of file