main.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "Base.h"
  2. #include "DAESceneEncoder.h"
  3. #include "FBXSceneEncoder.h"
  4. #include "TTFFontEncoder.h"
  5. #include "GPBDecoder.h"
  6. #include "EncoderArguments.h"
  7. using namespace gameplay;
  8. std::string getFileName(const std::string& filepath)
  9. {
  10. size_t index1 = filepath.find_last_of('\\');
  11. size_t index2 = filepath.find_last_of('/');
  12. size_t index = (index1 != -1 && index1 > index2 ? index1 : index2);
  13. size_t length = filepath.length();
  14. std::string filename = filepath.substr(index + 1, length);
  15. length = filename.length();
  16. std::string output = filename.substr(0, (length-4));
  17. return output;
  18. }
  19. /**
  20. * Main application entry point.
  21. *
  22. * @param argc The number of command line arguments
  23. * @param argv The array of command line arguments.
  24. *
  25. * usage: gameplay-encoder[options] <file_list>
  26. * example: gameplay-encoder C:/assets/seymour.dae
  27. * example: gameplay-encoder -i boy seymour.dae
  28. *
  29. * @stod: Improve argument parsing.
  30. */
  31. int main(int argc, const char** argv)
  32. {
  33. EncoderArguments arguments(argc, argv);
  34. if (arguments.parseErrorOccured())
  35. {
  36. arguments.printUsage();
  37. return 0;
  38. }
  39. // Check if the file exists.
  40. if (!arguments.fileExists())
  41. {
  42. fprintf(stderr, "Error: File not found: %s\n", arguments.getFilePathPointer());
  43. return -1;
  44. }
  45. // File exists
  46. fprintf(stderr, "Encoding file: %s\n", arguments.getFilePathPointer());
  47. switch (arguments.getFileFormat())
  48. {
  49. case EncoderArguments::FILEFORMAT_DAE:
  50. {
  51. std::string realpath(arguments.getFilePath());
  52. DAESceneEncoder daeEncoder;
  53. daeEncoder.write(realpath, arguments);
  54. break;
  55. }
  56. case EncoderArguments::FILEFORMAT_FBX:
  57. {
  58. #ifdef USE_FBX
  59. std::string realpath(arguments.getFilePath());
  60. FBXSceneEncoder fbxEncoder;
  61. fbxEncoder.write(realpath, arguments);
  62. break;
  63. #else
  64. fprintf(stderr, "Error: FBX not enabled. Install the FBX SDK and use the preprocessor definition USE_FBX.\n");
  65. return -1;
  66. #endif
  67. }
  68. case EncoderArguments::FILEFORMAT_TTF:
  69. {
  70. std::string realpath(arguments.getFilePath());
  71. std::string id = getFileName(realpath);
  72. writeFont(realpath.c_str(), arguments.getFontSize(), id.c_str(), arguments.fontPreviewEnabled());
  73. break;
  74. }
  75. case EncoderArguments::FILEFORMAT_GPB:
  76. {
  77. std::string realpath(arguments.getFilePath());
  78. GPBDecoder decoder;
  79. decoder.readBinary(realpath);
  80. break;
  81. }
  82. default:
  83. {
  84. fprintf(stderr, "Error: Unsupported file format: %s\n", arguments.getFilePathPointer());
  85. return -1;
  86. }
  87. }
  88. return 0;
  89. }