Main.h 7.7 KB

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