]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
loadMesh normals corrected
authorPeter Schaefer <schaeferpm@gmail.com>
Thu, 28 Apr 2016 07:00:21 +0000 (09:00 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Thu, 28 Apr 2016 07:00:21 +0000 (09:00 +0200)
Weave/Graphix/Model/IMesh.cpp
Weave/Graphix/Model/Model.cpp
Weave/Graphix/Model/Model.h
Weave/Graphix/Model/SkyBox.cpp

index a0f1138a05c8c7af4dfe2d7e1973c2dc5e025864..89ef0443fb6cf53097e27461109aa0f04c94a695 100644 (file)
@@ -40,7 +40,7 @@ using std::array;
 \r
 IMesh::IMesh(const aiMesh* _mesh, const vec3& _scale) : modelpath("IMesh")\r
 {\r
-       loadMesh(_mesh, numvertices, numfaces, vertex, uvs, normals, index, name, _scale);\r
+       loadMesh(_mesh, _scale);\r
 \r
        //bindModel();\r
 \r
index bb0db48df471ffa399ceba595c07de61a61d56bd..68e07d7de759c2f015ab44f1ef7dd97bb24b7a33 100644 (file)
@@ -358,7 +358,7 @@ void Model::deleteIMetaModel(const string& _modelpath)
 //}\r
 \r
 \r
-bool Model::loadMesh(const string& _modelpath, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, string& name, uint _mindex)\r
+bool Model::loadMesh(const string& _modelpath, uint _mindex)\r
 {\r
        Assimp::Importer importer;\r
 \r
@@ -375,10 +375,10 @@ bool Model::loadMesh(const string& _modelpath, uint& numvertices, uint& numfaces
                return false;\r
        }\r
 \r
-       return loadMesh(scene->mMeshes[_mindex], numvertices, numfaces, vertex, uvs, normals, index, name);\r
+       return loadMesh(scene->mMeshes[_mindex]);\r
 }\r
 \r
-bool Model::loadMesh(const aiMesh* mesh, uint& numvertices, uint& numfaces, float*& vertex, float*& uvs, float*& normals, uint*& index, string& name, const vec3& _scale)\r
+bool Model::loadMesh(const aiMesh* mesh, const vec3& _scale)\r
 {\r
 \r
        name = std::string((char*) (mesh->mName.data),(uint) (mesh->mName.length));\r
@@ -415,14 +415,19 @@ bool Model::loadMesh(const aiMesh* mesh, uint& numvertices, uint& numfaces, floa
        }\r
 \r
        //load normals from Mesh\r
-       if (mesh->mNormals != NULL)\r
+       if (mesh->mNormals != NULL) //TODO Normals may be wrong\r
        {\r
+               vec3 tmp;\r
                normals = new float[numvertices * 3];\r
                for (uint i = 0; i < numvertices; i++)\r
                {\r
-                       normals[3 * i] = mesh->mNormals[i].x;// / _scale.x;\r
-                       normals[3 * i + 1] = mesh->mNormals[i].y;// / _scale.y;\r
-                       normals[3 * i + 2] = mesh->mNormals[i].z;// / _scale.z;\r
+                       tmp = vec3(mesh->mNormals[i].x / _scale.x, mesh->mNormals[i].y / _scale.y, mesh->mNormals[i].z / _scale.z);\r
+                       tmp = normalize(tmp);\r
+               \r
+                       normals[3 * i] = tmp.x;\r
+                       normals[3 * i + 1] = tmp.y;\r
+                       normals[3 * i + 2] = tmp.z;\r
+               \r
                }\r
 \r
        }\r
index 0bfac79fae3ccebaf557daaed1c2c494cd5fd25b..5d43284a943a7cf9b54cb8ab4a6c66a0964eecd2 100644 (file)
@@ -56,8 +56,8 @@ public:
        virtual void bt_setMargin(btScalar margin);\r
 \r
        // Mesh Speichern?\r
-       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);\r
-       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));\r
+       bool loadMesh(const std::string& modelpath, uint mindex = 0);\r
+       bool loadMesh(const aiMesh* mesh, const vec3& scale = vec3(1.f));\r
 \r
 protected:\r
        Model();\r
@@ -71,6 +71,9 @@ protected:
        float *vertex = nullptr, *normals = nullptr, *uvs = nullptr;\r
        uint *index = nullptr;\r
 \r
+       vec3 center;\r
+       float radius;\r
+\r
        std::unordered_map<uint, uint> shader_map;\r
        \r
 \r
index e3b8406f6b27859e6efd5544afc0461a694a8970..86aec17202b22e8da19bf34398dbab9258289ea1 100644 (file)
@@ -9,7 +9,7 @@
 SkyBox::SkyBox()\r
 {\r
 \r
-       loadMesh("SkyBox.dae", numvertices, numfaces, vertex, uvs, normals, index, name, 0);\r
+       loadMesh("SkyBox.dae", 0);\r
 \r
        name = "SkyBox";\r
 \r