Main.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright (C) 2009-2017, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include "Exporter.h"
  6. static void parseCommandLineArgs(int argc, char** argv, Exporter& exporter)
  7. {
  8. static const char* usage = R"(Usage: %s in_file out_dir [options]
  9. Options:
  10. -rpath <string> : Append a string to the meshes and materials
  11. -texrpath <string> : Append a string to the textures paths
  12. -flipyz : Flip y with z (For blender exports)
  13. )";
  14. // Parse config
  15. if(argc < 3)
  16. {
  17. goto error;
  18. }
  19. exporter.m_inputFilename = argv[1];
  20. exporter.m_outputDirectory = argv[2] + std::string("/");
  21. for(int i = 3; i < argc; i++)
  22. {
  23. if(strcmp(argv[i], "-texrpath") == 0)
  24. {
  25. ++i;
  26. if(i < argc)
  27. {
  28. exporter.m_texrpath = argv[i] + std::string("/");
  29. }
  30. else
  31. {
  32. goto error;
  33. }
  34. }
  35. else if(strcmp(argv[i], "-rpath") == 0)
  36. {
  37. ++i;
  38. if(i < argc)
  39. {
  40. exporter.m_rpath = argv[i] + std::string("/");
  41. }
  42. else
  43. {
  44. goto error;
  45. }
  46. }
  47. else if(strcmp(argv[i], "-flipyz") == 0)
  48. {
  49. exporter.m_flipyz = true;
  50. }
  51. else
  52. {
  53. goto error;
  54. }
  55. }
  56. if(exporter.m_rpath.empty())
  57. {
  58. exporter.m_rpath = exporter.m_outputDirectory;
  59. }
  60. if(exporter.m_texrpath.empty())
  61. {
  62. exporter.m_texrpath = exporter.m_outputDirectory;
  63. }
  64. return;
  65. error:
  66. printf(usage, argv[0]);
  67. exit(1);
  68. }
  69. int main(int argc, char** argv)
  70. {
  71. try
  72. {
  73. Exporter exporter;
  74. parseCommandLineArgs(argc, argv, exporter);
  75. // Load file
  76. exporter.load();
  77. // Export
  78. exporter.exportAll();
  79. }
  80. catch(std::exception& e)
  81. {
  82. ERROR("Exception: %s", &e.what()[0]);
  83. }
  84. }