Main.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright (C) 2009-2018, 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> : Replace all absolute paths of assets with that path
  11. -texrpath <string> : Same as rpath but for textures
  12. -flipyz : Flip y with z (For blender exports)
  13. )";
  14. bool rpathFound = false;
  15. bool texrpathFound = false;
  16. // Parse config
  17. if(argc < 3)
  18. {
  19. goto error;
  20. }
  21. exporter.m_inputFilename = argv[1];
  22. exporter.m_outputDirectory = argv[2] + std::string("/");
  23. for(int i = 3; i < argc; i++)
  24. {
  25. if(strcmp(argv[i], "-texrpath") == 0)
  26. {
  27. texrpathFound = true;
  28. ++i;
  29. if(i < argc)
  30. {
  31. if(std::strlen(argv[i]) > 0)
  32. {
  33. exporter.m_texrpath = argv[i] + std::string("/");
  34. }
  35. }
  36. else
  37. {
  38. goto error;
  39. }
  40. }
  41. else if(strcmp(argv[i], "-rpath") == 0)
  42. {
  43. rpathFound = true;
  44. ++i;
  45. if(i < argc)
  46. {
  47. if(std::strlen(argv[i]) > 0)
  48. {
  49. exporter.m_rpath = argv[i] + std::string("/");
  50. }
  51. }
  52. else
  53. {
  54. goto error;
  55. }
  56. }
  57. else if(strcmp(argv[i], "-flipyz") == 0)
  58. {
  59. exporter.m_flipyz = true;
  60. }
  61. else
  62. {
  63. goto error;
  64. }
  65. }
  66. if(!rpathFound)
  67. {
  68. exporter.m_rpath = exporter.m_outputDirectory;
  69. }
  70. if(!texrpathFound)
  71. {
  72. exporter.m_texrpath = exporter.m_outputDirectory;
  73. }
  74. return;
  75. error:
  76. printf(usage, argv[0]);
  77. exit(1);
  78. }
  79. int main(int argc, char** argv)
  80. {
  81. try
  82. {
  83. Exporter exporter;
  84. parseCommandLineArgs(argc, argv, exporter);
  85. // Load file
  86. exporter.load();
  87. // Export
  88. exporter.exportAll();
  89. }
  90. catch(std::exception& e)
  91. {
  92. ERROR("Exception: %s", &e.what()[0]);
  93. }
  94. }