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