1 | /* |
2 | Open Asset Import Library (assimp) |
3 | ---------------------------------------------------------------------- |
4 | |
5 | Copyright (c) 2006-2017, 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 <map> |
48 | #include <vector> |
49 | #include <string> |
50 | #include <assimp/matrix4x4.h> |
51 | |
52 | struct aiScene; |
53 | |
54 | namespace Assimp { |
55 | class ProgressHandler; |
56 | class IOSystem; |
57 | class BaseImporter; |
58 | class BaseProcess; |
59 | class SharedPostProcessInfo; |
60 | |
61 | |
62 | //! @cond never |
63 | // --------------------------------------------------------------------------- |
64 | /** @brief Internal PIMPL implementation for Assimp::Importer |
65 | * |
66 | * Using this idiom here allows us to drop the dependency from |
67 | * std::vector and std::map in the public headers. Furthermore we are dropping |
68 | * any STL interface problems caused by mismatching STL settings. All |
69 | * size calculation are now done by us, not the app heap. */ |
70 | class ImporterPimpl |
71 | { |
72 | public: |
73 | |
74 | // Data type to store the key hash |
75 | typedef unsigned int KeyType; |
76 | |
77 | // typedefs for our four configuration maps. |
78 | // We don't need more, so there is no need for a generic solution |
79 | typedef std::map<KeyType, int> IntPropertyMap; |
80 | typedef std::map<KeyType, ai_real> FloatPropertyMap; |
81 | typedef std::map<KeyType, std::string> StringPropertyMap; |
82 | typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap; |
83 | |
84 | public: |
85 | |
86 | /** IO handler to use for all file accesses. */ |
87 | IOSystem* mIOHandler; |
88 | bool mIsDefaultHandler; |
89 | |
90 | /** Progress handler for feedback. */ |
91 | ProgressHandler* mProgressHandler; |
92 | bool mIsDefaultProgressHandler; |
93 | |
94 | /** Format-specific importer worker objects - one for each format we can read.*/ |
95 | std::vector< BaseImporter* > mImporter; |
96 | |
97 | /** Post processing steps we can apply at the imported data. */ |
98 | std::vector< BaseProcess* > mPostProcessingSteps; |
99 | |
100 | /** The imported data, if ReadFile() was successful, NULL otherwise. */ |
101 | aiScene* mScene; |
102 | |
103 | /** The error description, if there was one. */ |
104 | std::string mErrorString; |
105 | |
106 | /** List of integer properties */ |
107 | IntPropertyMap mIntProperties; |
108 | |
109 | /** List of floating-point properties */ |
110 | FloatPropertyMap mFloatProperties; |
111 | |
112 | /** List of string properties */ |
113 | StringPropertyMap mStringProperties; |
114 | |
115 | /** List of Matrix properties */ |
116 | MatrixPropertyMap mMatrixProperties; |
117 | |
118 | /** Used for testing - extra verbose mode causes the ValidateDataStructure-Step |
119 | * to be executed before and after every single postprocess step */ |
120 | bool ; |
121 | |
122 | /** Used by post-process steps to share data */ |
123 | SharedPostProcessInfo* mPPShared; |
124 | }; |
125 | //! @endcond |
126 | |
127 | |
128 | struct BatchData; |
129 | |
130 | // --------------------------------------------------------------------------- |
131 | /** FOR IMPORTER PLUGINS ONLY: A helper class to the pleasure of importers |
132 | * that need to load many external meshes recursively. |
133 | * |
134 | * The class uses several threads to load these meshes (or at least it |
135 | * could, this has not yet been implemented at the moment). |
136 | * |
137 | * @note The class may not be used by more than one thread*/ |
138 | class ASSIMP_API BatchLoader |
139 | { |
140 | // friend of Importer |
141 | |
142 | public: |
143 | //! @cond never |
144 | // ------------------------------------------------------------------- |
145 | /** Wraps a full list of configuration properties for an importer. |
146 | * Properties can be set using SetGenericProperty */ |
147 | struct PropertyMap |
148 | { |
149 | ImporterPimpl::IntPropertyMap ints; |
150 | ImporterPimpl::FloatPropertyMap floats; |
151 | ImporterPimpl::StringPropertyMap strings; |
152 | ImporterPimpl::MatrixPropertyMap matrices; |
153 | |
154 | bool operator == (const PropertyMap& prop) const { |
155 | // fixme: really isocpp? gcc complains |
156 | return ints == prop.ints && floats == prop.floats && strings == prop.strings && matrices == prop.matrices; |
157 | } |
158 | |
159 | bool empty () const { |
160 | return ints.empty() && floats.empty() && strings.empty() && matrices.empty(); |
161 | } |
162 | }; |
163 | //! @endcond |
164 | |
165 | public: |
166 | // ------------------------------------------------------------------- |
167 | /** Construct a batch loader from a given IO system to be used |
168 | * to access external files |
169 | */ |
170 | explicit BatchLoader(IOSystem* pIO, bool validate = false ); |
171 | |
172 | // ------------------------------------------------------------------- |
173 | /** The class destructor. |
174 | */ |
175 | ~BatchLoader(); |
176 | |
177 | // ------------------------------------------------------------------- |
178 | /** Sets the validation step. True for enable validation during postprocess. |
179 | * @param enable True for validation. |
180 | */ |
181 | void setValidation( bool enabled ); |
182 | |
183 | // ------------------------------------------------------------------- |
184 | /** Returns the current validation step. |
185 | * @return The current validation step. |
186 | */ |
187 | bool getValidation() const; |
188 | |
189 | // ------------------------------------------------------------------- |
190 | /** Add a new file to the list of files to be loaded. |
191 | * @param file File to be loaded |
192 | * @param steps Post-processing steps to be executed on the file |
193 | * @param map Optional configuration properties |
194 | * @return 'Load request channel' - an unique ID that can later |
195 | * be used to access the imported file data. |
196 | * @see GetImport */ |
197 | unsigned int AddLoadRequest ( |
198 | const std::string& file, |
199 | unsigned int steps = 0, |
200 | const PropertyMap* map = NULL |
201 | ); |
202 | |
203 | // ------------------------------------------------------------------- |
204 | /** Get an imported scene. |
205 | * This polls the import from the internal request list. |
206 | * If an import is requested several times, this function |
207 | * can be called several times, too. |
208 | * |
209 | * @param which LRWC returned by AddLoadRequest(). |
210 | * @return NULL if there is no scene with this file name |
211 | * in the queue of the scene hasn't been loaded yet. */ |
212 | aiScene* GetImport( |
213 | unsigned int which |
214 | ); |
215 | |
216 | // ------------------------------------------------------------------- |
217 | /** Waits until all scenes have been loaded. This returns |
218 | * immediately if no scenes are queued.*/ |
219 | void LoadAll(); |
220 | |
221 | private: |
222 | // No need to have that in the public API ... |
223 | BatchData *m_data; |
224 | }; |
225 | |
226 | } // Namespace Assimp |
227 | |
228 | #endif // INCLUDED_AI_IMPORTER_H |
229 | |