Importer.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2015, 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. #ifndef INCLUDED_AI_IMPORTER_H
  35. #define INCLUDED_AI_IMPORTER_H
  36. #include <map>
  37. #include <string>
  38. #include <vector>
  39. #include "../include/assimp/matrix4x4.h"
  40. struct aiScene;
  41. namespace Assimp {
  42. class ProgressHandler;
  43. class IOSystem;
  44. class BaseImporter;
  45. class BaseProcess;
  46. class SharedPostProcessInfo;
  47. //! @cond never
  48. // ---------------------------------------------------------------------------
  49. /** @brief Internal PIMPL implementation for Assimp::Importer
  50. *
  51. * Using this idiom here allows us to drop the dependency from
  52. * std::vector and std::map in the public headers. Furthermore we are dropping
  53. * any STL interface problems caused by mismatching STL settings. All
  54. * size calculation are now done by us, not the app heap. */
  55. class ImporterPimpl
  56. {
  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, float> FloatPropertyMap;
  64. typedef std::map<KeyType, std::string> StringPropertyMap;
  65. typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap;
  66. public:
  67. /** IO handler to use for all file accesses. */
  68. IOSystem* mIOHandler;
  69. bool mIsDefaultHandler;
  70. /** Progress handler for feedback. */
  71. ProgressHandler* mProgressHandler;
  72. bool mIsDefaultProgressHandler;
  73. /** Format-specific importer worker objects - one for each format we can read.*/
  74. std::vector< BaseImporter* > mImporter;
  75. /** Post processing steps we can apply at the imported data. */
  76. std::vector< BaseProcess* > mPostProcessingSteps;
  77. /** The imported data, if ReadFile() was successful, NULL otherwise. */
  78. aiScene* mScene;
  79. /** The error description, if there was one. */
  80. std::string mErrorString;
  81. /** List of integer properties */
  82. IntPropertyMap mIntProperties;
  83. /** List of floating-point properties */
  84. FloatPropertyMap mFloatProperties;
  85. /** List of string properties */
  86. StringPropertyMap mStringProperties;
  87. /** List of Matrix properties */
  88. MatrixPropertyMap mMatrixProperties;
  89. /** Used for testing - extra verbose mode causes the ValidateDataStructure-Step
  90. * to be executed before and after every single postprocess step */
  91. bool bExtraVerbose;
  92. /** Used by post-process steps to share data */
  93. SharedPostProcessInfo* mPPShared;
  94. };
  95. //! @endcond
  96. struct BatchData;
  97. // ---------------------------------------------------------------------------
  98. /** FOR IMPORTER PLUGINS ONLY: A helper class to the pleasure of importers
  99. * that need to load many external meshes recursively.
  100. *
  101. * The class uses several threads to load these meshes (or at least it
  102. * could, this has not yet been implemented at the moment).
  103. *
  104. * @note The class may not be used by more than one thread*/
  105. class BatchLoader
  106. {
  107. // friend of Importer
  108. public:
  109. //! @cond never
  110. // -------------------------------------------------------------------
  111. /** Wraps a full list of configuration properties for an importer.
  112. * Properties can be set using SetGenericProperty */
  113. struct PropertyMap
  114. {
  115. ImporterPimpl::IntPropertyMap ints;
  116. ImporterPimpl::FloatPropertyMap floats;
  117. ImporterPimpl::StringPropertyMap strings;
  118. ImporterPimpl::MatrixPropertyMap matrices;
  119. bool operator == (const PropertyMap& prop) const {
  120. // fixme: really isocpp? gcc complains
  121. return ints == prop.ints && floats == prop.floats && strings == prop.strings && matrices == prop.matrices;
  122. }
  123. bool empty () const {
  124. return ints.empty() && floats.empty() && strings.empty() && matrices.empty();
  125. }
  126. };
  127. //! @endcond
  128. public:
  129. // -------------------------------------------------------------------
  130. /** Construct a batch loader from a given IO system to be used
  131. * to acess external files */
  132. explicit BatchLoader(IOSystem* pIO);
  133. ~BatchLoader();
  134. // -------------------------------------------------------------------
  135. /** Add a new file to the list of files to be loaded.
  136. * @param file File to be loaded
  137. * @param steps Post-processing steps to be executed on the file
  138. * @param map Optional configuration properties
  139. * @return 'Load request channel' - an unique ID that can later
  140. * be used to access the imported file data.
  141. * @see GetImport */
  142. unsigned int AddLoadRequest (
  143. const std::string& file,
  144. unsigned int steps = 0,
  145. const PropertyMap* map = NULL
  146. );
  147. // -------------------------------------------------------------------
  148. /** Get an imported scene.
  149. * This polls the import from the internal request list.
  150. * If an import is requested several times, this function
  151. * can be called several times, too.
  152. *
  153. * @param which LRWC returned by AddLoadRequest().
  154. * @return NULL if there is no scene with this file name
  155. * in the queue of the scene hasn't been loaded yet. */
  156. aiScene* GetImport(
  157. unsigned int which
  158. );
  159. // -------------------------------------------------------------------
  160. /** Waits until all scenes have been loaded. This returns
  161. * immediately if no scenes are queued.*/
  162. void LoadAll();
  163. private:
  164. // No need to have that in the public API ...
  165. BatchData* data;
  166. };
  167. }
  168. #endif