|
| 1 | +/* +------------------------------------------------------------------------+ |
| 2 | + | Mobile Robot Programming Toolkit (MRPT) | |
| 3 | + | https://www.mrpt.org/ | |
| 4 | + | | |
| 5 | + | Copyright (c) 2005-2024, 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 | + |
| 11 | +#include <mrpt/img/CImage.h> |
| 12 | +#include <mrpt/viz/CVisualObject.h> |
| 13 | + |
| 14 | +#include <map> |
| 15 | +#include <optional> |
| 16 | + |
| 17 | +namespace mrpt::viz |
| 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 | + *  |
| 30 | + * |
| 31 | + * \sa opengl::Scene |
| 32 | + * \ingroup mrpt_viz_grp |
| 33 | + */ |
| 34 | +class CAssimpModel : public CVisualObject |
| 35 | +{ |
| 36 | + DEFINE_SERIALIZABLE(CAssimpModel, mrpt::viz) |
| 37 | + |
| 38 | + public: |
| 39 | + CAssimpModel(); |
| 40 | + virtual ~CAssimpModel() override; |
| 41 | + |
| 42 | + /** Import flags for loadScene |
| 43 | + * \note Not defined as ``enum class`` to allow C++-valid or-wise combinations |
| 44 | + */ |
| 45 | + struct LoadFlags |
| 46 | + { |
| 47 | + enum flags_t : uint32_t |
| 48 | + { |
| 49 | + /** See: aiProcessPreset_TargetRealtime_Fast */ |
| 50 | + RealTimeFast = 0x0001, |
| 51 | + |
| 52 | + /** See: aiProcessPreset_TargetRealtime_Quality */ |
| 53 | + RealTimeQuality = 0x0002, |
| 54 | + |
| 55 | + /** See: aiProcessPreset_TargetRealtime_MaxQuality */ |
| 56 | + RealTimeMaxQuality = 0x0004, |
| 57 | + |
| 58 | + /** See: aiProcess_FlipUVs */ |
| 59 | + FlipUVs = 0x0010, |
| 60 | + |
| 61 | + /** MRPT-specific: ignore materials and replace by the base class |
| 62 | + CRenderizable uniform color that was defined before calling |
| 63 | + loadScene(). \note (New in MRPT 2.5.0) */ |
| 64 | + IgnoreMaterialColor = 0x0100, |
| 65 | + |
| 66 | + /** Displays messages on loaded textures, etc. */ |
| 67 | + Verbose = 0x1000 |
| 68 | + }; |
| 69 | + }; |
| 70 | + |
| 71 | + using filepath_t = std::string; |
| 72 | + |
| 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( |
| 78 | + const std::string& file_name, |
| 79 | + const int flags = LoadFlags::RealTimeMaxQuality | LoadFlags::FlipUVs | LoadFlags::Verbose); |
| 80 | + |
| 81 | + /** Empty the object */ |
| 82 | + void clear(); |
| 83 | + |
| 84 | + /* Simulation of ray-trace. */ |
| 85 | + bool traceRay(const mrpt::poses::CPose3D& o, double& dist) const override; |
| 86 | + |
| 87 | + mrpt::math::TBoundingBoxf internalBoundingBoxLocal() const override; |
| 88 | + |
| 89 | + /** Enable (or disable if set to .0f) a feature in which textured triangles |
| 90 | + * are split into different renderizable smaller objects. |
| 91 | + * This is required only for semitransparent objects with overlaping regions. |
| 92 | + */ |
| 93 | + void split_triangles_rendering_bbox(const float bbox_size); |
| 94 | + |
| 95 | + [[nodiscard]] float split_triangles_rendering_bbox() const |
| 96 | + { |
| 97 | + return m_split_triangles_rendering_bbox; |
| 98 | + } |
| 99 | + |
| 100 | + private: |
| 101 | + filepath_t m_modelPath; |
| 102 | + uint32_t m_modelLoadFlags = 0; |
| 103 | + float m_split_triangles_rendering_bbox = .0f; |
| 104 | +}; |
| 105 | + |
| 106 | +} // namespace mrpt::viz |
0 commit comments