Importer.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2020, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file Importer.h mostly internal stuff for use by #Assimp::Importer */
  34. #pragma once
  35. #ifndef INCLUDED_AI_IMPORTER_H
  36. #define INCLUDED_AI_IMPORTER_H
  37. #include <map>
  38. #include <vector>
  39. #include <string>
  40. #include <assimp/matrix4x4.h>
  41. struct aiScene;
  42. namespace Assimp {
  43. class ProgressHandler;
  44. class IOSystem;
  45. class BaseImporter;
  46. class BaseProcess;
  47. class SharedPostProcessInfo;
  48. //! @cond never
  49. // ---------------------------------------------------------------------------
  50. /** @brief Internal PIMPL implementation for Assimp::Importer
  51. *
  52. * Using this idiom here allows us to drop the dependency from
  53. * std::vector and std::map in the public headers. Furthermore we are dropping
  54. * any STL interface problems caused by mismatching STL settings. All
  55. * size calculation are now done by us, not the app heap. */
  56. class ImporterPimpl {
  57. public:
  58. // Data type to store the key hash
  59. typedef unsigned int KeyType;
  60. // typedefs for our four configuration maps.
  61. // We don't need more, so there is no need for a generic solution
  62. typedef std::map<KeyType, int> IntPropertyMap;
  63. typedef std::map<KeyType, ai_real> FloatPropertyMap;
  64. typedef std::map<KeyType, std::string> StringPropertyMap;
  65. typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap;
  66. /** IO handler to use for all file accesses. */
  67. IOSystem* mIOHandler;
  68. bool mIsDefaultHandler;
  69. /** Progress handler for feedback. */
  70. ProgressHandler* mProgressHandler;
  71. bool mIsDefaultProgressHandler;
  72. /** Format-specific importer worker objects - one for each format we can read.*/
  73. std::vector< BaseImporter* > mImporter;
  74. /** Post processing steps we can apply at the imported data. */
  75. std::vector< BaseProcess* > mPostProcessingSteps;
  76. /** The imported data, if ReadFile() was successful, nullptr otherwise. */
  77. aiScene* mScene;
  78. /** The error description, if there was one. */
  79. std::string mErrorString;
  80. /** List of integer properties */
  81. IntPropertyMap mIntProperties;
  82. /** List of floating-point properties */
  83. FloatPropertyMap mFloatProperties;
  84. /** List of string properties */
  85. StringPropertyMap mStringProperties;
  86. /** List of Matrix properties */
  87. MatrixPropertyMap mMatrixProperties;
  88. /** Used for testing - extra verbose mode causes the ValidateDataStructure-Step
  89. * to be executed before and after every single post-process step */
  90. bool bExtraVerbose;
  91. /** Used by post-process steps to share data */
  92. SharedPostProcessInfo* mPPShared;
  93. /// The default class constructor.
  94. ImporterPimpl() AI_NO_EXCEPT;
  95. };
  96. inline
  97. ImporterPimpl::ImporterPimpl() AI_NO_EXCEPT
  98. : mIOHandler( nullptr )
  99. , mIsDefaultHandler( false )
  100. , mProgressHandler( nullptr )
  101. , mIsDefaultProgressHandler( false )
  102. , mImporter()
  103. , mPostProcessingSteps()
  104. , mScene( nullptr )
  105. , mErrorString()
  106. , mIntProperties()
  107. , mFloatProperties()
  108. , mStringProperties()
  109. , mMatrixProperties()
  110. , bExtraVerbose( false )
  111. , mPPShared( nullptr ) {
  112. // empty
  113. }
  114. //! @endcond
  115. struct BatchData;
  116. // ---------------------------------------------------------------------------
  117. /** FOR IMPORTER PLUGINS ONLY: A helper class to the pleasure of importers
  118. * that need to load many external meshes recursively.
  119. *
  120. * The class uses several threads to load these meshes (or at least it
  121. * could, this has not yet been implemented at the moment).
  122. *
  123. * @note The class may not be used by more than one thread*/
  124. class ASSIMP_API BatchLoader
  125. {
  126. // friend of Importer
  127. public:
  128. //! @cond never
  129. // -------------------------------------------------------------------
  130. /** Wraps a full list of configuration properties for an importer.
  131. * Properties can be set using SetGenericProperty */
  132. struct PropertyMap
  133. {
  134. ImporterPimpl::IntPropertyMap ints;
  135. ImporterPimpl::FloatPropertyMap floats;
  136. ImporterPimpl::StringPropertyMap strings;
  137. ImporterPimpl::MatrixPropertyMap matrices;
  138. bool operator == (const PropertyMap& prop) const {
  139. // fixme: really isocpp? gcc complains
  140. return ints == prop.ints && floats == prop.floats && strings == prop.strings && matrices == prop.matrices;
  141. }
  142. bool empty () const {
  143. return ints.empty() && floats.empty() && strings.empty() && matrices.empty();
  144. }
  145. };
  146. //! @endcond
  147. public:
  148. // -------------------------------------------------------------------
  149. /** Construct a batch loader from a given IO system to be used
  150. * to access external files
  151. */
  152. explicit BatchLoader(IOSystem* pIO, bool validate = false );
  153. // -------------------------------------------------------------------
  154. /** The class destructor.
  155. */
  156. ~BatchLoader();
  157. // -------------------------------------------------------------------
  158. /** Sets the validation step. True for enable validation during postprocess.
  159. * @param enable True for validation.
  160. */
  161. void setValidation( bool enabled );
  162. // -------------------------------------------------------------------
  163. /** Returns the current validation step.
  164. * @return The current validation step.
  165. */
  166. bool getValidation() const;
  167. // -------------------------------------------------------------------
  168. /** Add a new file to the list of files to be loaded.
  169. * @param file File to be loaded
  170. * @param steps Post-processing steps to be executed on the file
  171. * @param map Optional configuration properties
  172. * @return 'Load request channel' - an unique ID that can later
  173. * be used to access the imported file data.
  174. * @see GetImport */
  175. unsigned int AddLoadRequest (
  176. const std::string& file,
  177. unsigned int steps = 0,
  178. const PropertyMap *map = nullptr
  179. );
  180. // -------------------------------------------------------------------
  181. /** Get an imported scene.
  182. * This polls the import from the internal request list.
  183. * If an import is requested several times, this function
  184. * can be called several times, too.
  185. *
  186. * @param which LRWC returned by AddLoadRequest().
  187. * @return nullptr if there is no scene with this file name
  188. * in the queue of the scene hasn't been loaded yet. */
  189. aiScene* GetImport(
  190. unsigned int which
  191. );
  192. // -------------------------------------------------------------------
  193. /** Waits until all scenes have been loaded. This returns
  194. * immediately if no scenes are queued.*/
  195. void LoadAll();
  196. private:
  197. // No need to have that in the public API ...
  198. BatchData *m_data;
  199. };
  200. } // Namespace Assimp
  201. #endif // INCLUDED_AI_IMPORTER_H