MRPT  2.0.3
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  };
110  std::shared_ptr<TImplAssimp> m_assimp_scene;
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
mrpt::opengl::CAssimpModel::m_bbox_max
mrpt::math::TPoint3D m_bbox_max
Definition: CAssimpModel.h:113
mrpt::opengl::CAssimpModel::onUpdateBuffers_Points
void onUpdateBuffers_Points() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CAssimpModel.cpp:129
mrpt::opengl::CAssimpModel::onUpdateBuffers_all
void onUpdateBuffers_all()
Definition: CAssimpModel.cpp:94
mrpt::math::TPoint3D_< double >
DEFINE_SERIALIZABLE
#define DEFINE_SERIALIZABLE(class_name, NS)
This declaration must be inserted in all CSerializable classes definition, within the class declarati...
Definition: CSerializable.h:152
mrpt::opengl::CAssimpModel::TImplAssimp::TImplAssimp
TImplAssimp()
mrpt::opengl::CAssimpModel::onUpdateBuffers_Triangles
void onUpdateBuffers_Triangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CAssimpModel.cpp:130
mrpt::opengl::CAssimpModel
This class can load & render 3D models in a number of different formats (requires the library assimp)...
Definition: CAssimpModel.h:41
mrpt::opengl::CAssimpModel::freeOpenGLResources
void freeOpenGLResources() override
Free opengl buffers.
Definition: CAssimpModel.h:63
mrpt::opengl::CAssimpModel::m_modelPath
std::string m_modelPath
Definition: CAssimpModel.h:115
mrpt::opengl::CRenderizableShaderWireFrame
Renderizable generic renderer for objects using the wireframe shader.
Definition: CRenderizableShaderWireFrame.h:24
mrpt::opengl::CAssimpModel::onUpdateBuffers_Wireframe
void onUpdateBuffers_Wireframe() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
Definition: CAssimpModel.cpp:128
mrpt::opengl::CRenderizableShaderTriangles::freeOpenGLResources
void freeOpenGLResources() override
Free opengl buffers.
Definition: CRenderizableShaderTriangles.h:45
mrpt::opengl::CAssimpModel::renderUpdateBuffers
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers,...
Definition: CAssimpModel.cpp:82
mrpt::opengl::CRenderizableShaderWireFrame::freeOpenGLResources
void freeOpenGLResources() override
Free opengl buffers.
Definition: CRenderizableShaderWireFrame.h:57
mrpt::opengl::CAssimpModel::TImplAssimp::~TImplAssimp
~TImplAssimp()
Definition: CAssimpModel.cpp:241
mrpt::opengl::CAssimpModel::TImplAssimp
A container for automatic deletion of assimp scene when the last reference of the smart_ptr's is dest...
Definition: CAssimpModel.h:103
mrpt::opengl::CAssimpModel::m_assimp_scene
std::shared_ptr< TImplAssimp > m_assimp_scene
Definition: CAssimpModel.h:110
CRenderizableShaderTriangles.h
bb_max
const auto bb_max
Definition: CPose3DPDFGrid_unittest.cpp:25
mrpt::opengl::DefaultShaderID::WIREFRAME
static constexpr shader_id_t WIREFRAME
Definition: DefaultShaders.h:25
bb_min
const auto bb_min
Definition: CPose3DPDFGrid_unittest.cpp:23
mrpt::opengl::DefaultShaderID::TRIANGLES
static constexpr shader_id_t TRIANGLES
Definition: DefaultShaders.h:27
mrpt::opengl::CAssimpModel::getBoundingBox
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...
Definition: CAssimpModel.cpp:229
COpenGLScene.h
mrpt::opengl::CAssimpModel::CAssimpModel
CAssimpModel()
Definition: CAssimpModel.cpp:171
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
CRenderizableShaderWireFrame.h
mrpt::opengl::CAssimpModel::TImplAssimp::scene
void * scene
aiScene*
Definition: CAssimpModel.h:108
mrpt::opengl::CAssimpModel::~CAssimpModel
virtual ~CAssimpModel() override
Definition: CAssimpModel.cpp:176
mrpt::opengl::CRenderizable::RenderContext
Context for calls to render()
Definition: CRenderizable.h:266
mrpt::opengl::CRenderizableShaderPoints::freeOpenGLResources
void freeOpenGLResources() override
Free opengl buffers.
Definition: CRenderizableShaderPoints.h:86
mrpt::opengl::CAssimpModel::traceRay
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
Definition: CAssimpModel.cpp:255
mrpt::opengl::CAssimpModel::requiredShaders
virtual shader_list_t requiredShaders() const override
Returns the ID of the OpenGL shader program required to render this class.
Definition: CAssimpModel.h:53
CRenderizableShaderPoints.h
mrpt::opengl::CRenderizableShaderPoints
Renderizable generic renderer for objects using the points shader.
Definition: CRenderizableShaderPoints.h:38
mrpt::opengl::shader_list_t
std::vector< shader_id_t > shader_list_t
A list of shader IDs.
Definition: Shader.h:26
mrpt::opengl::CRenderizableShaderTriangles
Renderizable generic renderer for objects using the triangles shader.
Definition: CRenderizableShaderTriangles.h:25
mrpt::opengl::CAssimpModel::clear
void clear()
Empty the object.
Definition: CAssimpModel.cpp:180
mrpt::opengl::CAssimpModel::m_bbox_min
mrpt::math::TPoint3D m_bbox_min
Bounding box.
Definition: CAssimpModel.h:113
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
mrpt::opengl::DefaultShaderID::POINTS
static constexpr shader_id_t POINTS
Definition: DefaultShaders.h:24
mrpt::opengl::CAssimpModel::loadScene
void loadScene(const std::string &file_name)
Loads a scene from a file in any supported file.
Definition: CAssimpModel.cpp:199
mrpt::opengl::CAssimpModel::render
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
Definition: CAssimpModel.cpp:67



Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Fri May 15 15:49:54 UTC 2020