Main.cpp 1.9 KB

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