Class CAssimpModel
Defined in File CAssimpModel.h
Nested Relationships
Nested Types
Inheritance Relationships
Base Type
public mrpt::viz::CSetOfObjects(Class CSetOfObjects)
Derived Type
public mrpt::viz::CAnimatedAssimpModel(Class CAnimatedAssimpModel)
Class Documentation
-
class CAssimpModel : public mrpt::viz::CSetOfObjects
This class can load & render 3D models in a number of different formats (requires the library assimp).
Supported formats (via Assimp library): http://assimp.sourceforge.net/main_features_formats.html
Most common ones: AutoCAD DXF (.dxf), Collada (.dae), Blender 3D (.blend), 3ds Max 3DS (.3ds), 3ds Max ASE (.ase), Quake I (.mdl), Quake II (.md2), Quake III Mesh (.md3), Wavefront OBJ (.obj), Stanford PLY (.ply), glTF (.gltf, .glb), FBX (.fbx), etc.
Models are loaded via CAssimpModel::loadScene()
Architecture (MRPT 3.0):
This class is part of mrpt::viz (no OpenGL dependencies)
It loads 3D models using Assimp and converts them to mrpt::viz primitives
Textured meshes become CSetOfTexturedTriangles children
Non-textured meshes become triangle data (VisualObjectParams_Triangles)
Point clouds become point data (VisualObjectParams_Points)
Wireframe elements become line data (VisualObjectParams_Lines)
The class is a CSetOfObjects container that holds:
One CSetOfTexturedTriangles per texture used in the model
One CSetOfTriangles for all non-textured triangles
Additional child objects for points and lines if present

See also
Subclassed by mrpt::viz::CAnimatedAssimpModel
Model Loading
-
void loadScene(const std::string &file_name, int flags = LoadFlags::RealTimeMaxQuality | LoadFlags::FlipUVs | LoadFlags::Verbose)
Loads a 3D scene from a file in any Assimp-supported format.
This clears any previously loaded content and populates this object with the loaded model’s geometry, materials, and textures.
Example:
CAssimpModel model; model.loadScene("robot.dae", CAssimpModel::LoadFlags::RealTimeMaxQuality); scene->insert(model);
Note
Textures are loaded from paths relative to the model file’s directory
- Parameters:
file_name – Path to the 3D model file
flags – Combination of LoadFlags values (OR’d together)
- Throws:
std::runtime_error – On any error during loading or importing
-
void clear()
Clear the loaded model and all child objects
-
inline const std::string &getModelPath() const
Returns the path of the currently loaded model, or empty string if none
-
inline uint32_t getModelLoadFlags() const
Returns the flags used when loading the current model
Rendering Options
-
void setSplitTrianglesRenderingBBox(float bbox_size)
Enable (or disable if set to 0.0f) splitting of textured triangles into separate renderable objects based on spatial bounding boxes.
This is required only for semi-transparent objects with overlapping regions, to ensure correct depth sorting during rendering.
- Parameters:
bbox_size – Size of the bounding box for splitting (0.0 = disabled)
-
inline float getSplitTrianglesRenderingBBox() const
Returns the current triangle splitting bbox size (0.0 = disabled)
Model Information
-
inline size_t getTexturedMeshCount() const
Returns the number of textured mesh groups in the loaded model
-
size_t getNonTexturedTriangleCount() const
Returns the number of non-textured triangles in the model
-
size_t getTotalVertexCount() const
Returns the total vertex count across all meshes
-
size_t getTotalTriangleCount() const
Returns the total triangle count across all meshes
-
std::vector<TextureInfo> getTextureInfo() const
Returns information about all textures in the model
CVisualObject Interface
-
virtual mrpt::math::TBoundingBoxf internalBoundingBoxLocal() const override
Must be implemented by derived classes to provide the updated bounding box in the object local frame of coordinates. This will be called only once after each time the derived class reports to notifyChange() that the object geometry changed.
See also
getBoundingBox(), getBoundingBoxLocal(), getBoundingBoxLocalf()
-
virtual bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose. Returns true if the ray effectively collisions with the object (returning the distance to the origin of the ray in “dist”), or false in other case. “dist” variable yields undefined behaviour when false is returned
Public Functions
-
CAssimpModel()
-
~CAssimpModel() override
-
CAssimpModel(CAssimpModel&&) noexcept
-
CAssimpModel &operator=(CAssimpModel&&) noexcept
Protected Functions
-
const void *getAssimpScenePtr() const
Access to the internal Assimp scene (for subclasses like CAnimatedAssimpModel). Returns nullptr if no scene is loaded or Assimp is not available.
-
void rebuildFromAssimpScene()
Re-process the loaded Assimp scene, rebuilding all child viz objects. Useful for subclasses that modify the aiScene data (e.g. skinning).
-
struct LoadFlags
Import flags for loadScene.
These can be OR’d together. See Assimp documentation for details.
Note
Not defined as
enum classto allow C++-valid or-wise combinationsPublic Types
-
enum flags_t
Values:
-
enumerator RealTimeFast
See: aiProcessPreset_TargetRealtime_Fast Basic optimizations, fast loading.
-
enumerator RealTimeQuality
See: aiProcessPreset_TargetRealtime_Quality Good balance of quality and speed.
-
enumerator RealTimeMaxQuality
See: aiProcessPreset_TargetRealtime_MaxQuality Maximum quality, slower loading.
-
enumerator FlipUVs
See: aiProcess_FlipUVs Flip texture V coordinates (needed for some formats).
-
enumerator IgnoreMaterialColor
MRPT-specific: ignore material colors from the file and use the base class CVisualObject uniform color instead. Useful when you want to override the model’s colors.
Note
(New in MRPT 2.5.0)
-
enumerator IgnoreTextures
MRPT-specific: ignore textures from the file. The model will be rendered with solid colors only.
Note
(New in MRPT 3.0.0)
-
enumerator Verbose
Displays verbose messages during loading (textures, meshes, etc.)
-
enumerator RealTimeFast
-
enum flags_t
-
struct TextureInfo
Information about a texture used in the model