TDME2  1.9.200
scenefixmodelszup2yup-main.cpp
Go to the documentation of this file.
1 #include <memory>
2 #include <string>
3 
4 #include <tdme/tdme.h>
14 #include <tdme/engine/Transform.h>
15 #include <tdme/engine/Version.h>
16 #include <tdme/math/Matrix4x4.h>
17 #include <tdme/math/Vector3.h>
20 #include <tdme/utilities/Console.h>
22 
23 using std::string;
24 using std::unique_ptr;
25 
43 
44 int main(int argc, char** argv)
45 {
46  Console::println(string("scenefixmodelszup2yup ") + Version::getVersion());
47  Console::println(Version::getCopyright());
48  Console::println();
49 
50  if (argc != 2) {
51  Console::println("Usage: scenefixmodelszup2yup scene");
52  Application::exit(Application::EXITCODE_FAILURE);
53  }
54  string sceneFileName = string(argv[1]);
55  try {
56  Console::println("Loading scene: " + sceneFileName);
57  auto scene = unique_ptr<Scene>(
58  SceneReader::read(
59  FileSystem::getInstance()->getPathName(sceneFileName),
60  FileSystem::getInstance()->getFileName(sceneFileName)
61  )
62  );
63  Console::println("Fixing scene models up axis from Z-Up to Y-Up");
64  Matrix4x4 z2yUpMatrix;
65  z2yUpMatrix.identity().setAxes(Vector3(1.0f, 0.0f, 0.0f), -90.0f);
66  // scene prototype library
67  auto sceneLibray = scene->getLibrary();
68  for (auto i = 0; i < sceneLibray->getPrototypeCount(); i++) {
69  auto prototype = sceneLibray->getPrototypeAt(i);
70  if (prototype->getType() != Prototype_Type::MODEL) continue;
71  prototype->getModel()->setImportTransformMatrix(prototype->getModel()->getImportTransformMatrix().clone().multiply(z2yUpMatrix));
72  prototype->getModel()->getBoundingBox()->getMin() = z2yUpMatrix.multiply(prototype->getModel()->getBoundingBox()->getMin());
73  prototype->getModel()->getBoundingBox()->getMax() = z2yUpMatrix.multiply(prototype->getModel()->getBoundingBox()->getMax());
74  prototype->getModel()->getBoundingBox()->update();
75  }
76  // scene entities
77  for (auto i = 0; i < scene->getEntityCount(); i++) {
78  auto sceneEntity = scene->getEntityAt(i);
79  if (sceneEntity->getPrototype()->getType() != Prototype_Type::MODEL) continue;
80  auto scale = sceneEntity->getTransform().getScale();
81  sceneEntity->getTransform().setScale(Vector3(scale.getX(), scale.getZ(), scale.getY()));
82  auto rotationX = sceneEntity->getTransform().getRotationAngle(scene->getRotationOrder()->getAxisXIndex());
83  sceneEntity->getTransform().setRotationAngle(scene->getRotationOrder()->getAxisXIndex(), rotationX + 90);
84  sceneEntity->getTransform().update();
85  }
86  // TODO: bvs
87  Console::println("Saving scene: " + sceneFileName);
88  SceneWriter::write(
89  FileSystem::getInstance()->getPathName(sceneFileName),
90  FileSystem::getInstance()->getFileName(sceneFileName),
91  scene.get()
92  );
93  } catch (Exception& exception) {
94  Console::println("An error occurred: " + string(exception.what()));
95  }
96 
97  //
98  Application::exit(Application::EXITCODE_SUCCESS);
99 }
Application base class, please make sure to allocate application on heap to have correct application ...
Definition: Application.h:41
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
Represents rotation orders of a model.
Definition: RotationOrder.h:23
Prototype definition.
Definition: Prototype.h:55
Scene entity definition.
Definition: SceneEntity.h:23
Scene prototype library definition.
Definition: SceneLibrary.h:32
Scene definition.
Definition: Scene.h:50
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
Matrix4x4 & identity()
Creates identity matrix.
Definition: Matrix4x4.h:158
Vector3 multiply(const Vector3 &vector3) const
Multiplies this matrix with vector3.
Definition: Matrix4x4.h:225
Matrix4x4 & setAxes(const Vector3 &xAxis, const Vector3 &yAxis, const Vector3 &zAxis)
Set coordinate system axes.
Definition: Matrix4x4.h:334
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
File system singleton class.
Definition: FileSystem.h:17
Console class.
Definition: Console.h:29
std::exception Exception
Exception base class.
Definition: Exception.h:18
int main(int argc, char **argv)