From 9c622c6b2f6ce763090356758a403e664ccece6a Mon Sep 17 00:00:00 2001 From: Peter Schaefer Date: Thu, 28 Apr 2016 09:00:21 +0200 Subject: [PATCH] loadMesh normals corrected --- Weave/Graphix/Model/IMesh.cpp | 2 +- Weave/Graphix/Model/Model.cpp | 19 ++++++++++++------- Weave/Graphix/Model/Model.h | 7 +++++-- Weave/Graphix/Model/SkyBox.cpp | 2 +- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Weave/Graphix/Model/IMesh.cpp b/Weave/Graphix/Model/IMesh.cpp index a0f1138..89ef044 100644 --- a/Weave/Graphix/Model/IMesh.cpp +++ b/Weave/Graphix/Model/IMesh.cpp @@ -40,7 +40,7 @@ using std::array; IMesh::IMesh(const aiMesh* _mesh, const vec3& _scale) : modelpath("IMesh") { - loadMesh(_mesh, numvertices, numfaces, vertex, uvs, normals, index, name, _scale); + loadMesh(_mesh, _scale); //bindModel(); diff --git a/Weave/Graphix/Model/Model.cpp b/Weave/Graphix/Model/Model.cpp index bb0db48..68e07d7 100644 --- a/Weave/Graphix/Model/Model.cpp +++ b/Weave/Graphix/Model/Model.cpp @@ -358,7 +358,7 @@ void Model::deleteIMetaModel(const string& _modelpath) //} -bool Model::loadMesh(const string& _modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, string& name, uint _mindex) +bool Model::loadMesh(const string& _modelpath, uint _mindex) { Assimp::Importer importer; @@ -375,10 +375,10 @@ bool Model::loadMesh(const string& _modelpath, uint& numvertices, uint& numfaces return false; } - return loadMesh(scene->mMeshes[_mindex], numvertices, numfaces, vertex, uvs, normals, index, name); + return loadMesh(scene->mMeshes[_mindex]); } -bool Model::loadMesh(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, string& name, const vec3& _scale) +bool Model::loadMesh(const aiMesh* mesh, const vec3& _scale) { name = std::string((char*) (mesh->mName.data),(uint) (mesh->mName.length)); @@ -415,14 +415,19 @@ bool Model::loadMesh(const aiMesh* mesh, uint& numvertices, uint& numfaces, floa } //load normals from Mesh - if (mesh->mNormals != NULL) + if (mesh->mNormals != NULL) //TODO Normals may be wrong { + vec3 tmp; normals = new float[numvertices * 3]; for (uint i = 0; i < numvertices; i++) { - normals[3 * i] = mesh->mNormals[i].x;// / _scale.x; - normals[3 * i + 1] = mesh->mNormals[i].y;// / _scale.y; - normals[3 * i + 2] = mesh->mNormals[i].z;// / _scale.z; + tmp = vec3(mesh->mNormals[i].x / _scale.x, mesh->mNormals[i].y / _scale.y, mesh->mNormals[i].z / _scale.z); + tmp = normalize(tmp); + + normals[3 * i] = tmp.x; + normals[3 * i + 1] = tmp.y; + normals[3 * i + 2] = tmp.z; + } } diff --git a/Weave/Graphix/Model/Model.h b/Weave/Graphix/Model/Model.h index 0bfac79..5d43284 100644 --- a/Weave/Graphix/Model/Model.h +++ b/Weave/Graphix/Model/Model.h @@ -56,8 +56,8 @@ public: virtual void bt_setMargin(btScalar margin); // Mesh Speichern? - static bool loadMesh(const std::string& modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, std::string& name, uint mindex = 0); - static bool loadMesh(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, std::string& name, const vec3& scale = vec3(1.f)); + bool loadMesh(const std::string& modelpath, uint mindex = 0); + bool loadMesh(const aiMesh* mesh, const vec3& scale = vec3(1.f)); protected: Model(); @@ -71,6 +71,9 @@ protected: float *vertex = nullptr, *normals = nullptr, *uvs = nullptr; uint *index = nullptr; + vec3 center; + float radius; + std::unordered_map shader_map; diff --git a/Weave/Graphix/Model/SkyBox.cpp b/Weave/Graphix/Model/SkyBox.cpp index e3b8406..86aec17 100644 --- a/Weave/Graphix/Model/SkyBox.cpp +++ b/Weave/Graphix/Model/SkyBox.cpp @@ -9,7 +9,7 @@ SkyBox::SkyBox() { - loadMesh("SkyBox.dae", numvertices, numfaces, vertex, uvs, normals, index, name, 0); + loadMesh("SkyBox.dae", 0); name = "SkyBox"; -- 2.47.3