MRPT  1.9.9
CAssimpModel.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
13 #include <map>
14 
15 namespace mrpt::opengl
16 {
17 /** This class can load & render 3D models in a number of different formats
18  * (requires the library assimp).
19  * - All supported formats:
20  * http://assimp.sourceforge.net/main_features_formats.html
21  * - Most common ones: AutoCAD DXF ( .dxf ), Collada ( .dae ), Blender 3D (
22  * .blend ), 3ds Max 3DS ( .3ds ), 3ds Max ASE ( .ase ), Quake I ( .mdl ), Quake
23  * II ( .md2 ), Quake III Mesh ( .md3 ), etc.
24  *
25  * Models are loaded via CAssimpModel::loadScene()
26  *
27  * <div align="center">
28  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
29  * border-style: solid;">
30  * <tr> <td> mrpt::opengl::CAssimpModel </td> <td> \image html
31  * preview_CAssimpModel.png </td> </tr>
32  * </table>
33  * </div>
34  *
35  * \sa opengl::COpenGLScene
36  * \ingroup mrpt_opengl_grp
37  * \note Class introduced in MRPT 1.2.2
38  */
40 {
42 
43  public:
44  /** Render child objects */
45  void render_dl() const override;
46 
47  /** Evaluates the bounding box of this object (including possible children)
48  * in the coordinate frame of the object parent. */
49  void getBoundingBox(
51  mrpt::math::TPoint3D& bb_max) const override;
52 
53  /** Loads a scene from a file in any supported file.
54  * \exception std::runtime_error On any error during loading or importing
55  * the file.
56  */
57  void loadScene(const std::string& file_name);
58 
59  /** Empty the object */
60  void clear();
61 
62  /** Evaluates the scene at a given animation time */
63  void evaluateAnimation(double time_anim);
64 
65  /* Simulation of ray-trace. */
66  bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const override;
67 
69  {
70  /** indices in \a m_textureIds. string::npos for non-initialized ones.
71  */
72  size_t id_idx;
74  TInfoPerTexture() : id_idx(std::string::npos) {}
75  };
76 
77  CAssimpModel();
78  /** Private, virtual destructor: only can be deleted from smart pointers */
79  ~CAssimpModel() override;
80 
81  private:
82  /** A container for automatic deletion of assimp scene when the last
83  * reference of the smart_ptr's is destroyed.
84  */
85  struct TImplAssimp
86  {
87  TImplAssimp();
88  ~TImplAssimp();
89  /** aiScene* */
90  void* scene{nullptr};
91  };
93 
94  /** Bounding box */
96 
97  mutable bool m_textures_loaded{false};
98  std::string m_modelPath;
99  mutable std::vector<unsigned int> m_textureIds;
100 
101  mutable std::map<std::string, TInfoPerTexture> m_textureIdMap;
102 };
103 
104 } // namespace mrpt::opengl
size_t id_idx
indices in m_textureIds.
Definition: CAssimpModel.h:72
void evaluateAnimation(double time_anim)
Evaluates the scene at a given animation time.
STL namespace.
void loadScene(const std::string &file_name)
Loads a scene from a file in any supported file.
mrpt::math::TPoint3D m_bbox_min
Bounding box.
Definition: CAssimpModel.h:95
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
A renderizable object suitable for rendering with OpenGL&#39;s display lists.
std::map< std::string, TInfoPerTexture > m_textureIdMap
Definition: CAssimpModel.h:101
mrpt::math::TPoint3D m_bbox_max
Definition: CAssimpModel.h:95
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const override
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
void clear()
Empty the object.
~CAssimpModel() override
Private, virtual destructor: only can be deleted from smart pointers.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
const auto bb_max
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
const auto bb_min
void render_dl() const override
Render child objects.
A container for automatic deletion of assimp scene when the last reference of the smart_ptr&#39;s is dest...
Definition: CAssimpModel.h:85
This class can load & render 3D models in a number of different formats (requires the library assimp)...
Definition: CAssimpModel.h:39
std::vector< unsigned int > m_textureIds
Definition: CAssimpModel.h:99
std::shared_ptr< TImplAssimp > m_assimp_scene
Definition: CAssimpModel.h:92



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 338471620 Mon Feb 17 00:12:39 2020 +0100 at lun feb 17 00:15:10 CET 2020