Assimp Hacks 2: Get the bounding boxes from your meshes
Nov 8, 2022
What is the problem?
After importing a model you want to get teh bounding boxes from your meshes. This is important for picking, rendering, partitioning or just for doing some basic frustum culling
How to solve it!
There is a post-processing step for that. After importing your model you can get an axis-aligned bounding box for each mesh for itself. Just try the following code:
#include <assimp/Importer.hpp>
::Assimp::Importer importer;
const aiScene *scene = importer.import("testmodel.obj", aiProcess_GenBoundingBoxes);
const aabb &aabb = scene->mMeshes[0]->mAABB;
The axis-aligned bounding box will store the minimum and maximum coordinates for your mesh:
struct aiAABB {
aiVector3D mMin; // <- the minimum edge
aiVector3D mMax; // <- the maximum edge
};
Home that is useful for you.