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

source code of qt3d/src/3rdparty/assimp/src/code/Common/Importer.h