miniassimp

view src/Importer.h @ 0:879c81d94345

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Jan 2019 18:19:26 +0200
parents
children
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2018, assimp team
8 All rights reserved.
10 Redistribution and use of this software in source and binary forms,
11 with or without modification, are permitted provided that the
12 following conditions are met:
14 * Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the
16 following disclaimer.
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.
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.
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 ----------------------------------------------------------------------
41 */
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
48 #include <map>
49 #include <vector>
50 #include <string>
51 #include <miniassimp/matrix4x4.h>
53 struct aiScene;
55 namespace Assimp {
56 class ProgressHandler;
57 class IOSystem;
58 class BaseImporter;
59 class BaseProcess;
60 class SharedPostProcessInfo;
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;
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;
83 /** IO handler to use for all file accesses. */
84 IOSystem* mIOHandler;
85 bool mIsDefaultHandler;
87 /** Progress handler for feedback. */
88 ProgressHandler* mProgressHandler;
89 bool mIsDefaultProgressHandler;
91 /** Format-specific importer worker objects - one for each format we can read.*/
92 std::vector< BaseImporter* > mImporter;
94 /** Post processing steps we can apply at the imported data. */
95 std::vector< BaseProcess* > mPostProcessingSteps;
97 /** The imported data, if ReadFile() was successful, NULL otherwise. */
98 aiScene* mScene;
100 /** The error description, if there was one. */
101 std::string mErrorString;
103 /** List of integer properties */
104 IntPropertyMap mIntProperties;
106 /** List of floating-point properties */
107 FloatPropertyMap mFloatProperties;
109 /** List of string properties */
110 StringPropertyMap mStringProperties;
112 /** List of Matrix properties */
113 MatrixPropertyMap mMatrixProperties;
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;
119 /** Used by post-process steps to share data */
120 SharedPostProcessInfo* mPPShared;
122 /// The default class constructor.
123 ImporterPimpl() AI_NO_EXCEPT;
124 };
126 inline
127 ImporterPimpl::ImporterPimpl() AI_NO_EXCEPT
128 : mIOHandler( 0 )
129 , mIsDefaultHandler( false )
130 , mProgressHandler( 0 )
131 , mIsDefaultProgressHandler( false )
132 , mImporter()
133 , mPostProcessingSteps()
134 , mScene( 0 )
135 , mErrorString()
136 , mIntProperties()
137 , mFloatProperties()
138 , mStringProperties()
139 , mMatrixProperties()
140 , bExtraVerbose( false )
141 , mPPShared( 0 ) {
142 // empty
143 }
144 //! @endcond
147 struct BatchData;
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*/
157 class ASSIMP_API BatchLoader
158 {
159 // friend of Importer
161 public:
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;
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 }
178 bool empty () const {
179 return ints.empty() && floats.empty() && strings.empty() && matrices.empty();
180 }
181 };
182 //! @endcond
184 public:
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 );
191 // -------------------------------------------------------------------
192 /** The class destructor.
193 */
194 ~BatchLoader();
196 // -------------------------------------------------------------------
197 /** Sets the validation step. True for enable validation during postprocess.
198 * @param enable True for validation.
199 */
200 void setValidation( bool enabled );
202 // -------------------------------------------------------------------
203 /** Returns the current validation step.
204 * @return The current validation step.
205 */
206 bool getValidation() const;
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 );
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 );
235 // -------------------------------------------------------------------
236 /** Waits until all scenes have been loaded. This returns
237 * immediately if no scenes are queued.*/
238 void LoadAll();
240 private:
241 // No need to have that in the public API ...
242 BatchData *m_data;
243 };
245 } // Namespace Assimp
247 #endif // INCLUDED_AI_IMPORTER_H