EncoderArguments.h 4.8 KB

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