TDME2  1.9.200
ModelReader.cpp
Go to the documentation of this file.
2 
3 #include <memory>
4 #include <string>
5 #include <vector>
6 
7 #include <tdme/tdme.h>
17 #include <tdme/utilities/Console.h>
20 
21 using std::make_unique;
22 using std::string;
23 using std::unique_ptr;
24 using std::vector;
25 
39 
40 vector<string> ModelReader::extensions = {"dae", "glb", "gltf", "tm", "tmodel"};
41 
42 const vector<string>& ModelReader::getModelExtensions() {
43  return extensions;
44 }
45 
46 Model* ModelReader::read(const string& pathName, const string& fileName, bool useBC7TextureCompression)
47 {
48  try {
49  if (StringTools::endsWith(StringTools::toLowerCase(fileName), ".dae") == true) {
50  return DAEReader::read(pathName, fileName, useBC7TextureCompression);
51  } else
52  if (StringTools::endsWith(StringTools::toLowerCase(fileName), ".glb") == true) {
53  return GLTFReader::read(pathName, fileName, useBC7TextureCompression);
54  } else
55  if (StringTools::endsWith(StringTools::toLowerCase(fileName), ".gltf") == true) {
56  return GLTFReader::read(pathName, fileName, useBC7TextureCompression);
57  } else
58  if (StringTools::endsWith(StringTools::toLowerCase(fileName), ".tm") == true) {
59  return TMReader::read(pathName, fileName, useBC7TextureCompression);
60  } else
61  if (StringTools::endsWith(StringTools::toLowerCase(fileName), ".tmodel") == true) {
62  unique_ptr<Prototype> prototype(PrototypeReader::read(pathName, fileName));
63  if (prototype != nullptr && prototype->getModel() != nullptr) {
64  auto model = prototype->unsetModel();
65  return model;
66  } else {
67  return nullptr;
68  }
69  } else {
70  throw ModelFileIOException(string("Unsupported mode file: ") + pathName + "/" + fileName);
71  }
72  } catch (Exception& exception) {
73  Console::println("ModelReader::read(): Could not read model: " + pathName + "/" + fileName + ": " + exception.what());
74  throw;
75  }
76  return nullptr;
77 }
78 
Collada DAE model reader.
Definition: DAEReader.h:39
static Model * read(const string &pathName, const string &fileName, bool useBC7TextureCompression=true)
Reads Collada DAE file.
Definition: DAEReader.cpp:96
static Model * read(const string &pathName, const string &fileName, bool useBC7TextureCompression=true)
Reads GLTF file.
Definition: GLTFReader.cpp:85
static STATIC_DLL_IMPEXT vector< string > extensions
Definition: ModelReader.h:28
static Model * read(const string &pathName, const string &fileName, bool useBC7TextureCompression=true)
Reads a model.
Definition: ModelReader.cpp:46
static Model * read(const string &pathName, const string &fileName, bool useBC7TextureCompression=true)
TDME model format reader.
Definition: TMReader.cpp:69
Representation of a 3D model.
Definition: Model.h:35
Prototype definition.
Definition: Prototype.h:55
File system singleton class.
Definition: FileSystem.h:17
Console class.
Definition: Console.h:29
String tools class.
Definition: StringTools.h:22
std::exception Exception
Exception base class.
Definition: Exception.h:18