Conscience Core
CscEntityModelGlTFLoader.h
Go to the documentation of this file.
1 #ifndef CscEntityModelGlTFLoader_h
2 #define CscEntityModelGlTFLoader_h
3 
6 #include "CscCommon.h"
7 #include "CscGlTFParser.h"
8 
9 #define CONSCIENCE_NODE_PREFIX "Conscience_"
10 #define CONSCIENCE_NODE_PREFIX_COMPRESSED "CS_"
11 
13 
20 
21 public:
23  CscEntityModel *parseFromPath(const fs::path &filePath);
24 
25 private:
26  unique_ptr<CscLogger> logger = CscLogger::getForCategory("CscEntityModelGlTFLoader");
27  CscGlTFParser *parser = nullptr;
28 
29  template <class TOutputData>
30  void createAndAddOutputs(CscGlTFParser &parser, const string &nodeType, vector<TOutputData *> &dataList, GltfParseContext &context) {
31 
32  string fullPrefix = string(CONSCIENCE_NODE_PREFIX) + nodeType + "_";
33  string compressedPrefix = string(CONSCIENCE_NODE_PREFIX_COMPRESSED) + nodeType.substr(0, 2) + "_";
34  vector<pair<unsigned, CscJsonObjectReader *>> nodesJson = parser.findNodesStartingBy(context, {fullPrefix, compressedPrefix});
35  parser.sortByName(nodesJson);
36 
37  LOGGER_INFO("Nb " + nodeType + "s : " + to_string(nodesJson.size()));
38  for (int i = 0; i < nodesJson.size(); i++) {
39  LOGGER_INFO(nodeType + " #" + to_string(i));
40 
41  unsigned nodeIndex = nodesJson.at(i).first;
42  CscJsonObjectReader * nodeJson = nodesJson.at(i).second;
43 
44  string searchName = nodeJson->getStringValue("name").value_or("");
45  if (searchName == "") {
46  // Gérer le cas où la clé "name" n'existe pas
47  LOGGER_ERROR("Key 'name' not found in node " + nodeType + " at index " + to_string(i));
48  continue;
49  }
50  auto prefixEndPos = searchName.find("_", searchName.find("_") + 1);
51  if (prefixEndPos != string::npos) {
52  searchName.replace(0, prefixEndPos + 1, fullPrefix);
53  }
54 
55  vector<string> *nodeNameTokens = splitString(searchName, "_");
56 
57  BoundingBox globalBBox;
58  parser.computeBoundingBoxAndVerticesAndPolygons(context, globalBBox, false, nullptr, nullptr, nodeIndex, *nodeJson);
59  double width = globalBBox.max.x - globalBBox.min.x;
60  double height = globalBBox.max.y - globalBBox.min.y;
61  double length = globalBBox.max.z - globalBBox.min.z;
62  LOGGER_INFO("Bounding Box for " + searchName + " : width = " + to_string(width) + " , height = " + to_string(height) + " , length = " + to_string(length));
63 
64  int outputId = stoi(nodeNameTokens->at(2));
65  string pureNameIn = "Conscience_" + nodeType + "_" + to_string(outputId);
66 
67  auto temp = new TOutputData(
68  outputId, searchName,
69  new CscPoint3d(globalBBox.min.x, globalBBox.min.y, globalBBox.min.z),
70  new CscPoint3d(globalBBox.max.x, globalBBox.max.y, globalBBox.max.z));
71  dataList.push_back(temp);
72 
73  delete nodeNameTokens;
74  }
75  }
76 };
77 
78 }
79 
80 #endif
conscience_core::axiomes::Vec3::x
double x
Definition: Csc3dTypes.h:368
nlohmann::to_string
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition: json.hpp:26470
conscience_core::core_objects::exchange::gltf::BoundingBox
Definition: CscGlTFParser.h:57
conscience_core::axiomes::CscPoint3d
The CscPoint3d class represents a point in three-dimensional space. It is primarily used to denote a ...
Definition: Csc3dTypes.h:24
conscience_core::core_objects::exchange::gltf::CscGlTFParser::computeBoundingBoxAndVerticesAndPolygons
void computeBoundingBoxAndVerticesAndPolygons(GltfParseContext &context, BoundingBox &globalBBox, bool collectVerticesAndPolygons, vector< const CscPoint3d * > *vertices, vector< const CscPolygon * > *polygons, unsigned nodeIndex, CscJsonObjectReader &node)
Definition: CscGlTFParser.cpp:513
conscience_core::core_objects::exchange::gltf::CscGlTFParser::sortByName
void sortByName(vector< pair< unsigned, CscJsonObjectReader * >> &nodes)
Definition: CscGlTFParser.cpp:589
CscEntityModel
Definition: CscEntityModel.h:54
conscience_core::core_objects::exchange::gltf::BoundingBox::min
Vec3 min
Definition: CscGlTFParser.h:58
conscience_utils::splitString
vector< string > * splitString(const string &inputString, const string &delimiter, bool escapeDelimiterWithBackslash)
Definition: conscience_util.cpp:235
conscience_core::core_objects::exchange::gltf::GltfParseContext
Definition: CscGlTFParser.h:28
conscience_core::core_objects::exchange::gltf::CscEntityModelGlTFLoader::CscEntityModelGlTFLoader
CscEntityModelGlTFLoader()
Definition: CscEntityModelGlTFLoader.cpp:34
CscGlTFParser.h
conscience_core::core_objects::exchange::gltf::CscEntityModelGlTFLoader::parseFromPath
CscEntityModel * parseFromPath(const fs::path &filePath)
Definition: CscEntityModelGlTFLoader.cpp:39
CONSCIENCE_NODE_PREFIX_COMPRESSED
#define CONSCIENCE_NODE_PREFIX_COMPRESSED
Definition: CscEntityModelGlTFLoader.h:10
conscience_core::core_objects::exchange::gltf::CscGlTFParser
Definition: CscGlTFParser.h:73
conscience_core::core_objects::exchange::gltf::BoundingBox::max
Vec3 max
Definition: CscGlTFParser.h:59
conscience_core::core_objects::exchange::gltf::CscGlTFParser::findNodesStartingBy
vector< pair< unsigned, CscJsonObjectReader * > > findNodesStartingBy(GltfParseContext &context, const vector< string > &searchNamePrefixes)
Definition: CscGlTFParser.cpp:523
conscience_core::core_objects::exchange::gltf
Definition: CscEntityModelGlTFLoader.cpp:32
CscCommon.h
LOGGER_INFO
#define LOGGER_INFO(message)
Definition: conscience_log.h:199
conscience_core::axiomes::Vec3::y
double y
Definition: Csc3dTypes.h:368
CONSCIENCE_NODE_PREFIX
#define CONSCIENCE_NODE_PREFIX
Definition: CscEntityModelGlTFLoader.h:9
CscEntityModel.h
conscience_utils::JSON::CscJsonObjectReader
Definition: json.h:100
LOGGER_ERROR
#define LOGGER_ERROR(message)
Definition: conscience_log.h:201
conscience_core::core_objects::exchange::gltf::CscEntityModelGlTFLoader
Definition: CscEntityModelGlTFLoader.h:19
conscience_utils::JSON::CscJsonObjectReader::getStringValue
optional< string > getStringValue(const string &key)
Definition: json.cpp:206
CscEntityModelData.h
conscience_core::axiomes::Vec3::z
double z
Definition: Csc3dTypes.h:368
i
int i
Definition: HybridAStar.cpp:191