EncoderArguments.h 5.2 KB

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