miniassimp
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/Importer.h Mon Jan 28 18:19:26 2019 +0200 1.3 @@ -0,0 +1,247 @@ 1.4 +/* 1.5 +Open Asset Import Library (assimp) 1.6 +---------------------------------------------------------------------- 1.7 + 1.8 +Copyright (c) 2006-2018, assimp team 1.9 + 1.10 + 1.11 +All rights reserved. 1.12 + 1.13 +Redistribution and use of this software in source and binary forms, 1.14 +with or without modification, are permitted provided that the 1.15 +following conditions are met: 1.16 + 1.17 +* Redistributions of source code must retain the above 1.18 + copyright notice, this list of conditions and the 1.19 + following disclaimer. 1.20 + 1.21 +* Redistributions in binary form must reproduce the above 1.22 + copyright notice, this list of conditions and the 1.23 + following disclaimer in the documentation and/or other 1.24 + materials provided with the distribution. 1.25 + 1.26 +* Neither the name of the assimp team, nor the names of its 1.27 + contributors may be used to endorse or promote products 1.28 + derived from this software without specific prior 1.29 + written permission of the assimp team. 1.30 + 1.31 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.32 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.33 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.34 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.35 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.36 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.37 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.38 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.39 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.40 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.41 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.42 + 1.43 +---------------------------------------------------------------------- 1.44 +*/ 1.45 + 1.46 +/** @file Importer.h mostly internal stuff for use by #Assimp::Importer */ 1.47 +#pragma once 1.48 +#ifndef INCLUDED_AI_IMPORTER_H 1.49 +#define INCLUDED_AI_IMPORTER_H 1.50 + 1.51 +#include <map> 1.52 +#include <vector> 1.53 +#include <string> 1.54 +#include <miniassimp/matrix4x4.h> 1.55 + 1.56 +struct aiScene; 1.57 + 1.58 +namespace Assimp { 1.59 + class ProgressHandler; 1.60 + class IOSystem; 1.61 + class BaseImporter; 1.62 + class BaseProcess; 1.63 + class SharedPostProcessInfo; 1.64 + 1.65 + 1.66 +//! @cond never 1.67 +// --------------------------------------------------------------------------- 1.68 +/** @brief Internal PIMPL implementation for Assimp::Importer 1.69 + * 1.70 + * Using this idiom here allows us to drop the dependency from 1.71 + * std::vector and std::map in the public headers. Furthermore we are dropping 1.72 + * any STL interface problems caused by mismatching STL settings. All 1.73 + * size calculation are now done by us, not the app heap. */ 1.74 +class ImporterPimpl { 1.75 +public: 1.76 + // Data type to store the key hash 1.77 + typedef unsigned int KeyType; 1.78 + 1.79 + // typedefs for our four configuration maps. 1.80 + // We don't need more, so there is no need for a generic solution 1.81 + typedef std::map<KeyType, int> IntPropertyMap; 1.82 + typedef std::map<KeyType, ai_real> FloatPropertyMap; 1.83 + typedef std::map<KeyType, std::string> StringPropertyMap; 1.84 + typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap; 1.85 + 1.86 + /** IO handler to use for all file accesses. */ 1.87 + IOSystem* mIOHandler; 1.88 + bool mIsDefaultHandler; 1.89 + 1.90 + /** Progress handler for feedback. */ 1.91 + ProgressHandler* mProgressHandler; 1.92 + bool mIsDefaultProgressHandler; 1.93 + 1.94 + /** Format-specific importer worker objects - one for each format we can read.*/ 1.95 + std::vector< BaseImporter* > mImporter; 1.96 + 1.97 + /** Post processing steps we can apply at the imported data. */ 1.98 + std::vector< BaseProcess* > mPostProcessingSteps; 1.99 + 1.100 + /** The imported data, if ReadFile() was successful, NULL otherwise. */ 1.101 + aiScene* mScene; 1.102 + 1.103 + /** The error description, if there was one. */ 1.104 + std::string mErrorString; 1.105 + 1.106 + /** List of integer properties */ 1.107 + IntPropertyMap mIntProperties; 1.108 + 1.109 + /** List of floating-point properties */ 1.110 + FloatPropertyMap mFloatProperties; 1.111 + 1.112 + /** List of string properties */ 1.113 + StringPropertyMap mStringProperties; 1.114 + 1.115 + /** List of Matrix properties */ 1.116 + MatrixPropertyMap mMatrixProperties; 1.117 + 1.118 + /** Used for testing - extra verbose mode causes the ValidateDataStructure-Step 1.119 + * to be executed before and after every single post-process step */ 1.120 + bool bExtraVerbose; 1.121 + 1.122 + /** Used by post-process steps to share data */ 1.123 + SharedPostProcessInfo* mPPShared; 1.124 + 1.125 + /// The default class constructor. 1.126 + ImporterPimpl() AI_NO_EXCEPT; 1.127 +}; 1.128 + 1.129 +inline 1.130 +ImporterPimpl::ImporterPimpl() AI_NO_EXCEPT 1.131 +: mIOHandler( 0 ) 1.132 +, mIsDefaultHandler( false ) 1.133 +, mProgressHandler( 0 ) 1.134 +, mIsDefaultProgressHandler( false ) 1.135 +, mImporter() 1.136 +, mPostProcessingSteps() 1.137 +, mScene( 0 ) 1.138 +, mErrorString() 1.139 +, mIntProperties() 1.140 +, mFloatProperties() 1.141 +, mStringProperties() 1.142 +, mMatrixProperties() 1.143 +, bExtraVerbose( false ) 1.144 +, mPPShared( 0 ) { 1.145 + // empty 1.146 +} 1.147 +//! @endcond 1.148 + 1.149 + 1.150 +struct BatchData; 1.151 + 1.152 +// --------------------------------------------------------------------------- 1.153 +/** FOR IMPORTER PLUGINS ONLY: A helper class to the pleasure of importers 1.154 + * that need to load many external meshes recursively. 1.155 + * 1.156 + * The class uses several threads to load these meshes (or at least it 1.157 + * could, this has not yet been implemented at the moment). 1.158 + * 1.159 + * @note The class may not be used by more than one thread*/ 1.160 +class ASSIMP_API BatchLoader 1.161 +{ 1.162 + // friend of Importer 1.163 + 1.164 +public: 1.165 + //! @cond never 1.166 + // ------------------------------------------------------------------- 1.167 + /** Wraps a full list of configuration properties for an importer. 1.168 + * Properties can be set using SetGenericProperty */ 1.169 + struct PropertyMap 1.170 + { 1.171 + ImporterPimpl::IntPropertyMap ints; 1.172 + ImporterPimpl::FloatPropertyMap floats; 1.173 + ImporterPimpl::StringPropertyMap strings; 1.174 + ImporterPimpl::MatrixPropertyMap matrices; 1.175 + 1.176 + bool operator == (const PropertyMap& prop) const { 1.177 + // fixme: really isocpp? gcc complains 1.178 + return ints == prop.ints && floats == prop.floats && strings == prop.strings && matrices == prop.matrices; 1.179 + } 1.180 + 1.181 + bool empty () const { 1.182 + return ints.empty() && floats.empty() && strings.empty() && matrices.empty(); 1.183 + } 1.184 + }; 1.185 + //! @endcond 1.186 + 1.187 +public: 1.188 + // ------------------------------------------------------------------- 1.189 + /** Construct a batch loader from a given IO system to be used 1.190 + * to access external files 1.191 + */ 1.192 + explicit BatchLoader(IOSystem* pIO, bool validate = false ); 1.193 + 1.194 + // ------------------------------------------------------------------- 1.195 + /** The class destructor. 1.196 + */ 1.197 + ~BatchLoader(); 1.198 + 1.199 + // ------------------------------------------------------------------- 1.200 + /** Sets the validation step. True for enable validation during postprocess. 1.201 + * @param enable True for validation. 1.202 + */ 1.203 + void setValidation( bool enabled ); 1.204 + 1.205 + // ------------------------------------------------------------------- 1.206 + /** Returns the current validation step. 1.207 + * @return The current validation step. 1.208 + */ 1.209 + bool getValidation() const; 1.210 + 1.211 + // ------------------------------------------------------------------- 1.212 + /** Add a new file to the list of files to be loaded. 1.213 + * @param file File to be loaded 1.214 + * @param steps Post-processing steps to be executed on the file 1.215 + * @param map Optional configuration properties 1.216 + * @return 'Load request channel' - an unique ID that can later 1.217 + * be used to access the imported file data. 1.218 + * @see GetImport */ 1.219 + unsigned int AddLoadRequest ( 1.220 + const std::string& file, 1.221 + unsigned int steps = 0, 1.222 + const PropertyMap* map = NULL 1.223 + ); 1.224 + 1.225 + // ------------------------------------------------------------------- 1.226 + /** Get an imported scene. 1.227 + * This polls the import from the internal request list. 1.228 + * If an import is requested several times, this function 1.229 + * can be called several times, too. 1.230 + * 1.231 + * @param which LRWC returned by AddLoadRequest(). 1.232 + * @return NULL if there is no scene with this file name 1.233 + * in the queue of the scene hasn't been loaded yet. */ 1.234 + aiScene* GetImport( 1.235 + unsigned int which 1.236 + ); 1.237 + 1.238 + // ------------------------------------------------------------------- 1.239 + /** Waits until all scenes have been loaded. This returns 1.240 + * immediately if no scenes are queued.*/ 1.241 + void LoadAll(); 1.242 + 1.243 +private: 1.244 + // No need to have that in the public API ... 1.245 + BatchData *m_data; 1.246 +}; 1.247 + 1.248 +} // Namespace Assimp 1.249 + 1.250 +#endif // INCLUDED_AI_IMPORTER_H