EncoderArguments.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. #ifndef ENCODERARGUMENTS_H_
  2. #define ENCODERARGUMENTS_H_
  3. #include <set>
  4. #include "Vector3.h"
  5. #include "Font.h"
  6. namespace gameplay
  7. {
  8. /**
  9. * EncoderArguments handles parsing the command line arguments for the GamePlay Encoder.
  10. */
  11. class EncoderArguments
  12. {
  13. public:
  14. enum FileFormat
  15. {
  16. FILEFORMAT_UNKNOWN,
  17. FILEFORMAT_FBX,
  18. FILEFORMAT_TMX,
  19. FILEFORMAT_TTF,
  20. FILEFORMAT_GPB,
  21. FILEFORMAT_PNG,
  22. FILEFORMAT_RAW
  23. };
  24. struct HeightmapOption
  25. {
  26. std::vector<std::string> nodeIds;
  27. std::string filename;
  28. bool isHighPrecision;
  29. int width;
  30. int height;
  31. };
  32. struct NormalMapOption
  33. {
  34. std::string inputFile;
  35. std::string outputFile;
  36. Vector3 worldSize;
  37. };
  38. enum AnimationGroupOption
  39. {
  40. ANIMATIONGROUP_PROMPT,
  41. ANIMATIONGROUP_AUTO,
  42. ANIMATIONGROUP_OFF
  43. };
  44. /**
  45. * Constructor.
  46. */
  47. EncoderArguments(size_t argc, const char** argv);
  48. /**
  49. * Destructor.
  50. */
  51. ~EncoderArguments(void);
  52. /**
  53. * Gets the EncoderArguments instance.
  54. */
  55. static EncoderArguments* getInstance();
  56. /**
  57. * Gets the file format from the file path based on the extension.
  58. */
  59. FileFormat getFileFormat() const;
  60. /**
  61. * Returns the file path.
  62. */
  63. const std::string& getFilePath() const;
  64. /**
  65. * Returns the path/folder.
  66. * Example: "C:/dir"
  67. */
  68. const std::string getFileDirPath() const;
  69. /**
  70. * Returns the char pointer to the file path string.
  71. */
  72. const char* getFilePathPointer() const;
  73. /**
  74. * Get the file name of the input file.
  75. */
  76. const std::string getFileName() const;
  77. /**
  78. * Returns the output path/folder.
  79. * Example: "C:/dir"
  80. */
  81. std::string getOutputDirPath() const;
  82. /**
  83. * Returns the output file path.
  84. * Example: "C:/dir/scene.gpb"
  85. */
  86. std::string getOutputFilePath() const;
  87. /**
  88. * Returns the output file extension.
  89. */
  90. std::string getOutputFileExtension() const;
  91. const std::vector<std::string>& getGroupAnimationNodeId() const;
  92. const std::vector<std::string>& getGroupAnimationAnimationId() const;
  93. bool containsGroupNodeId(const std::string& nodeId) const;
  94. const std::string getAnimationId(const std::string& nodeId) const;
  95. AnimationGroupOption getAnimationGrouping() const;
  96. const std::vector<HeightmapOption>& getHeightmapOptions() const;
  97. /**
  98. * Returns the number of node IDs that were marked as needing to compute tangents and binormals.
  99. */
  100. unsigned int tangentBinormalIdCount() const;
  101. /**
  102. * Returns true if the given node ID was marked as needing to generate tangents and binormals.
  103. */
  104. bool isGenerateTangentBinormalId(const std::string& id) const;
  105. /**
  106. * Returns true if normal map generation is turned on.
  107. */
  108. bool normalMapGeneration() const;
  109. /**
  110. * Returns the supplied intput heightmap resolution.
  111. *
  112. * This option is only applicable for normal map generation.
  113. */
  114. void getHeightmapResolution(int* x, int* y) const;
  115. /**
  116. * Returns world size option.
  117. *
  118. * This option is only applicable for normal map generation.
  119. */
  120. const Vector3& getHeightmapWorldSize() const;
  121. /**
  122. * Returns true if an error occurred while parsing the command line arguments.
  123. */
  124. bool parseErrorOccured() const;
  125. /**
  126. * Tests if a file exists on the file system.
  127. *
  128. * @return True if the file exists; false otherwise.
  129. */
  130. bool fileExists() const;
  131. /**
  132. * Prints the usage information.
  133. */
  134. void printUsage() const;
  135. std::vector<unsigned int> getFontSizes() const;
  136. bool fontPreviewEnabled() const;
  137. Font::FontFormat getFontFormat() const;
  138. bool textOutputEnabled() const;
  139. bool optimizeAnimationsEnabled() const;
  140. bool outputMaterialEnabled() const;
  141. bool generateTextureGutter() const;
  142. const char* getNodeId() const;
  143. static std::string getRealPath(const std::string& filepath);
  144. private:
  145. /**
  146. * Reads the command line option from the list of options starting at the given index.
  147. *
  148. * @param options The list of command line options.
  149. * @param index Pointer to the index within the options list. The index will be changed
  150. * if an option takes multiple arguments.
  151. */
  152. void readOption(const std::vector<std::string>& options, size_t *index);
  153. void setInputfilePath(const std::string& inputPath);
  154. /**
  155. * Sets the output file path that the encoder will write to.
  156. */
  157. void setOutputfilePath(const std::string& outputPath);
  158. /**
  159. * Replaces all instance of oldChar with newChar in str.
  160. */
  161. static void replace_char(char* str, char oldChar, char newChar);
  162. private:
  163. std::string _filePath;
  164. std::string _fileOutputPath;
  165. std::string _nodeId;
  166. bool _normalMap;
  167. Vector3 _heightmapWorldSize;
  168. int _heightmapResolution[2];
  169. bool _parseError;
  170. std::vector<unsigned int> _fontSizes;
  171. bool _fontPreview;
  172. Font::FontFormat _fontFormat;
  173. bool _textOutput;
  174. bool _optimizeAnimations;
  175. AnimationGroupOption _animationGrouping;
  176. bool _outputMaterial;
  177. bool _generateTextureGutter;
  178. std::vector<std::string> _groupAnimationNodeId;
  179. std::vector<std::string> _groupAnimationAnimationId;
  180. std::vector<HeightmapOption> _heightmaps;
  181. std::set<std::string> _tangentBinormalId;
  182. };
  183. void unittestsEncoderArguments();
  184. }
  185. #endif