main.cpp 3.8 KB

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