Main.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2021, 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. #ifndef ASSIMP_BUILD_NO_EXPORT
  52. # include <assimp/Exporter.hpp>
  53. #endif
  54. #ifdef ASSIMP_BUILD_NO_OWN_ZLIB
  55. #include <zlib.h>
  56. #else
  57. #include <../contrib/zlib/zlib.h>
  58. #endif
  59. #ifndef SIZE_MAX
  60. # define SIZE_MAX (std::numeric_limits<size_t>::max())
  61. #endif
  62. using namespace Assimp;
  63. // Global assimp importer instance
  64. extern Assimp::Importer* globalImporter;
  65. #ifndef ASSIMP_BUILD_NO_EXPORT
  66. // Global assimp exporter instance
  67. extern Assimp::Exporter* globalExporter;
  68. #endif
  69. // ------------------------------------------------------------------------------
  70. /// Defines common import parameters
  71. struct ImportData {
  72. ImportData()
  73. : ppFlags (0)
  74. , showLog (false)
  75. , verbose (false)
  76. , log (false)
  77. , rot (aiVector3D(0.f, 0.f, 0.f))
  78. {}
  79. /// Post-processing flags
  80. unsigned int ppFlags;
  81. // Log to std::err?
  82. bool showLog;
  83. // Log file
  84. std::string logFile;
  85. // Verbose log mode?
  86. bool verbose;
  87. // Need to log?
  88. bool log;
  89. // Export With Rotation
  90. aiVector3D rot;
  91. };
  92. /// \enum AssimpCmdError
  93. /// \brief General error codes used among assimp_cmd's utilities.
  94. enum AssimpCmdError {
  95. Success = 0,
  96. InvalidNumberOfArguments,
  97. UnrecognizedCommand,
  98. FailedToLoadInputFile,
  99. FailedToOpenOutputFile,
  100. NoFileFormatSpecified,
  101. UnknownFileFormat,
  102. NoFileExtensionSpecified,
  103. UnknownFileExtension,
  104. ExceptionWasRaised,
  105. // Add new error codes here...
  106. LastAssimpCmdError, // Must be last.
  107. };
  108. // ------------------------------------------------------------------------------
  109. /** Process standard arguments
  110. *
  111. * @param fill Filled by function
  112. * @param params Command line parameters to be processed
  113. * @param num NUmber of params
  114. * @return An #AssimpCmdError value. */
  115. int ProcessStandardArguments(ImportData& fill,
  116. const char* const* params,
  117. unsigned int num);
  118. // ------------------------------------------------------------------------------
  119. /** Import a specific model file
  120. * @param imp Import configuration to be used
  121. * @param path Path to the file to be read */
  122. const aiScene* ImportModel(
  123. const ImportData& imp,
  124. const std::string& path);
  125. #ifndef ASSIMP_BUILD_NO_EXPORT
  126. // ------------------------------------------------------------------------------
  127. /** Export a specific model file
  128. * @param imp Import configuration to be used
  129. * @param path Path to the file to be written
  130. * @param format Format id*/
  131. bool ExportModel(const aiScene* pOut,
  132. const ImportData& imp,
  133. const std::string& path,
  134. const char* pID);
  135. #endif
  136. // ------------------------------------------------------------------------------
  137. /** assimp_dump utility
  138. * @param params Command line parameters to 'assimp dump'
  139. * @param Number of params
  140. * @return An #AssimpCmdError value.*/
  141. int Assimp_Dump (
  142. const char* const* params,
  143. unsigned int num);
  144. /// \enum AssimpCmdExportError
  145. /// \brief Error codes used by the 'Export' utility.
  146. enum AssimpCmdExportError {
  147. FailedToImportModel = AssimpCmdError::LastAssimpCmdError,
  148. FailedToExportModel,
  149. // Add new error codes here...
  150. LastAssimpCmdExportError, // Must be last.
  151. };
  152. // ------------------------------------------------------------------------------
  153. /** assimp_export utility
  154. * @param params Command line parameters to 'assimp export'
  155. * @param Number of params
  156. * @return Either an #AssimpCmdError or #AssimpCmdExportError value. */
  157. int Assimp_Export (
  158. const char* const* params,
  159. unsigned int num);
  160. /// \enum AssimpCmdExtractError
  161. /// \brief Error codes used by the 'Image Extractor' utility.
  162. enum AssimpCmdExtractError {
  163. TextureIndexIsOutOfRange = AssimpCmdError::LastAssimpCmdError,
  164. NoAvailableTextureEncoderFound,
  165. FailedToExportCompressedTexture,
  166. // Add new error codes here...
  167. LastAssimpCmdExtractError, // Must be last.
  168. };
  169. // ------------------------------------------------------------------------------
  170. /** assimp_extract utility
  171. * @param params Command line parameters to 'assimp extract'
  172. * @param Number of params
  173. * @return Either an #AssimpCmdError or #AssimpCmdExtractError value. */
  174. int Assimp_Extract (
  175. const char* const* params,
  176. unsigned int num);
  177. /// \enum AssimpCmdCompareDumpError
  178. /// \brief Error codes used by the 'Compare Dump' utility.
  179. enum AssimpCmdCompareDumpError {
  180. FailedToLoadExpectedInputFile = AssimpCmdError::LastAssimpCmdError,
  181. FileComparaisonFailure,
  182. UnknownFailure,
  183. // Add new error codes here...
  184. LastAssimpCmdCompareDumpError, // Must be last.
  185. };
  186. // ------------------------------------------------------------------------------
  187. /** assimp_cmpdump utility
  188. * @param params Command line parameters to 'assimp cmpdump'
  189. * @param Number of params
  190. * @return Either an #AssimpCmdError or #AssimpCmdCompareDumpError. */
  191. int Assimp_CompareDump (
  192. const char* const* params,
  193. unsigned int num);
  194. /// \enum AssimpCmdInfoError
  195. /// \brief Error codes used by the 'Info' utility.
  196. enum AssimpCmdInfoError {
  197. InvalidCombinaisonOfArguments = AssimpCmdError::LastAssimpCmdError,
  198. // Add new error codes here...
  199. LastAssimpCmdInfoError, // Must be last.
  200. };
  201. // ------------------------------------------------------------------------------
  202. /** @brief assimp info utility
  203. * @param params Command line parameters to 'assimp info'
  204. * @param Number of params
  205. * @return Either an #AssimpCmdError or #AssimpCmdInfoError value. */
  206. int Assimp_Info (
  207. const char* const* params,
  208. unsigned int num);
  209. // ------------------------------------------------------------------------------
  210. /** @brief assimp testbatchload utility
  211. * @param params Command line parameters to 'assimp testbatchload'
  212. * @param Number of params
  213. * @return An #AssimpCmdError value. */
  214. int Assimp_TestBatchLoad (
  215. const char* const* params,
  216. unsigned int num);
  217. #endif // !! AICMD_MAIN_INCLUDED