MRPT  2.0.5
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-2020, 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 
15 #include <map>
16 
17 namespace mrpt::opengl
18 {
19 /** This class can load & render 3D models in a number of different formats
20  * (requires the library assimp).
21  * - All supported formats:
22  * http://assimp.sourceforge.net/main_features_formats.html
23  * - Most common ones: AutoCAD DXF ( .dxf ), Collada ( .dae ), Blender 3D (
24  * .blend ), 3ds Max 3DS ( .3ds ), 3ds Max ASE ( .ase ), Quake I ( .mdl ), Quake
25  * II ( .md2 ), Quake III Mesh ( .md3 ), etc.
26  *
27  * Models are loaded via CAssimpModel::loadScene()
28  *
29  * <div align="center">
30  * <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px;
31  * border-style: solid;">
32  * <tr> <td> mrpt::opengl::CAssimpModel </td> <td> \image html
33  * preview_CAssimpModel.png </td> </tr>
34  * </table>
35  * </div>
36  *
37  * \sa opengl::COpenGLScene
38  * \ingroup mrpt_opengl_grp
39  * \note Class introduced in MRPT 1.2.2
40  */
44 {
46 
47  public:
48  /** @name Renderizable shader API virtual methods
49  * @{ */
50  void render(const RenderContext& rc) const override;
51  void renderUpdateBuffers() const override;
52 
53  virtual shader_list_t requiredShaders() const override
54  {
55  // May use up to two shaders (triangles and lines):
58  }
59  void onUpdateBuffers_Wireframe() override;
60  void onUpdateBuffers_Triangles() override;
61  void onUpdateBuffers_Points() override;
62  void onUpdateBuffers_all(); // special case for assimp
63  void freeOpenGLResources() override
64  {
68  }
69  /** @} */
70 
71  CAssimpModel();
72  virtual ~CAssimpModel() override;
73  /** Loads a scene from a file in any supported file.
74  * \exception std::runtime_error On any error during loading or importing
75  * the file.
76  */
77  void loadScene(const std::string& file_name);
78 
79  /** Empty the object */
80  void clear();
81 
82  /* Simulation of ray-trace. */
83  bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const override;
84 
85  void getBoundingBox(
87  mrpt::math::TPoint3D& bb_max) const override;
88 
89  /* Disabled for now (port to OpenGL3, March 2020)
90  struct TInfoPerTexture
91  {
92  // indices in \a m_textureIds. string::npos for non-initialized ones
93  size_t id_idx;
94  mrpt::img::CImage::Ptr img_rgb, img_alpha;
95  TInfoPerTexture() : id_idx(std::string::npos) {}
96  };
97  */
98 
99  private:
100  /** A container for automatic deletion of assimp scene when the last
101  * reference of the smart_ptr's is destroyed.
102  */
103  struct TImplAssimp
104  {
105  TImplAssimp();
106  ~TImplAssimp();
107  /** aiScene* */
108  void* scene = nullptr;
109  };
111 
112  /** Bounding box */
114 
115  std::string m_modelPath;
116 
117  // mutable std::vector<unsigned int> m_textureIds;
118  // mutable bool m_textures_loaded{false};
119  // mutable std::map<std::string, TInfoPerTexture> m_textureIdMap;
120 
121 }; // namespace mrpt::opengl
122 
123 } // namespace mrpt::opengl
void freeOpenGLResources() override
Free opengl buffers.
void freeOpenGLResources() override
Free opengl buffers.
Definition: CAssimpModel.h:63
void onUpdateBuffers_Triangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
void onUpdateBuffers_Points() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Renderizable generic renderer for objects using the triangles shader.
void freeOpenGLResources() override
Free opengl buffers.
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:113
std::vector< shader_id_t > shader_list_t
A list of shader IDs.
Definition: Shader.h:26
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
Context for calls to render()
void onUpdateBuffers_Wireframe() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
mrpt::math::TPoint3D m_bbox_max
Definition: CAssimpModel.h:113
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.
static constexpr shader_id_t WIREFRAME
virtual ~CAssimpModel() override
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
Renderizable generic renderer for objects using the points shader.
static constexpr shader_id_t TRIANGLES
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
Renderizable generic renderer for objects using the wireframe shader.
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
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 freeOpenGLResources() override
Free opengl buffers.
virtual shader_list_t requiredShaders() const override
Returns the ID of the OpenGL shader program required to render this class.
Definition: CAssimpModel.h:53
A container for automatic deletion of assimp scene when the last reference of the smart_ptr&#39;s is dest...
Definition: CAssimpModel.h:103
This class can load & render 3D models in a number of different formats (requires the library assimp)...
Definition: CAssimpModel.h:41
static constexpr shader_id_t POINTS
std::shared_ptr< TImplAssimp > m_assimp_scene
Definition: CAssimpModel.h:110



Page generated by Doxygen 1.8.14 for MRPT 2.0.5 Git: b26ce1112 Mon Jul 6 09:39:08 2020 +0200 at lun jul 6 09:45:13 CEST 2020