main.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. 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/duck.fbx
  39. * example: gameplay-encoder -i boy duck.fbx
  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. LOG(1, "Error: Collada support has been removed. Convert your DAE file to FBX.\n");
  64. return -1;
  65. }
  66. case EncoderArguments::FILEFORMAT_FBX:
  67. {
  68. std::string realpath(arguments.getFilePath());
  69. FBXSceneEncoder fbxEncoder;
  70. fbxEncoder.write(realpath, arguments);
  71. break;
  72. }
  73. case EncoderArguments::FILEFORMAT_TTF:
  74. {
  75. unsigned int fontSize = arguments.getFontSize();
  76. if (fontSize == 0)
  77. {
  78. fontSize = promptUserFontSize();
  79. }
  80. std::string id = getBaseName(arguments.getFilePath());
  81. writeFont(arguments.getFilePath().c_str(), arguments.getOutputFilePath().c_str(), fontSize, id.c_str(), arguments.fontPreviewEnabled());
  82. break;
  83. }
  84. case EncoderArguments::FILEFORMAT_GPB:
  85. {
  86. std::string realpath(arguments.getFilePath());
  87. GPBDecoder decoder;
  88. decoder.readBinary(realpath);
  89. break;
  90. }
  91. case EncoderArguments::FILEFORMAT_PNG:
  92. case EncoderArguments::FILEFORMAT_RAW:
  93. {
  94. if (arguments.normalMapGeneration())
  95. {
  96. int x, y;
  97. arguments.getHeightmapResolution(&x, &y);
  98. NormalMapGenerator generator(arguments.getFilePath().c_str(), arguments.getOutputFilePath().c_str(), x, y, arguments.getHeightmapWorldSize());
  99. generator.generate();
  100. }
  101. else
  102. {
  103. LOG(1, "Error: Nothing to do for specified file format. Did you forget an option?\n");
  104. return -1;
  105. }
  106. break;
  107. }
  108. default:
  109. {
  110. LOG(1, "Error: Unsupported file format: %s\n", arguments.getFilePathPointer());
  111. return -1;
  112. }
  113. }
  114. return 0;
  115. }