]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
importer improved
authorLockedLunatic <locked.lunatic@aon.at>
Sat, 25 Apr 2015 16:39:22 +0000 (18:39 +0200)
committerLockedLunatic <locked.lunatic@aon.at>
Sat, 25 Apr 2015 16:39:22 +0000 (18:39 +0200)
Weave/Graphix/Model/IMesh.cpp
Weave/Graphix/Model/IMesh.h
Weave/Graphix/Model/IMetaMesh.cpp
Weave/Graphix/Model/Model.h

index 5a876d0db9a8c99839a213528016adea96061852..ef7bb2f7e2cb670a886b2d6de3b95dca67a1436a 100644 (file)
@@ -32,7 +32,7 @@ IMesh::IMesh(const string& _modelpath, uint _mindex)
 
 }
 
-IMesh::IMesh(const aiMesh* _mesh)
+IMesh::IMesh(const aiMesh* _mesh, mat4* transformation)
 {
 
        float *vertex = nullptr, *normals = nullptr, *uvs = nullptr;
@@ -40,6 +40,8 @@ IMesh::IMesh(const aiMesh* _mesh)
 
        import(_mesh, numvertices, numfaces, vertex, uvs, normals, index);
 
+       modelMat = *transformation;
+
        updateBB(vertex);
 
        genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
@@ -63,8 +65,8 @@ IMesh::~IMesh()
 
 void IMesh::useModelMat(const mat4& _model, Shader* _shader) const
 {
-       Model::useModelMat(_model, _shader);
-//     Model::useModelMat(_model * modelMat, _shader);
+//     Model::useModelMat(_model, _shader);
+       Model::useModelMat(_model * modelMat, _shader);
 }
 
 //void IMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
index fa6c4430f11e9f48daa776e50314b7169f50a933..bf63286f5cef1002d9d5661df8bded79fb2c230b 100644 (file)
@@ -15,7 +15,7 @@ class IMesh : public Model
 {
 public:
        IMesh(const string& modelpath, uint index=0);
-       IMesh(const aiMesh* mesh);
+       IMesh(const aiMesh* mesh, mat4* transformation);
 
        virtual ~IMesh();
 
index f6f7902d7e3b27401866802bde38545550d2fb3c..9f4c84acd4c3348ae8fb2c52668430a2cb752cff 100644 (file)
@@ -13,24 +13,36 @@ 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); //
+       const aiScene* scene = importer.ReadFile("../models/" + _modelpath, aiProcess_GenUVCoords | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType);
        if (!scene)
        {
                Message::error("The file " + _modelpath + " couldn't be read.\n" + importer.GetErrorString());
                return;
        }
 
+       const aiNode* root = scene->mRootNode;
+
        IMesh* tmpIMesh = nullptr;
+       aiMatrix4x4* aimat;
+       mat4 tmpModelMat;
        vec3 tmpMin, tmpMax;
        if (scene->HasMeshes())// && scene->mNumMeshes > mindex)
        {
-               tmpIMesh = new IMesh(scene->mMeshes[0]);
+               aimat = &(root->mChildren[0]->mTransformation);
+
+               tmpModelMat = mat4(aimat->a1, aimat->c1, -aimat->b1, aimat->d1, aimat->a2, aimat->c2, -aimat->b2, aimat->d2, aimat->a3, aimat->c3, -aimat->b3, aimat->d3, aimat->a4, aimat->c4, -aimat->b4, aimat->d4);
+
+               tmpIMesh = new IMesh(scene->mMeshes[0], &tmpModelMat);
                models.push_back(tmpIMesh);
                tmpIMesh->getBBmm(BBmin, BBmax);
 
                for (auto i = 1; i < scene->mNumMeshes; i++)
                {
-                       tmpIMesh = new IMesh(scene->mMeshes[i]);
+                       aimat = &(root->mChildren[i]->mTransformation);
+
+                       tmpModelMat = mat4(aimat->a1, aimat->c1, -aimat->b1, aimat->d1, aimat->a2, aimat->c2, -aimat->b2, aimat->d2, aimat->a3, aimat->c3, -aimat->b3, aimat->d3, aimat->a4, aimat->c4, -aimat->b4, aimat->d4);
+
+                       tmpIMesh = new IMesh(scene->mMeshes[i], &tmpModelMat);
                        models.push_back(tmpIMesh);
                        tmpIMesh->getBBmm(tmpMin, tmpMax);
                        for (auto j = 0; j < 3; ++j)
@@ -87,5 +99,4 @@ void IMetaMesh::drawBBox(Shader* _shader, const mat4& _modelMat) const
                }
        }
 
-}
-
+}
\ No newline at end of file
index ea5645e47a82dda31fd627eb787faa16bdf53a4a..ea2a4a8d2ebedb343d8a0cc8e2bcae5a3c29731b 100644 (file)
@@ -29,6 +29,7 @@ public:
 protected:
        uint numvertices, numfaces;
        uint vertexBuffer, indexBuffer, normalBuffer, uvBuffer;
+       mat4 modelMat;
 
        std::unordered_map<uint, uint> shader_map;