From: LockedLunatic Date: Sat, 25 Apr 2015 16:39:22 +0000 (+0200) Subject: importer improved X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=5188dd9b55e5ed59898478c9f28a4d9cdf9538db;p=cgue_weave.git importer improved --- diff --git a/Weave/Graphix/Model/IMesh.cpp b/Weave/Graphix/Model/IMesh.cpp index 5a876d0..ef7bb2f 100644 --- a/Weave/Graphix/Model/IMesh.cpp +++ b/Weave/Graphix/Model/IMesh.cpp @@ -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 diff --git a/Weave/Graphix/Model/IMesh.h b/Weave/Graphix/Model/IMesh.h index fa6c443..bf63286 100644 --- a/Weave/Graphix/Model/IMesh.h +++ b/Weave/Graphix/Model/IMesh.h @@ -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(); diff --git a/Weave/Graphix/Model/IMetaMesh.cpp b/Weave/Graphix/Model/IMetaMesh.cpp index f6f7902..9f4c84a 100644 --- a/Weave/Graphix/Model/IMetaMesh.cpp +++ b/Weave/Graphix/Model/IMetaMesh.cpp @@ -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 diff --git a/Weave/Graphix/Model/Model.h b/Weave/Graphix/Model/Model.h index ea5645e..ea2a4a8 100644 --- a/Weave/Graphix/Model/Model.h +++ b/Weave/Graphix/Model/Model.h @@ -29,6 +29,7 @@ public: protected: uint numvertices, numfaces; uint vertexBuffer, indexBuffer, normalBuffer, uvBuffer; + mat4 modelMat; std::unordered_map shader_map;