process model aabb

This commit is contained in:
2024-04-13 09:46:21 +02:00
parent d13030fbb0
commit ed3322f256
2 changed files with 14 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
#pragma once
#include "blitz/maths/Physics.h"
#include "client/render/loader/GLLoader.h"
#include <memory>
#include <string>
@@ -12,6 +13,7 @@ typedef std::unique_ptr<GL::VertexArray> VaoPtr;
struct Model {
std::vector<VaoPtr> mVaos;
std::vector<maths::AABB> mAABBs;
};
Model LoadModel(const std::string& fileName);

View File

@@ -82,15 +82,19 @@ static VaoPtr ProcessMesh(aiMesh* mesh, const aiScene* scene, const aiMatrix4x4&
return Vao;
}
static void ProcessNode(aiNode* node, const aiScene* scene, std::vector<VaoPtr>& meshes, const aiMatrix4x4& transform) {
static void ProcessNode(
aiNode* node, const aiScene* scene, std::vector<VaoPtr>& meshes, std::vector<maths::AABB>& aabbs, const aiMatrix4x4& transform) {
// recursive
for (unsigned int i = 0; i < node->mNumChildren; i++) {
ProcessNode(node->mChildren[i], scene, meshes, transform * node->mTransformation);
ProcessNode(node->mChildren[i], scene, meshes, aabbs, transform * node->mTransformation);
}
for (unsigned int i = 0; i < node->mNumMeshes; i++) {
aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
meshes.push_back(ProcessMesh(mesh, scene, transform * node->mTransformation));
aiAABB& aabb = mesh->mAABB;
aabbs.push_back({Vec3f{aabb.mMin.x, aabb.mMin.y, aabb.mMin.z}, {aabb.mMax.x, aabb.mMax.y, aabb.mMax.z}});
}
}
@@ -101,17 +105,20 @@ Model LoadModel(const std::string& fileName) {
const aiScene* scene = importer.ReadFileFromMemory(fileData.data(), fileData.GetSize(),
aiProcess_CalcTangentSpace | aiProcess_Triangulate | aiProcess_SortByPType | aiProcess_OptimizeGraph |
aiProcess_OptimizeMeshes);
aiProcess_OptimizeMeshes | aiProcess_GenBoundingBoxes);
if (nullptr == scene) {
utils::LOGE("[ModelLoader] Failed to load model !");
return {};
}
utils::LOGD(utils::Format("[ModelLoader]\tModel nodes : %i", scene->mRootNode->mNumMeshes));
utils::LOGD(utils::Format("[ModelLoader]\tModel nodes : %i", scene->mRootNode->mNumChildren));
Model model;
ProcessNode(scene->mRootNode, scene, model.mVaos, {});
ProcessNode(scene->mRootNode, scene, model.mVaos, model.mAABBs, {});
utils::LOGD(utils::Format("[ModelLoader]\tAABB count : %i", model.mAABBs.size()));
return model;
}