miniassimp

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