}
-IMesh::IMesh(const aiMesh* _mesh)
+IMesh::IMesh(const aiMesh* _mesh, mat4* transformation)
{
float *vertex = nullptr, *normals = nullptr, *uvs = nullptr;
import(_mesh, numvertices, numfaces, vertex, uvs, normals, index);
+ modelMat = *transformation;
+
updateBB(vertex);
genBuffer(vertexBuffer, numvertices * 3 * sizeof(float), (void*)vertex);
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
{
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)
}
}
-}
-
+}
\ No newline at end of file