TDME2 1.9.121
optimizemodel-main.cpp
Go to the documentation of this file.
1#include <cstdlib>
2#include <string>
3
4#include <tdme/tdme.h>
16
27
28int main(int argc, char** argv)
29{
30 Console::println(string("optimizemodel ") + Version::getVersion());
31 Console::println(Version::getCopyright());
32 Console::println();
33 if (argc < 2) {
34 Console::println("Usage: optimizemodel file.tm [exclude_materials_with_specific_filename1] [exclude_materials_with_specific_filenameN]");
35 Application::exit(1);
36 }
37 string fileName = string(argv[1]);
38 if (StringTools::endsWith(StringTools::toLowerCase(fileName), ".tm") == false) {
39 Console::println("optimizemodel only accepts .tm model files");
40 Application::exit(1);
41 }
42 vector<string> excludeDiffuseTextureFileNamePatterns;
43 for (auto i = 2; i < argc; i++) excludeDiffuseTextureFileNamePatterns.push_back(argv[i]);
44 try {
45 Console::println("Loading model: " + fileName);
46 auto model = ModelReader::read(
47 FileSystem::getInstance()->getPathName(fileName),
48 FileSystem::getInstance()->getFileName(fileName)
49 );
50 auto optimizedModel = model;
51 if (ModelTools::isOptimizedModel(model) == true) {
52 Console::println("Already optimized. Skipping.");
53 } else {
54 Console::println("Optimizing model: " + fileName);
55 optimizedModel = ModelTools::optimizeModel(model, FileSystem::getInstance()->getPathName(fileName), excludeDiffuseTextureFileNamePatterns);
56 if (optimizedModel == model) {
57 Console::println("No optimization was required. Skipping.");
58 } else {
59 Console::println("Exporting model: " + fileName);
60 TMWriter::write(
61 optimizedModel,
62 FileSystem::getInstance()->getPathName(fileName),
63 FileSystem::getInstance()->getFileName(fileName)
64 );
65 }
66 }
67 delete optimizedModel;
68 } catch (Exception& exception) {
69 Console::println("An error occurred: " + string(exception.what()));
70 }
71}
Application base class, please make sure to allocate application on heap to have correct application ...
Definition: Application.h:37
File system singleton class.
Definition: FileSystem.h:14
Console class.
Definition: Console.h:26
Model tools functions class.
Definition: ModelTools.h:38
String tools class.
Definition: StringTools.h:20
std::exception Exception
Exception base class.
Definition: Exception.h:19
int main(int argc, char **argv)