ModelsCache.cpp
Go to the documentation of this file.
1 /*+-------------------------------------------------------------------------+
2  | MultiVehicle simulator (libmvsim) |
3  | |
4  | Copyright (C) 2014-2024 Jose Luis Blanco Claraco |
5  | Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6  | Distributed under 3-clause BSD License |
7  | See COPYING |
8  +-------------------------------------------------------------------------+ */
9 
10 #include "ModelsCache.h"
11 
12 #include <mrpt/core/get_env.h>
13 #include <mrpt/system/filesystem.h>
14 #include <mrpt/version.h>
15 
16 #include <cstdlib>
17 #include <cstring>
18 
19 using namespace mvsim;
20 
22 {
23  static ModelsCache o;
24  return o;
25 }
26 
27 mrpt::opengl::CAssimpModel::Ptr ModelsCache::get(
28  const std::string& localFileName, const Options& options)
29 {
30  // already cached?
31  if (auto it = cache.find(localFileName); it != cache.end()) return it->second;
32 
33  // No, it's a new model path, create its placeholder:
34  auto m = cache[localFileName] = mrpt::opengl::CAssimpModel::Create();
35 
36  ASSERT_FILE_EXISTS_(localFileName);
37 
38  // En/Dis-able the extra verbosity while loading the 3D model:
39  int loadFlags = mrpt::opengl::CAssimpModel::LoadFlags::RealTimeMaxQuality |
40  mrpt::opengl::CAssimpModel::LoadFlags::FlipUVs;
41 
42  if (options.modelColor != mrpt::img::TColor::white())
43  loadFlags |= mrpt::opengl::CAssimpModel::LoadFlags::IgnoreMaterialColor;
44 
45  m->setColor_u8(options.modelColor);
46 
47  if (mrpt::get_env<bool>("MVSIM_LOAD_MODELS_VERBOSE", false))
48  loadFlags |= mrpt::opengl::CAssimpModel::LoadFlags::Verbose;
49 
50  m->loadScene(localFileName, loadFlags);
51 
52  m->cullFaces(mrpt::typemeta::TEnumType<mrpt::opengl::TCullFace>::name2value(options.modelCull));
53 
54 #if MRPT_VERSION >= 0x20e01 // Feature added in MRPT 2.14.1
55  m->split_triangles_rendering_bbox(options.splitSize);
56 #endif
57 
58  return m;
59 }
mvsim
Definition: Client.h:21
mvsim::ModelsCache::Options::modelColor
mrpt::img::TColor modelColor
Definition: ModelsCache.h:23
mvsim::ModelsCache
Definition: ModelsCache.h:16
mvsim::ModelsCache::Options
Definition: ModelsCache.h:21
ModelsCache.h
mvsim::ModelsCache::cache
std::map< std::string, mrpt::opengl::CAssimpModel::Ptr > cache
Definition: ModelsCache.h:41
mvsim::ModelsCache::get
mrpt::opengl::CAssimpModel::Ptr get(const std::string &url, const Options &options)
Definition: ModelsCache.cpp:27
mvsim::ModelsCache::Options::modelCull
std::string modelCull
Definition: ModelsCache.h:24
mvsim::ModelsCache::Instance
static ModelsCache & Instance()
Definition: ModelsCache.cpp:21
mvsim::ModelsCache::Options::splitSize
float splitSize
Definition: ModelsCache.h:30


mvsim
Author(s):
autogenerated on Wed May 28 2025 02:13:08