main.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /**
  9. * Prompts the user for a font size until a valid font size is entered.
  10. *
  11. * @return A valid font size.
  12. */
  13. static unsigned int promptUserFontSize()
  14. {
  15. static const int lowerBound = 8;
  16. static const int upperBound = 500;
  17. unsigned int fontSize = 0;
  18. char buffer[80];
  19. do
  20. {
  21. printf("Enter font size (between %d and %d):\n", lowerBound, upperBound);
  22. std::cin.getline(buffer, 80);
  23. int i = atoi(buffer);
  24. if (i >= lowerBound && i <= upperBound)
  25. {
  26. fontSize = (unsigned int)i;
  27. }
  28. } while (fontSize == 0);
  29. return fontSize;
  30. }
  31. /**
  32. * Main application entry point.
  33. *
  34. * @param argc The number of command line arguments
  35. * @param argv The array of command line arguments.
  36. *
  37. * usage: gameplay-encoder[options] <file_list>
  38. * example: gameplay-encoder C:/assets/seymour.dae
  39. * example: gameplay-encoder -i boy seymour.dae
  40. *
  41. * @stod: Improve argument parsing.
  42. */
  43. int main(int argc, const char** argv)
  44. {
  45. EncoderArguments arguments(argc, argv);
  46. if (arguments.parseErrorOccured())
  47. {
  48. arguments.printUsage();
  49. return 0;
  50. }
  51. // Check if the file exists.
  52. if (!arguments.fileExists())
  53. {
  54. LOG(1, "Error: File not found: %s\n", arguments.getFilePathPointer());
  55. return -1;
  56. }
  57. // File exists
  58. LOG(1, "Encoding file: %s\n", arguments.getFilePathPointer());
  59. switch (arguments.getFileFormat())
  60. {
  61. case EncoderArguments::FILEFORMAT_DAE:
  62. {
  63. std::string realpath(arguments.getFilePath());
  64. DAESceneEncoder daeEncoder;
  65. daeEncoder.write(realpath, arguments);
  66. break;
  67. }
  68. case EncoderArguments::FILEFORMAT_FBX:
  69. {
  70. #ifdef USE_FBX
  71. std::string realpath(arguments.getFilePath());
  72. FBXSceneEncoder fbxEncoder;
  73. fbxEncoder.write(realpath, arguments);
  74. break;
  75. #else
  76. LOG(1, "Error: FBX not enabled. Install the FBX SDK and use the preprocessor definition USE_FBX.\n");
  77. return -1;
  78. #endif
  79. }
  80. case EncoderArguments::FILEFORMAT_TTF:
  81. {
  82. unsigned int fontSize = arguments.getFontSize();
  83. if (fontSize == 0)
  84. {
  85. fontSize = promptUserFontSize();
  86. }
  87. std::string id = getBaseName(arguments.getFilePath());
  88. writeFont(arguments.getFilePath().c_str(), arguments.getOutputFilePath().c_str(), fontSize, id.c_str(), arguments.fontPreviewEnabled());
  89. break;
  90. }
  91. case EncoderArguments::FILEFORMAT_GPB:
  92. {
  93. std::string realpath(arguments.getFilePath());
  94. GPBDecoder decoder;
  95. decoder.readBinary(realpath);
  96. break;
  97. }
  98. default:
  99. {
  100. LOG(1, "Error: Unsupported file format: %s\n", arguments.getFilePathPointer());
  101. return -1;
  102. }
  103. }
  104. return 0;
  105. }