Main.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2024, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file Main.h
  35. * @brief Utility declarations for assimp_cmd
  36. */
  37. #ifndef AICMD_MAIN_INCLUDED
  38. #define AICMD_MAIN_INCLUDED
  39. #ifndef _CRT_SECURE_NO_WARNINGS
  40. # define _CRT_SECURE_NO_WARNINGS
  41. #endif
  42. #include <stdio.h>
  43. #include <string.h>
  44. #include <time.h>
  45. #include <limits>
  46. #include <assimp/postprocess.h>
  47. #include <assimp/version.h>
  48. #include <assimp/scene.h>
  49. #include <assimp/Importer.hpp>
  50. #include <assimp/DefaultLogger.hpp>
  51. #include "../code/Common/Compression.h"
  52. #ifndef ASSIMP_BUILD_NO_EXPORT
  53. # include <assimp/Exporter.hpp>
  54. #endif
  55. #ifndef SIZE_MAX
  56. # define SIZE_MAX (std::numeric_limits<size_t>::max())
  57. #endif
  58. using namespace Assimp;
  59. // Global assimp importer instance
  60. extern Assimp::Importer* globalImporter;
  61. #ifndef ASSIMP_BUILD_NO_EXPORT
  62. // Global assimp exporter instance
  63. extern Assimp::Exporter* globalExporter;
  64. #endif
  65. // ------------------------------------------------------------------------------
  66. /// Defines common import parameters
  67. struct ImportData {
  68. ImportData()
  69. : ppFlags (0)
  70. , showLog (false)
  71. , verbose (false)
  72. , log (false)
  73. , rot (aiVector3D(0.f, 0.f, 0.f))
  74. {}
  75. /// Post-processing flags
  76. unsigned int ppFlags;
  77. // Log to std::err?
  78. bool showLog;
  79. // Log file
  80. std::string logFile;
  81. // Verbose log mode?
  82. bool verbose;
  83. // Need to log?
  84. bool log;
  85. // Export With Rotation
  86. aiVector3D rot;
  87. };
  88. // ------------------------------------------------------------------------------
  89. /// @brief General error codes used among assimp_cmd's utilities.
  90. enum AssimpCmdError {
  91. Success = 0,
  92. InvalidNumberOfArguments,
  93. UnrecognizedCommand,
  94. FailedToLoadInputFile,
  95. FailedToOpenOutputFile,
  96. NoFileFormatSpecified,
  97. UnknownFileFormat,
  98. NoFileExtensionSpecified,
  99. UnknownFileExtension,
  100. ExceptionWasRaised,
  101. // Add new error codes here...
  102. LastAssimpCmdError, // Must be last.
  103. };
  104. // ------------------------------------------------------------------------------
  105. /** Process standard arguments
  106. *
  107. * @param fill Filled by function
  108. * @param params Command line parameters to be processed
  109. * @param num NUmber of params
  110. * @return An #AssimpCmdError value. */
  111. int ProcessStandardArguments(ImportData& fill,
  112. const char* const* params,
  113. unsigned int num);
  114. // ------------------------------------------------------------------------------
  115. /** Import a specific model file
  116. * @param imp Import configuration to be used
  117. * @param path Path to the file to be read */
  118. const aiScene* ImportModel(
  119. const ImportData& imp,
  120. const std::string& path);
  121. #ifndef ASSIMP_BUILD_NO_EXPORT
  122. // ------------------------------------------------------------------------------
  123. /** Export a specific model file
  124. * @param imp Import configuration to be used
  125. * @param path Path to the file to be written
  126. * @param format Format id*/
  127. bool ExportModel(const aiScene* pOut,
  128. const ImportData& imp,
  129. const std::string& path,
  130. const char* pID);
  131. #endif
  132. // ------------------------------------------------------------------------------
  133. /** assimp_dump utility
  134. * @param params Command line parameters to 'assimp dump'
  135. * @param Number of params
  136. * @return An #AssimpCmdError value.*/
  137. int Assimp_Dump (
  138. const char* const* params,
  139. unsigned int num);
  140. // ------------------------------------------------------------------------------
  141. /// @brief Error codes used by the 'Export' utility.
  142. enum AssimpCmdExportError {
  143. FailedToImportModel = AssimpCmdError::LastAssimpCmdError,
  144. FailedToExportModel,
  145. // Add new error codes here...
  146. LastAssimpCmdExportError, // Must be last.
  147. };
  148. // ------------------------------------------------------------------------------
  149. /** assimp_export utility
  150. * @param params Command line parameters to 'assimp export'
  151. * @param Number of params
  152. * @return Either an #AssimpCmdError or #AssimpCmdExportError value. */
  153. int Assimp_Export (
  154. const char* const* params,
  155. unsigned int num);
  156. // ------------------------------------------------------------------------------
  157. /// @brief Error codes used by the 'Image Extractor' utility.
  158. enum AssimpCmdExtractError {
  159. TextureIndexIsOutOfRange = AssimpCmdError::LastAssimpCmdError,
  160. NoAvailableTextureEncoderFound,
  161. FailedToExportCompressedTexture,
  162. // Add new error codes here...
  163. LastAssimpCmdExtractError, // Must be last.
  164. };
  165. // ------------------------------------------------------------------------------
  166. /** assimp_extract utility
  167. * @param params Command line parameters to 'assimp extract'
  168. * @param Number of params
  169. * @return Either an #AssimpCmdError or #AssimpCmdExtractError value. */
  170. int Assimp_Extract (
  171. const char* const* params,
  172. unsigned int num);
  173. // ------------------------------------------------------------------------------
  174. /// @brief Error codes used by the 'Compare Dump' utility.
  175. enum AssimpCmdCompareDumpError {
  176. FailedToLoadExpectedInputFile = AssimpCmdError::LastAssimpCmdError,
  177. FileComparaisonFailure,
  178. UnknownFailure,
  179. // Add new error codes here...
  180. LastAssimpCmdCompareDumpError, // Must be last.
  181. };
  182. // ------------------------------------------------------------------------------
  183. /** assimp_cmpdump utility
  184. * @param params Command line parameters to 'assimp cmpdump'
  185. * @param Number of params
  186. * @return Either an #AssimpCmdError or #AssimpCmdCompareDumpError. */
  187. int Assimp_CompareDump (
  188. const char* const* params,
  189. unsigned int num);
  190. /// @brief Error codes used by the 'Info' utility.
  191. enum AssimpCmdInfoError {
  192. InvalidCombinaisonOfArguments = AssimpCmdError::LastAssimpCmdError,
  193. // Add new error codes here...
  194. LastAssimpCmdInfoError, // Must be last.
  195. };
  196. // ------------------------------------------------------------------------------
  197. /** @brief assimp info utility
  198. * @param params Command line parameters to 'assimp info'
  199. * @param Number of params
  200. * @return Either an #AssimpCmdError or #AssimpCmdInfoError value. */
  201. int Assimp_Info (
  202. const char* const* params,
  203. unsigned int num);
  204. // ------------------------------------------------------------------------------
  205. /** @brief assimp testbatchload utility
  206. * @param params Command line parameters to 'assimp testbatchload'
  207. * @param Number of params
  208. * @return An #AssimpCmdError value. */
  209. int Assimp_TestBatchLoad (
  210. const char* const* params,
  211. unsigned int num);
  212. #endif // !! AICMD_MAIN_INCLUDED