main.cpp 4.1 KB

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