Main.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include "Exporter.h"
  6. //==============================================================================
  7. static void parseCommandLineArgs(int argc, char** argv, Exporter& exporter)
  8. {
  9. static const char* usage = R"(Usage: %s in_file out_dir [options]
  10. Options:
  11. -rpath <string> : Append a string to the meshes and materials
  12. -texrpath <string> : Append a string to the textures paths
  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], "-flipyz") == 0)
  49. {
  50. exporter.m_flipyz = true;
  51. }
  52. else
  53. {
  54. goto error;
  55. }
  56. }
  57. if(exporter.m_rpath.empty())
  58. {
  59. exporter.m_rpath = exporter.m_outputDirectory;
  60. }
  61. if(exporter.m_texrpath.empty())
  62. {
  63. exporter.m_texrpath = exporter.m_outputDirectory;
  64. }
  65. return;
  66. error:
  67. printf(usage, argv[0]);
  68. exit(1);
  69. }
  70. //==============================================================================
  71. int main(int argc, char** argv)
  72. {
  73. try
  74. {
  75. Exporter exporter;
  76. parseCommandLineArgs(argc, argv, exporter);
  77. // Load file
  78. exporter.load();
  79. // Export
  80. exporter.exportAll();
  81. }
  82. catch(std::exception& e)
  83. {
  84. ERROR("Exception: %s", &e.what()[0]);
  85. }
  86. }