EncoderArguments.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. /**
  38. * Constructor.
  39. */
  40. EncoderArguments(size_t argc, const char** argv);
  41. /**
  42. * Destructor.
  43. */
  44. ~EncoderArguments(void);
  45. /**
  46. * Gets the EncoderArguments instance.
  47. */
  48. static EncoderArguments* getInstance();
  49. /**
  50. * Gets the file format from the file path based on the extension.
  51. */
  52. FileFormat getFileFormat() const;
  53. /**
  54. * Returns the file path.
  55. */
  56. const std::string& getFilePath() const;
  57. /**
  58. * Returns the char pointer to the file path string.
  59. */
  60. const char* getFilePathPointer() const;
  61. /**
  62. * Returns the output path/folder.
  63. * Example: "C:/dir"
  64. */
  65. std::string getOutputDirPath() const;
  66. /**
  67. * Returns the output file path.
  68. * Example: "C:/dir/scene.gpb"
  69. */
  70. std::string getOutputFilePath() const;
  71. /**
  72. * Returns the output file extension.
  73. */
  74. std::string getOutputFileExtension() const;
  75. const std::vector<std::string>& getGroupAnimationNodeId() const;
  76. const std::vector<std::string>& getGroupAnimationAnimationId() const;
  77. bool containsGroupNodeId(const std::string& nodeId) const;
  78. const std::string getAnimationId(const std::string& nodeId) const;
  79. const std::vector<HeightmapOption>& getHeightmapOptions() const;
  80. /**
  81. * Returns the number of node IDs that were marked as needing to compute tangents and binormals.
  82. */
  83. unsigned int tangentBinormalIdCount() const;
  84. /**
  85. * Returns true if the given node ID was marked as needing to generate tangents and binormals.
  86. */
  87. bool isGenerateTangentBinormalId(const std::string& id) const;
  88. /**
  89. * Returns true if normal map generation is turned on.
  90. */
  91. bool normalMapGeneration() const;
  92. /**
  93. * Returns the supplied intput heightmap resolution.
  94. *
  95. * This option is only applicable for normal map generation.
  96. */
  97. void getHeightmapResolution(int* x, int* y) const;
  98. /**
  99. * Returns world size option.
  100. *
  101. * This option is only applicable for normal map generation.
  102. */
  103. const Vector3& getHeightmapWorldSize() const;
  104. /**
  105. * Returns true if an error occurred while parsing the command line arguments.
  106. */
  107. bool parseErrorOccured() const;
  108. /**
  109. * Tests if a file exists on the file system.
  110. *
  111. * @return True if the file exists; false otherwise.
  112. */
  113. bool fileExists() const;
  114. /**
  115. * Prints the usage information.
  116. */
  117. void printUsage() const;
  118. bool fontPreviewEnabled() const;
  119. bool textOutputEnabled() const;
  120. bool optimizeAnimationsEnabled() const;
  121. const char* getNodeId() const;
  122. unsigned int getFontSize() const;
  123. static std::string getRealPath(const std::string& filepath);
  124. private:
  125. /**
  126. * Reads the command line option from the list of options starting at the given index.
  127. *
  128. * @param options The list of command line options.
  129. * @param index Pointer to the index within the options list. The index will be changed
  130. * if an option takes multiple arguments.
  131. */
  132. void readOption(const std::vector<std::string>& options, size_t *index);
  133. void setInputfilePath(const std::string& inputPath);
  134. /**
  135. * Sets the output file path that the encoder will write to.
  136. */
  137. void setOutputfilePath(const std::string& outputPath);
  138. /**
  139. * Replaces all instance of oldChar with newChar in str.
  140. */
  141. static void replace_char(char* str, char oldChar, char newChar);
  142. private:
  143. std::string _filePath;
  144. std::string _fileOutputPath;
  145. std::string _nodeId;
  146. unsigned int _fontSize;
  147. bool _normalMap;
  148. Vector3 _heightmapWorldSize;
  149. int _heightmapResolution[2];
  150. bool _parseError;
  151. bool _fontPreview;
  152. bool _textOutput;
  153. bool _optimizeAnimations;
  154. std::vector<std::string> _groupAnimationNodeId;
  155. std::vector<std::string> _groupAnimationAnimationId;
  156. std::vector<HeightmapOption> _heightmaps;
  157. std::set<std::string> _tangentBinormalId;
  158. };
  159. void unittestsEncoderArguments();
  160. }
  161. #endif