TDME2  1.9.200
copyanimationsetups-main.cpp
Go to the documentation of this file.
1 #include <memory>
2 #include <string>
3 
4 using std::string;
5 using std::unique_ptr;
6 
7 #include <tdme/tdme.h>
13 #include <tdme/engine/Version.h>
16 #include <tdme/utilities/Console.h>
18 
29 
30 int main(int argc, char** argv)
31 {
32  Console::println(string("copyanimationsetups ") + Version::getVersion());
33  Console::println(Version::getCopyright());
34  Console::println();
35  if (argc != 3) {
36  Console::println("Usage: copyanimationsetups sourcefile targetfile.tm");
37  Application::exit(Application::EXITCODE_FAILURE);
38  }
39  string sourceFileName = string(argv[1]);
40  string targetFileName = string(argv[2]);
41  //
42  try {
43  Console::println("Loading source model: " + sourceFileName);
44  auto srcModel = unique_ptr<Model>(
45  ModelReader::read(
46  FileSystem::getInstance()->getPathName(sourceFileName),
47  FileSystem::getInstance()->getFileName(sourceFileName)
48  )
49  );
50  Console::println("Loading target model: " + targetFileName);
51  auto targetModel = unique_ptr<Model>(
52  ModelReader::read(
53  FileSystem::getInstance()->getPathName(targetFileName),
54  FileSystem::getInstance()->getFileName(targetFileName)
55  )
56  );
57  Console::println("Clearing target animation setups");
58  targetModel->clearAnimationSetups();
59  for (const auto& [srcAnimationSetupId, srcAnimationSetup]: srcModel->getAnimationSetups()) {
60  Console::println("Adding target animation setup: " + srcAnimationSetup->getId());
61  if (srcAnimationSetup->getOverlayFromNodeId().length() == 0) {
62  targetModel->addAnimationSetup(
63  srcAnimationSetup->getId(),
64  srcAnimationSetup->getStartFrame(),
65  srcAnimationSetup->getEndFrame(),
66  srcAnimationSetup->isLoop(),
67  srcAnimationSetup->getSpeed()
68  );
69  } else {
70  targetModel->addOverlayAnimationSetup(
71  srcAnimationSetup->getId(),
72  srcAnimationSetup->getOverlayFromNodeId(),
73  srcAnimationSetup->getStartFrame(),
74  srcAnimationSetup->getEndFrame(),
75  srcAnimationSetup->isLoop(),
76  srcAnimationSetup->getSpeed()
77  );
78  }
79  }
80  Console::println("Saving target model: " + targetFileName);
81  TMWriter::write(
82  targetModel.get(),
83  FileSystem::getInstance()->getPathName(targetFileName),
84  FileSystem::getInstance()->getFileName(targetFileName)
85  );
86  } catch (Exception& exception) {
87  Console::println("An error occurred: " + string(exception.what()));
88  }
89 
90  //
91  Application::exit(Application::EXITCODE_SUCCESS);
92 }
Application base class, please make sure to allocate application on heap to have correct application ...
Definition: Application.h:41
Representation of a 3D model.
Definition: Model.h:35
File system singleton class.
Definition: FileSystem.h:17
Console class.
Definition: Console.h:29
int main(int argc, char **argv)
std::exception Exception
Exception base class.
Definition: Exception.h:18