From 57388609900a2c1eaa5fc0b160f14180c3384e2f Mon Sep 17 00:00:00 2001 From: aramis_acg Date: Tue, 2 Mar 2010 17:38:01 +0000 Subject: [PATCH] - Change BaseImporter::GetExtensionList to add all known file extensions to a std::set, so uniqueness is guaranteed. Also rewrite all related functions in Importer. NOTE: This does *not* change the public interface. - FIX build error on vc8/release-noboost x64, ConvertUTF.c had wrong PCH settings. - ADD knowext and listext verbs to assimp_cmd, add some raw docs. - Update unit tests to reflect these changes. Currently I keep getting failures in some tests, this needs to be resolved *urgently*. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@567 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/3DSLoader.cpp | 8 +- code/3DSLoader.h | 2 +- code/ACLoader.cpp | 6 +- code/ACLoader.h | 2 +- code/ASELoader.cpp | 5 +- code/ASELoader.h | 2 +- code/Assimp.cpp | 3 +- code/B3DImporter.cpp | 4 +- code/B3DImporter.h | 2 +- code/BVHLoader.h | 4 +- code/BaseImporter.h | 97 +++++++----- code/CSMLoader.cpp | 4 +- code/CSMLoader.h | 2 +- code/ColladaLoader.cpp | 4 +- code/ColladaLoader.h | 2 +- code/DXFLoader.cpp | 4 +- code/DXFLoader.h | 2 +- code/HMPLoader.cpp | 4 +- code/HMPLoader.h | 2 +- code/IRRLoader.cpp | 9 +- code/IRRLoader.h | 2 +- code/IRRMeshLoader.cpp | 6 +- code/IRRMeshLoader.h | 2 +- code/Importer.cpp | 140 ++++++++++-------- code/LWOLoader.h | 5 +- code/LWSLoader.cpp | 5 +- code/LWSLoader.h | 2 +- code/MD2Loader.cpp | 4 +- code/MD2Loader.h | 2 +- code/MD3Loader.cpp | 19 ++- code/MD3Loader.h | 2 +- code/MD5Loader.cpp | 6 +- code/MD5Loader.h | 2 +- code/MDCLoader.cpp | 4 +- code/MDCLoader.h | 2 +- code/MDLLoader.cpp | 4 +- code/MDLLoader.h | 2 +- code/MS3DLoader.cpp | 4 +- code/MS3DLoader.h | 2 +- code/NFFLoader.cpp | 5 +- code/NFFLoader.h | 2 +- code/OFFLoader.cpp | 4 +- code/OFFLoader.h | 2 +- code/ObjFileImporter.h | 6 +- code/OgreImporter.cpp | 4 +- code/OgreImporter.h | 2 +- code/PlyLoader.cpp | 4 +- code/PlyLoader.h | 2 +- code/Q3DLoader.cpp | 5 +- code/Q3DLoader.h | 2 +- code/RawLoader.cpp | 4 +- code/RawLoader.h | 2 +- code/SMDLoader.cpp | 5 +- code/SMDLoader.h | 2 +- code/STLLoader.cpp | 4 +- code/STLLoader.h | 2 +- code/TerragenLoader.cpp | 4 +- code/TerragenLoader.h | 2 +- code/UnrealLoader.cpp | 7 +- code/UnrealLoader.h | 2 +- code/XFileImporter.cpp | 4 +- code/XFileImporter.h | 2 +- .../cppunit-1.12.1/src/cppunit/cppunit.vcproj | 8 +- doc/dox.h | 4 +- include/assimp.hpp | 82 +++++----- test/unit/Main.cpp | 1 + test/unit/utImporter.cpp | 15 +- test/unit/utImporter.h | 2 +- test/unit/utLimitBoneWeights.cpp | 6 +- tools/assimp_cmd/Main.cpp | 34 ++++- tools/assimp_cmd/WriteDumb.cpp | 2 +- workspaces/vc8/assimp.vcproj | 64 ++++++++ 72 files changed, 417 insertions(+), 262 deletions(-) diff --git a/code/3DSLoader.cpp b/code/3DSLoader.cpp index d8cf70fc0..82f28c39d 100644 --- a/code/3DSLoader.cpp +++ b/code/3DSLoader.cpp @@ -109,9 +109,10 @@ bool Discreet3DSImporter::CanRead( const std::string& pFile, IOSystem* pIOHandle // ------------------------------------------------------------------------------------------------ // Get list of all extension supported by this loader -void Discreet3DSImporter::GetExtensionList(std::string& append) +void Discreet3DSImporter::GetExtensionList(std::set& extensions) { - append.append("*.3ds;*.prj"); + extensions.insert("3ds"); + extensions.insert("prj"); } // ------------------------------------------------------------------------------------------------ @@ -130,8 +131,9 @@ void Discreet3DSImporter::InternReadFile( const std::string& pFile, this->stream = &stream; // We should have at least one chunk - if (stream.GetRemainingSize() < 16) + if (stream.GetRemainingSize() < 16) { throw new ImportErrorException("3DS file is either empty or corrupt: " + pFile); + } // Allocate our temporary 3DS representation mScene = new D3DS::Scene(); diff --git a/code/3DSLoader.h b/code/3DSLoader.h index 2e8625aca..126727e76 100644 --- a/code/3DSLoader.h +++ b/code/3DSLoader.h @@ -92,7 +92,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/ACLoader.cpp b/code/ACLoader.cpp index d84bb0e9d..7fb438328 100644 --- a/code/ACLoader.cpp +++ b/code/ACLoader.cpp @@ -137,9 +137,11 @@ bool AC3DImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool // ------------------------------------------------------------------------------------------------ // Get list of file extensions handled by this loader -void AC3DImporter::GetExtensionList(std::string& append) +void AC3DImporter::GetExtensionList(std::set& extensions) { - append.append("*.ac;*.acc;*.ac3d"); + extensions.insert("ac"); + extensions.insert("acc"); + extensions.insert("ac3d"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/ACLoader.h b/code/ACLoader.h index 41597691b..f7087a0cd 100644 --- a/code/ACLoader.h +++ b/code/ACLoader.h @@ -189,7 +189,7 @@ protected: // ------------------------------------------------------------------- /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/ASELoader.cpp b/code/ASELoader.cpp index 2447dcfe3..f47f1fb06 100644 --- a/code/ASELoader.cpp +++ b/code/ASELoader.cpp @@ -87,9 +87,10 @@ bool ASEImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool } // ------------------------------------------------------------------------------------------------ -void ASEImporter::GetExtensionList(std::string& append) +void ASEImporter::GetExtensionList(std::set& extensions) { - append.append("*.ase;*.ask"); + extensions.insert("ase"); + extensions.insert("ask"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/ASELoader.h b/code/ASELoader.h index efae439f4..20bde5fb6 100644 --- a/code/ASELoader.h +++ b/code/ASELoader.h @@ -86,7 +86,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/Assimp.cpp b/code/Assimp.cpp index 68ca7eac8..3cb2cdb1b 100644 --- a/code/Assimp.cpp +++ b/code/Assimp.cpp @@ -524,8 +524,7 @@ void aiGetExtensionList(aiString* szOut) boost::mutex::scoped_lock lock(gMutex); #endif - if (!gActiveImports.empty()) - { + if (!gActiveImports.empty()) { (*(gActiveImports.begin())).second->GetExtensionList(*szOut); return; } diff --git a/code/B3DImporter.cpp b/code/B3DImporter.cpp index 7aa65182f..7d20c380f 100644 --- a/code/B3DImporter.cpp +++ b/code/B3DImporter.cpp @@ -74,8 +74,8 @@ bool B3DImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool } // ------------------------------------------------------------------------------------------------ -void B3DImporter::GetExtensionList( std::string& append ){ - append.append("*.b3d"); +void B3DImporter::GetExtensionList( std::set& extensions ){ + extensions.insert("b3d"); } #ifdef DEBUG_B3D diff --git a/code/B3DImporter.h b/code/B3DImporter.h index 478de1f1e..fda865036 100644 --- a/code/B3DImporter.h +++ b/code/B3DImporter.h @@ -60,7 +60,7 @@ public: protected: - virtual void GetExtensionList(std::string& append); + virtual void GetExtensionList(std::set& extensions); virtual void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler); private: diff --git a/code/BVHLoader.h b/code/BVHLoader.h index dc1c3644d..1cd9f47f1 100644 --- a/code/BVHLoader.h +++ b/code/BVHLoader.h @@ -101,9 +101,9 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList( std::string& append) + void GetExtensionList(std::set& extensions) { - append.append("*.bvh"); + extensions.insert("bvh"); } /** Imports the given file into the given scene structure. diff --git a/code/BaseImporter.h b/code/BaseImporter.h index a68aae2d9..80cee4e40 100644 --- a/code/BaseImporter.h +++ b/code/BaseImporter.h @@ -63,8 +63,7 @@ class ASSIMP_API ImportErrorException { public: /** Constructor with arguments */ - ImportErrorException( const std::string& pErrorText) - { + ImportErrorException( const std::string& pErrorText) { mErrorText = pErrorText; } @@ -164,7 +163,7 @@ public: * the file extension is enough. If no suitable loader is found with * this strategy, CanRead() is called again, the 'checkSig' parameter * set to true this time. Now the implementation is expected to - * perform a full check of the file format, possibly searching the + * perform a full check of the file structure, possibly searching the * first bytes of the file for magic identifiers or keywords. * * @param pFile Path and file name of the file to be examined. @@ -174,14 +173,12 @@ public: * contents of the file to be loaded for magic bytes, keywords, etc * to be able to load files with unknown/not existent file extensions. * @return true if the class can read this file, false if not. - * - * @note Sometimes ASSIMP uses this method to determine whether a - * a given file extension is generally supported. In this case the - * file extension is passed in the pFile parameter, pIOHandler is NULL */ - virtual bool CanRead( const std::string& pFile, - IOSystem* pIOHandler, bool checkSig) const = 0; - + virtual bool CanRead( + const std::string& pFile, + IOSystem* pIOHandler, + bool checkSig + ) const = 0; // ------------------------------------------------------------------- /** Imports the given file and returns the imported data. @@ -201,7 +198,10 @@ public: * in InternReadFile(), this function will catch it and transform it into * a suitable response to the caller. */ - aiScene* ReadFile( const std::string& pFile, IOSystem* pIOHandler); + aiScene* ReadFile( + const std::string& pFile, + IOSystem* pIOHandler + ); // ------------------------------------------------------------------- /** Returns the error description of the last error that occured. @@ -218,18 +218,22 @@ public: * basing on the Importer's configuration property list. * @param pImp Importer instance */ - virtual void SetupProperties(const Importer* pImp); + virtual void SetupProperties( + const Importer* pImp + ); protected: // ------------------------------------------------------------------- /** Called by Importer::GetExtensionList() for each loaded importer. - * Importer implementations should append all file extensions - * which they supported to the passed string. - * Example: "*.blabb;*.quak;*.gug;*.foo" (no delimiter after the last!) - * @param append Output string - */ - virtual void GetExtensionList(std::string& append) = 0; + * Implementations are expected to insert() all file extensions + * handled by them into the extension set. A loader capable of + * reading certain files with the extension BLA would place the + * string bla (lower-case!) in the output set. + * @param extensions Output set. */ + virtual void GetExtensionList( + std::set& extensions + ) = 0; // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. The @@ -274,10 +278,12 @@ protected: * @param pScene The scene object to hold the imported data. * NULL is not a valid parameter. * @param pIOHandler The IO handler to use for any file access. - * NULL is not a valid parameter. - */ - virtual void InternReadFile( const std::string& pFile, - aiScene* pScene, IOSystem* pIOHandler) = 0; + * NULL is not a valid parameter. */ + virtual void InternReadFile( + const std::string& pFile, + aiScene* pScene, + IOSystem* pIOHandler + ) = 0; public: // static utilities @@ -295,11 +301,12 @@ public: // static utilities * @param numTokens Size of the token array * @param searchBytes Number of bytes to be searched for the tokens. */ - static bool SearchFileHeaderForToken(IOSystem* pIOSystem, + static bool SearchFileHeaderForToken( + IOSystem* pIOSystem, const std::string& file, - const char** tokens, - unsigned int numTokens, - unsigned int searchBytes = 200); + const char** tokens, + unsigned int numTokens, + unsigned int searchBytes = 200); // ------------------------------------------------------------------- @@ -310,7 +317,8 @@ public: // static utilities * @param ext2 Optional third extension * @note Case-insensitive */ - static bool SimpleExtensionCheck (const std::string& pFile, + static bool SimpleExtensionCheck ( + const std::string& pFile, const char* ext0, const char* ext1 = NULL, const char* ext2 = NULL); @@ -320,7 +328,8 @@ public: // static utilities * @param pFile Input file * @return Extension without trailing dot, all lowercase */ - static std::string GetExtension (const std::string& pFile); + static std::string GetExtension ( + const std::string& pFile); // ------------------------------------------------------------------- /** @brief Check whether a file starts with one or more magic tokens @@ -336,7 +345,9 @@ public: // static utilities * byte-swapped variant of all tokens (big endian). Only for * tokens of size 2,4. */ - static bool CheckMagicToken(IOSystem* pIOHandler, const std::string& pFile, + static bool CheckMagicToken( + IOSystem* pIOHandler, + const std::string& pFile, const void* magic, unsigned int num, unsigned int offset = 0, @@ -348,7 +359,8 @@ public: // static utilities * * @param data File buffer to be converted to UTF8 data. The buffer * is resized as appropriate. */ - static void ConvertToUTF8(std::vector& data); + static void ConvertToUTF8( + std::vector& data); // ------------------------------------------------------------------- /** Utility for text file loaders which copies the contents of the @@ -358,7 +370,8 @@ public: // static utilities * @param data Output buffer to be resized and filled with the * converted text file data. The buffer is terminated with * a binary 0. */ - static void TextFileToBuffer(IOStream* stream, + static void TextFileToBuffer( + IOStream* stream, std::vector& data); protected: @@ -377,7 +390,7 @@ struct BatchData; * could, this has not yet been implemented at the moment). * * @note The class may not be used by more than one thread*/ -class ASSIMP_API BatchLoader +class ASSIMP_API BatchLoader { // friend of Importer @@ -408,10 +421,12 @@ public: // ------------------------------------------------------------------- - /** Construct a batch loader from a given IO system to be used to acess external files */ + /** Construct a batch loader from a given IO system to be used + * to acess external files */ BatchLoader(IOSystem* pIO); ~BatchLoader(); + // ------------------------------------------------------------------- /** Add a new file to the list of files to be loaded. * @param file File to be loaded @@ -420,8 +435,12 @@ public: * @return 'Load request channel' - an unique ID that can later * be used to access the imported file data. * @see GetImport */ - unsigned int AddLoadRequest (const std::string& file, - unsigned int steps = 0, const PropertyMap* map = NULL); + unsigned int AddLoadRequest ( + const std::string& file, + unsigned int steps = 0, + const PropertyMap* map = NULL + ); + // ------------------------------------------------------------------- /** Get an imported scene. @@ -432,10 +451,14 @@ public: * @param which LRWC returned by AddLoadRequest(). * @return NULL if there is no scene with this file name * in the queue of the scene hasn't been loaded yet. */ - aiScene* GetImport (unsigned int which); + aiScene* GetImport( + unsigned int which + ); + // ------------------------------------------------------------------- - /** Waits until all scenes have been loaded. */ + /** Waits until all scenes have been loaded. This returns + * immediately if no scenes are queued.*/ void LoadAll(); private: diff --git a/code/CSMLoader.cpp b/code/CSMLoader.cpp index ff131e57b..e2ad65c29 100644 --- a/code/CSMLoader.cpp +++ b/code/CSMLoader.cpp @@ -83,9 +83,9 @@ bool CSMImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool // ------------------------------------------------------------------------------------------------ // Build a string of all file extensions supported -void CSMImporter::GetExtensionList(std::string& append) +void CSMImporter::GetExtensionList(std::set& extensions) { - append.append("*.csm"); + extensions.insert("csm"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/CSMLoader.h b/code/CSMLoader.h index b1480cf64..77f9062ce 100644 --- a/code/CSMLoader.h +++ b/code/CSMLoader.h @@ -76,7 +76,7 @@ public: protected: // ------------------------------------------------------------------- - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- diff --git a/code/ColladaLoader.cpp b/code/ColladaLoader.cpp index c0112479b..fa8fd0877 100644 --- a/code/ColladaLoader.cpp +++ b/code/ColladaLoader.cpp @@ -91,9 +91,9 @@ bool ColladaLoader::CanRead( const std::string& pFile, IOSystem* pIOHandler, boo // ------------------------------------------------------------------------------------------------ // Get file extension list -void ColladaLoader::GetExtensionList( std::string& append) +void ColladaLoader::GetExtensionList( std::set& extensions ) { - append.append("*.dae"); + extensions.insert("dae"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/ColladaLoader.h b/code/ColladaLoader.h index 10c7754c8..a849868be 100644 --- a/code/ColladaLoader.h +++ b/code/ColladaLoader.h @@ -96,7 +96,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList( std::string& append); + void GetExtensionList( std::set& extensions); /** Imports the given file into the given scene structure. * See BaseImporter::InternReadFile() for details diff --git a/code/DXFLoader.cpp b/code/DXFLoader.cpp index 59d635541..be0724910 100644 --- a/code/DXFLoader.cpp +++ b/code/DXFLoader.cpp @@ -101,9 +101,9 @@ bool DXFImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool // ------------------------------------------------------------------------------------------------ // Get a list of all supported file extensions -void DXFImporter::GetExtensionList(std::string& append) +void DXFImporter::GetExtensionList(std::set& extensions) { - append.append("*.dxf"); + extensions.insert("dxf"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/DXFLoader.h b/code/DXFLoader.h index f7c8f0ab7..30b7f4d17 100644 --- a/code/DXFLoader.h +++ b/code/DXFLoader.h @@ -96,7 +96,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/HMPLoader.cpp b/code/HMPLoader.cpp index 7d54b6bce..85443b8d5 100644 --- a/code/HMPLoader.cpp +++ b/code/HMPLoader.cpp @@ -86,9 +86,9 @@ bool HMPImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool // ------------------------------------------------------------------------------------------------ // Get list of all file extensions that are handled by this loader -void HMPImporter::GetExtensionList(std::string& append) +void HMPImporter::GetExtensionList(std::set& extensions) { - append.append("*.hmp"); + extensions.insert("hmp"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/HMPLoader.h b/code/HMPLoader.h index 2344f364b..08e805e1d 100644 --- a/code/HMPLoader.h +++ b/code/HMPLoader.h @@ -87,7 +87,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/IRRLoader.cpp b/code/IRRLoader.cpp index b3eb98a86..f520ab4bb 100644 --- a/code/IRRLoader.cpp +++ b/code/IRRLoader.cpp @@ -103,13 +103,10 @@ bool IRRImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool } // ------------------------------------------------------------------------------------------------ -void IRRImporter::GetExtensionList(std::string& append) +void IRRImporter::GetExtensionList(std::set& extensions) { - /* NOTE: The file extenxsion .xml is too generic. We'll - * need to open the file in CanRead() and check whether it is - * a real irrlicht file - */ - append.append("*.xml;*.irr"); + extensions.insert("irr"); + extensions.insert("xml"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/IRRLoader.h b/code/IRRLoader.h index d8d796de2..25a5fc87e 100644 --- a/code/IRRLoader.h +++ b/code/IRRLoader.h @@ -84,7 +84,7 @@ protected: // ------------------------------------------------------------------- /** */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** diff --git a/code/IRRMeshLoader.cpp b/code/IRRMeshLoader.cpp index 4bf77597a..f565d3c55 100644 --- a/code/IRRMeshLoader.cpp +++ b/code/IRRMeshLoader.cpp @@ -88,10 +88,10 @@ bool IRRMeshImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, b // ------------------------------------------------------------------------------------------------ // Get a list of all file extensions which are handled by this class -void IRRMeshImporter::GetExtensionList(std::string& append) +void IRRMeshImporter::GetExtensionList(std::set& extensions) { - // fixme: consider cleaner handling of xml extension - append.append("*.xml;*.irrmesh"); + extensions.insert("xml"); + extensions.insert("irrmesh"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/IRRMeshLoader.h b/code/IRRMeshLoader.h index 6d9b71173..b2c0716a3 100644 --- a/code/IRRMeshLoader.h +++ b/code/IRRMeshLoader.h @@ -83,7 +83,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/Importer.cpp b/code/Importer.cpp index 2a2159eb9..756704285 100644 --- a/code/Importer.cpp +++ b/code/Importer.cpp @@ -530,24 +530,26 @@ aiReturn Importer::RegisterLoader(BaseImporter* pImp) // -------------------------------------------------------------------- // Check whether we would have two loaders for the same file extension // This is absolutely OK, but we should warn the developer of the new - // loader that his code will probably never be called.s + // loader that his code will probably never be called if the first + // loader is a bit too lazy in his file checking. // -------------------------------------------------------------------- - std::string st; + std::set st; + std::string baked; pImp->GetExtensionList(st); + for(std::set::const_iterator it = st.begin(); it != st.end(); ++it) { + #ifdef _DEBUG - const char* sz = ::strtok(const_cast(st.c_str()),";"); // evil - while (sz) { - if (IsExtensionSupported(std::string(sz))) - DefaultLogger::get()->warn(std::string( "The file extension " ) + sz + " is already in use"); - - sz = ::strtok(NULL,";"); - } + if (IsExtensionSupported(*it)) { + DefaultLogger::get()->warn("The file extension " + *it + " is already in use"); + } #endif + baked += *it; + } // add the loader pimpl->mImporter.push_back(pImp); - DefaultLogger::get()->info("Registering custom importer: " + st); + DefaultLogger::get()->info("Registering custom importer for these file extensions: " + baked); return AI_SUCCESS; } @@ -555,14 +557,19 @@ aiReturn Importer::RegisterLoader(BaseImporter* pImp) // Unregister a custom loader plugin aiReturn Importer::UnregisterLoader(BaseImporter* pImp) { - ai_assert(NULL != pImp); + if(!pImp) { + // unregistering a NULL importer is no problem for us ... really! + return AI_SUCCESS; + } + std::vector::iterator it = std::find(pimpl->mImporter.begin(),pimpl->mImporter.end(),pImp); if (it != pimpl->mImporter.end()) { pimpl->mImporter.erase(it); - std::string st; + std::set st; pImp->GetExtensionList(st); - DefaultLogger::get()->info("Unregistering custom importer: " + st); + + DefaultLogger::get()->info("Unregistering custom importer: "); return AI_SUCCESS; } DefaultLogger::get()->warn("Unable to remove custom importer: I can't find you ..."); @@ -573,7 +580,11 @@ aiReturn Importer::UnregisterLoader(BaseImporter* pImp) // Unregister a custom loader plugin aiReturn Importer::UnregisterPPStep(BaseProcess* pImp) { - ai_assert(NULL != pImp); + if(!pImp) { + // unregistering a NULL ppstep is no problem for us ... really! + return AI_SUCCESS; + } + std::vector::iterator it = std::find(pimpl->mPostProcessingSteps.begin(),pimpl->mPostProcessingSteps.end(),pImp); if (it != pimpl->mPostProcessingSteps.end()) { pimpl->mPostProcessingSteps.erase(it); @@ -949,22 +960,27 @@ bool Importer::IsExtensionSupported(const char* szExtension) // ------------------------------------------------------------------------------------------------ // Find a loader plugin for a given file extension -BaseImporter* Importer::FindLoader (const char* _szExtension) +BaseImporter* Importer::FindLoader (const char* szExtension) { - std::string ext(_szExtension); + ai_assert(szExtension); + + // skip over wildcard and dot characters at string head -- + for(;*szExtension == '*' || *szExtension == '.'; ++szExtension); + + std::string ext(szExtension); if (ext.length() <= 1) return NULL; - if (ext[0] != '.') { - // trailing dot is explicitly requested in the doc but we don't care for now .. - ext.erase(0,1); - } - + std::set str; for (std::vector::const_iterator i = pimpl->mImporter.begin();i != pimpl->mImporter.end();++i) { + str.clear(); - // pass the file extension to the CanRead(..,NULL)-method - if ((*i)->CanRead(ext,NULL,false)) - return *i; + (*i)->GetExtensionList(str); + for (std::set::const_iterator it = str.begin(); it != str.end(); ++it) { + if (ext == *it) { + return (*i); + } + } } return NULL; } @@ -973,20 +989,20 @@ BaseImporter* Importer::FindLoader (const char* _szExtension) // Helper function to build a list of all file extensions supported by ASSIMP void Importer::GetExtensionList(aiString& szOut) { - unsigned int iNum = 0; - std::string tmp; - for (std::vector::const_iterator i = pimpl->mImporter.begin();i != pimpl->mImporter.end();++i,++iNum) - { - // Insert a comma as delimiter character - // FIX: to take lazy loader implementations into account, we are - // slightly more tolerant here than we'd need to be. - if (0 != iNum && ';' != *(tmp.end()-1)) - tmp.append(";"); - - (*i)->GetExtensionList(tmp); + std::set str; + for (std::vector::const_iterator i = pimpl->mImporter.begin();i != pimpl->mImporter.end();++i) { + (*i)->GetExtensionList(str); + } + + for (std::set::const_iterator it = str.begin();; ) { + szOut.Append("*."); + szOut.Append((*it).c_str()); + + if (++it == str.end()) { + break; + } + szOut.Append(";"); } - szOut.Set(tmp); - return; } // ------------------------------------------------------------------------------------------------ @@ -1044,8 +1060,10 @@ inline void AddNodeWeight(unsigned int& iScene,const aiNode* pcNode) iScene += sizeof(aiNode); iScene += sizeof(unsigned int) * pcNode->mNumMeshes; iScene += sizeof(void*) * pcNode->mNumChildren; - for (unsigned int i = 0; i < pcNode->mNumChildren;++i) + + for (unsigned int i = 0; i < pcNode->mNumChildren;++i) { AddNodeWeight(iScene,pcNode->mChildren[i]); + } } // ------------------------------------------------------------------------------------------------ @@ -1066,32 +1084,33 @@ void Importer::GetMemoryRequirements(aiMemoryInfo& in) const for (unsigned int i = 0; i < mScene->mNumMeshes;++i) { in.meshes += sizeof(aiMesh); - if (mScene->mMeshes[i]->HasPositions()) + if (mScene->mMeshes[i]->HasPositions()) { in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices; + } - if (mScene->mMeshes[i]->HasNormals()) + if (mScene->mMeshes[i]->HasNormals()) { in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices; + } - if (mScene->mMeshes[i]->HasTangentsAndBitangents()) + if (mScene->mMeshes[i]->HasTangentsAndBitangents()) { in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices * 2; + } - for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS;++a) - { - if (mScene->mMeshes[i]->HasVertexColors(a)) + for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS;++a) { + if (mScene->mMeshes[i]->HasVertexColors(a)) { in.meshes += sizeof(aiColor4D) * mScene->mMeshes[i]->mNumVertices; + } else break; } - for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS;++a) - { - if (mScene->mMeshes[i]->HasTextureCoords(a)) + for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS;++a) { + if (mScene->mMeshes[i]->HasTextureCoords(a)) { in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices; + } else break; } - if (mScene->mMeshes[i]->HasBones()) - { + if (mScene->mMeshes[i]->HasBones()) { in.meshes += sizeof(void*) * mScene->mMeshes[i]->mNumBones; - for (unsigned int p = 0; p < mScene->mMeshes[i]->mNumBones;++p) - { + for (unsigned int p = 0; p < mScene->mMeshes[i]->mNumBones;++p) { in.meshes += sizeof(aiBone); in.meshes += mScene->mMeshes[i]->mBones[p]->mNumWeights * sizeof(aiVertexWeight); } @@ -1101,12 +1120,10 @@ void Importer::GetMemoryRequirements(aiMemoryInfo& in) const in.total += in.meshes; // add all embedded textures - for (unsigned int i = 0; i < mScene->mNumTextures;++i) - { + for (unsigned int i = 0; i < mScene->mNumTextures;++i) { const aiTexture* pc = mScene->mTextures[i]; in.textures += sizeof(aiTexture); - if (pc->mHeight) - { + if (pc->mHeight) { in.textures += 4 * pc->mHeight * pc->mWidth; } else in.textures += pc->mWidth; @@ -1114,14 +1131,12 @@ void Importer::GetMemoryRequirements(aiMemoryInfo& in) const in.total += in.textures; // add all animations - for (unsigned int i = 0; i < mScene->mNumAnimations;++i) - { + for (unsigned int i = 0; i < mScene->mNumAnimations;++i) { const aiAnimation* pc = mScene->mAnimations[i]; in.animations += sizeof(aiAnimation); // add all bone anims - for (unsigned int a = 0; a < pc->mNumChannels; ++a) - { + for (unsigned int a = 0; a < pc->mNumChannels; ++a) { const aiNodeAnim* pc2 = pc->mChannels[i]; in.animations += sizeof(aiNodeAnim); in.animations += pc2->mNumPositionKeys * sizeof(aiVectorKey); @@ -1140,13 +1155,12 @@ void Importer::GetMemoryRequirements(aiMemoryInfo& in) const in.total += in.nodes; // add all materials - for (unsigned int i = 0; i < mScene->mNumMaterials;++i) - { + for (unsigned int i = 0; i < mScene->mNumMaterials;++i) { const aiMaterial* pc = mScene->mMaterials[i]; in.materials += sizeof(aiMaterial); in.materials += pc->mNumAllocated * sizeof(void*); - for (unsigned int a = 0; a < pc->mNumProperties;++a) - { + + for (unsigned int a = 0; a < pc->mNumProperties;++a) { in.materials += pc->mProperties[a]->mDataLength; } } diff --git a/code/LWOLoader.h b/code/LWOLoader.h index 3c889c74c..d70a275d7 100644 --- a/code/LWOLoader.h +++ b/code/LWOLoader.h @@ -100,9 +100,10 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append) + void GetExtensionList(std::set& extensions) { - append.append("*.lwo;*.lxo"); + extensions.insert("lxo"); + extensions.insert("lwo"); } // ------------------------------------------------------------------- diff --git a/code/LWSLoader.cpp b/code/LWSLoader.cpp index 278cffe57..657909da7 100644 --- a/code/LWSLoader.cpp +++ b/code/LWSLoader.cpp @@ -140,9 +140,10 @@ bool LWSImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler,bool c // ------------------------------------------------------------------------------------------------ // Get list of file extensions -void LWSImporter::GetExtensionList(std::string& append) +void LWSImporter::GetExtensionList(std::set& extensions) { - append.append("*.lws;*.mot"); + extensions.insert("lws"); + extensions.insert("mot"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/LWSLoader.h b/code/LWSLoader.h index 981cb1ddc..71db3745f 100644 --- a/code/LWSLoader.h +++ b/code/LWSLoader.h @@ -186,7 +186,7 @@ protected: // ------------------------------------------------------------------- // Get list of supported extensions - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- // Import file into given scene data structure diff --git a/code/MD2Loader.cpp b/code/MD2Loader.cpp index f8fe533d3..5e46683be 100644 --- a/code/MD2Loader.cpp +++ b/code/MD2Loader.cpp @@ -99,9 +99,9 @@ bool MD2Importer::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool // ------------------------------------------------------------------------------------------------ // Get a list of all extensions supported by this loader -void MD2Importer::GetExtensionList(std::string& append) +void MD2Importer::GetExtensionList(std::set& extensions) { - append.append("*.md2"); + extensions.insert("md2"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/MD2Loader.h b/code/MD2Loader.h index 314c54747..d4bf00dd9 100644 --- a/code/MD2Loader.h +++ b/code/MD2Loader.h @@ -91,7 +91,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/MD3Loader.cpp b/code/MD3Loader.cpp index f33f248f5..bb99e0cc9 100644 --- a/code/MD3Loader.cpp +++ b/code/MD3Loader.cpp @@ -401,20 +401,27 @@ void MD3Importer::ValidateSurfaceHeaderOffsets(const MD3::Surface* pcSurf) // Check whether all requirements for Q3 files are met. We don't // care, but probably someone does. - if (pcSurf->NUM_TRIANGLES > AI_MD3_MAX_TRIANGLES) + if (pcSurf->NUM_TRIANGLES > AI_MD3_MAX_TRIANGLES) { DefaultLogger::get()->warn("MD3: Quake III triangle limit exceeded"); - if (pcSurf->NUM_SHADER > AI_MD3_MAX_SHADERS) + } + + if (pcSurf->NUM_SHADER > AI_MD3_MAX_SHADERS) { DefaultLogger::get()->warn("MD3: Quake III shader limit exceeded"); - if (pcSurf->NUM_VERTICES > AI_MD3_MAX_VERTS) + } + + if (pcSurf->NUM_VERTICES > AI_MD3_MAX_VERTS) { DefaultLogger::get()->warn("MD3: Quake III vertex limit exceeded"); - if (pcSurf->NUM_FRAMES > AI_MD3_MAX_FRAMES) + } + + if (pcSurf->NUM_FRAMES > AI_MD3_MAX_FRAMES) { DefaultLogger::get()->warn("MD3: Quake III frame limit exceeded"); + } } // ------------------------------------------------------------------------------------------------ -void MD3Importer::GetExtensionList(std::string& append) +void MD3Importer::GetExtensionList(std::set& extensions) { - append.append("*.md3"); + extensions.insert("md3"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/MD3Loader.h b/code/MD3Loader.h index 0a5b80ccc..4f9bd366f 100644 --- a/code/MD3Loader.h +++ b/code/MD3Loader.h @@ -242,7 +242,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/MD5Loader.cpp b/code/MD5Loader.cpp index f7def9a21..c370b7a65 100644 --- a/code/MD5Loader.cpp +++ b/code/MD5Loader.cpp @@ -89,9 +89,11 @@ bool MD5Importer::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool // ------------------------------------------------------------------------------------------------ // Get list of all supported extensions -void MD5Importer::GetExtensionList(std::string& append) +void MD5Importer::GetExtensionList(std::set& extensions) { - append.append("*.md5mesh;*.md5anim;*.md5camera"); + extensions.insert("md5anim"); + extensions.insert("md5mesh"); + extensions.insert("md5camera"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/MD5Loader.h b/code/MD5Loader.h index 84ae840f7..c81da43bf 100644 --- a/code/MD5Loader.h +++ b/code/MD5Loader.h @@ -85,7 +85,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Called prior to ReadFile(). diff --git a/code/MDCLoader.cpp b/code/MDCLoader.cpp index 6a137d1e5..aeb4d91cb 100644 --- a/code/MDCLoader.cpp +++ b/code/MDCLoader.cpp @@ -103,9 +103,9 @@ bool MDCImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool } // ------------------------------------------------------------------------------------------------ -void MDCImporter::GetExtensionList(std::string& append) +void MDCImporter::GetExtensionList(std::set& extensions) { - append.append("*.mdc"); + extensions.insert("mdc"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/MDCLoader.h b/code/MDCLoader.h index 60ef038d0..e13b5e937 100644 --- a/code/MDCLoader.h +++ b/code/MDCLoader.h @@ -88,7 +88,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/MDLLoader.cpp b/code/MDLLoader.cpp index 92371d483..f65e49ced 100644 --- a/code/MDLLoader.cpp +++ b/code/MDLLoader.cpp @@ -117,9 +117,9 @@ void MDLImporter::SetupProperties(const Importer* pImp) // ------------------------------------------------------------------------------------------------ // Get a list of all supported extensions -void MDLImporter::GetExtensionList(std::string& append) +void MDLImporter::GetExtensionList(std::set& extensions) { - append.append( ".mdl" ); + extensions.insert( "mdl" ); } // ------------------------------------------------------------------------------------------------ diff --git a/code/MDLLoader.h b/code/MDLLoader.h index 9f4bd302a..d01624ff0 100644 --- a/code/MDLLoader.h +++ b/code/MDLLoader.h @@ -114,7 +114,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/MS3DLoader.cpp b/code/MS3DLoader.cpp index aa25efb74..b18b4bc43 100644 --- a/code/MS3DLoader.cpp +++ b/code/MS3DLoader.cpp @@ -84,9 +84,9 @@ bool MS3DImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool } // ------------------------------------------------------------------------------------------------ -void MS3DImporter::GetExtensionList(std::string& append) +void MS3DImporter::GetExtensionList(std::set& extensions) { - append.append("*.ms3d"); + extensions.insert("ms3d"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/MS3DLoader.h b/code/MS3DLoader.h index 2ec34af40..9ff236a9e 100644 --- a/code/MS3DLoader.h +++ b/code/MS3DLoader.h @@ -73,7 +73,7 @@ protected: // ------------------------------------------------------------------- /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/NFFLoader.cpp b/code/NFFLoader.cpp index 2c332d07e..b93443cd2 100644 --- a/code/NFFLoader.cpp +++ b/code/NFFLoader.cpp @@ -72,9 +72,10 @@ bool NFFImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool // ------------------------------------------------------------------------------------------------ // Get the list of all supported file extensions -void NFFImporter::GetExtensionList(std::string& append) +void NFFImporter::GetExtensionList(std::set& extensions) { - append.append("*.nff;*.enff"); + extensions.insert("enff"); + extensions.insert("nff"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/NFFLoader.h b/code/NFFLoader.h index 9a46eef87..b18ad175d 100644 --- a/code/NFFLoader.h +++ b/code/NFFLoader.h @@ -84,7 +84,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/OFFLoader.cpp b/code/OFFLoader.cpp index 4d76cf734..d557ad3d7 100644 --- a/code/OFFLoader.cpp +++ b/code/OFFLoader.cpp @@ -82,9 +82,9 @@ bool OFFImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool } // ------------------------------------------------------------------------------------------------ -void OFFImporter::GetExtensionList(std::string& append) +void OFFImporter::GetExtensionList(std::set& extensions) { - append.append("*.off"); + extensions.insert("off"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/OFFLoader.h b/code/OFFLoader.h index 9e6dd13a9..5ef20073e 100644 --- a/code/OFFLoader.h +++ b/code/OFFLoader.h @@ -78,7 +78,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/ObjFileImporter.h b/code/ObjFileImporter.h index a2ca52baa..083a24575 100644 --- a/code/ObjFileImporter.h +++ b/code/ObjFileImporter.h @@ -81,7 +81,7 @@ public: private: //! \brief Appends the supported extention. - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); //! \brief File import implementation. void InternReadFile(const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler); @@ -124,9 +124,9 @@ private: // ------------------------------------------------------------------------------------------------ // -inline void ObjFileImporter::GetExtensionList(std::string& append) +inline void ObjFileImporter::GetExtensionList(std::set& extensions) { - append.append("*.obj"); + extensions.insert("obj"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/OgreImporter.cpp b/code/OgreImporter.cpp index 748e8612e..431b83e77 100644 --- a/code/OgreImporter.cpp +++ b/code/OgreImporter.cpp @@ -129,9 +129,9 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass -void OgreImporter::GetExtensionList(std::string &append) +void OgreImporter::GetExtensionList(std::set& extensions) { - append+="*.mesh.xml"; + extensions.insert("mesh.xml"); } diff --git a/code/OgreImporter.h b/code/OgreImporter.h index b561668e6..9390b9be2 100644 --- a/code/OgreImporter.h +++ b/code/OgreImporter.h @@ -26,7 +26,7 @@ class OgreImporter : public BaseImporter public: virtual bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const; virtual void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler); - virtual void GetExtensionList(std::string& append); + virtual void GetExtensionList(std::set& extensions); virtual void SetupProperties(const Importer* pImp); private: diff --git a/code/PlyLoader.cpp b/code/PlyLoader.cpp index b8e2f3e3a..6a697bb85 100644 --- a/code/PlyLoader.cpp +++ b/code/PlyLoader.cpp @@ -80,9 +80,9 @@ bool PLYImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool } // ------------------------------------------------------------------------------------------------ -void PLYImporter::GetExtensionList(std::string& append) +void PLYImporter::GetExtensionList(std::set& extensions) { - append.append("*.ply"); + extensions.insert("ply"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/PlyLoader.h b/code/PlyLoader.h index 11c423fef..301bee1d2 100644 --- a/code/PlyLoader.h +++ b/code/PlyLoader.h @@ -85,7 +85,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/Q3DLoader.cpp b/code/Q3DLoader.cpp index fd370d140..8142200a7 100644 --- a/code/Q3DLoader.cpp +++ b/code/Q3DLoader.cpp @@ -81,9 +81,10 @@ bool Q3DImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool } // ------------------------------------------------------------------------------------------------ -void Q3DImporter::GetExtensionList(std::string& append) +void Q3DImporter::GetExtensionList(std::set& extensions) { - append.append("*.q3o;*.q3s"); + extensions.insert("q3o"); + extensions.insert("q3s"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/Q3DLoader.h b/code/Q3DLoader.h index a80b978f9..5edcb8c04 100644 --- a/code/Q3DLoader.h +++ b/code/Q3DLoader.h @@ -78,7 +78,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/RawLoader.cpp b/code/RawLoader.cpp index c50e51093..0ee4470cd 100644 --- a/code/RawLoader.cpp +++ b/code/RawLoader.cpp @@ -72,9 +72,9 @@ bool RAWImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool // ------------------------------------------------------------------------------------------------ // Get the list of all supported file extensions -void RAWImporter::GetExtensionList(std::string& append) +void RAWImporter::GetExtensionList(std::set& extensions) { - append.append("*.raw"); + extensions.insert("raw"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/RawLoader.h b/code/RawLoader.h index f91449246..00c1cacd4 100644 --- a/code/RawLoader.h +++ b/code/RawLoader.h @@ -79,7 +79,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/SMDLoader.cpp b/code/SMDLoader.cpp index ffeac762f..9c0807651 100644 --- a/code/SMDLoader.cpp +++ b/code/SMDLoader.cpp @@ -73,9 +73,10 @@ bool SMDImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool) // ------------------------------------------------------------------------------------------------ // Get a list of all supported file extensions -void SMDImporter::GetExtensionList(std::string& append) +void SMDImporter::GetExtensionList(std::set& extensions) { - append.append("*.smd;*.vta"); + extensions.insert("smd"); + extensions.insert("vta"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/SMDLoader.h b/code/SMDLoader.h index e3f863df4..b1853aae1 100644 --- a/code/SMDLoader.h +++ b/code/SMDLoader.h @@ -204,7 +204,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/STLLoader.cpp b/code/STLLoader.cpp index 8f3697af1..1f1f50d9e 100644 --- a/code/STLLoader.cpp +++ b/code/STLLoader.cpp @@ -80,9 +80,9 @@ bool STLImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool } // ------------------------------------------------------------------------------------------------ -void STLImporter::GetExtensionList(std::string& append) +void STLImporter::GetExtensionList(std::set& extensions) { - append.append("*.stl"); + extensions.insert("stl"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/STLLoader.h b/code/STLLoader.h index 4a59736de..8ae348df2 100644 --- a/code/STLLoader.h +++ b/code/STLLoader.h @@ -78,7 +78,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/code/TerragenLoader.cpp b/code/TerragenLoader.cpp index bfb6d6eb2..f9fa32d98 100644 --- a/code/TerragenLoader.cpp +++ b/code/TerragenLoader.cpp @@ -83,9 +83,9 @@ bool TerragenImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, // ------------------------------------------------------------------------------------------------ // Build a string of all file extensions supported -void TerragenImporter::GetExtensionList(std::string& append) +void TerragenImporter::GetExtensionList(std::set& extensions) { - append.append("*.ter;"); + extensions.insert("ter"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/TerragenLoader.h b/code/TerragenLoader.h index 8e84cf5e8..d417da568 100644 --- a/code/TerragenLoader.h +++ b/code/TerragenLoader.h @@ -87,7 +87,7 @@ public: protected: // ------------------------------------------------------------------- - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- void InternReadFile( const std::string& pFile, aiScene* pScene, diff --git a/code/UnrealLoader.cpp b/code/UnrealLoader.cpp index 424e7a643..b528e367b 100644 --- a/code/UnrealLoader.cpp +++ b/code/UnrealLoader.cpp @@ -79,9 +79,10 @@ bool UnrealImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bo // ------------------------------------------------------------------------------------------------ // Build a string of all file extensions supported -void UnrealImporter::GetExtensionList(std::string& append) +void UnrealImporter::GetExtensionList(std::set& extensions) { - append.append("*.3d;*.uc"); + extensions.insert("3d"); + extensions.insert("uc"); } // ------------------------------------------------------------------------------------------------ @@ -322,7 +323,7 @@ void UnrealImporter::InternReadFile( const std::string& pFile, ++pScene->mNumMeshes; } else { - tri.matIndex = nt-materials.begin(); + tri.matIndex = static_cast(nt-materials.begin()); ++nt->numFaces; } } diff --git a/code/UnrealLoader.h b/code/UnrealLoader.h index b2d492720..ff524bfb5 100644 --- a/code/UnrealLoader.h +++ b/code/UnrealLoader.h @@ -171,7 +171,7 @@ protected: * * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- diff --git a/code/XFileImporter.cpp b/code/XFileImporter.cpp index 354b3e651..1dc14c714 100644 --- a/code/XFileImporter.cpp +++ b/code/XFileImporter.cpp @@ -78,9 +78,9 @@ bool XFileImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, boo } // ------------------------------------------------------------------------------------------------ -void XFileImporter::GetExtensionList(std::string& append) +void XFileImporter::GetExtensionList(std::set& extensions) { - append.append("*.x"); + extensions.insert("x"); } // ------------------------------------------------------------------------------------------------ diff --git a/code/XFileImporter.h b/code/XFileImporter.h index daf8bfcb4..b2d327883 100644 --- a/code/XFileImporter.h +++ b/code/XFileImporter.h @@ -88,7 +88,7 @@ protected: /** Called by Importer::GetExtensionList() for each loaded importer. * See BaseImporter::GetExtensionList() for details */ - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // ------------------------------------------------------------------- /** Imports the given file into the given scene structure. diff --git a/contrib/cppunit-1.12.1/src/cppunit/cppunit.vcproj b/contrib/cppunit-1.12.1/src/cppunit/cppunit.vcproj index a2286c299..e8247acbb 100644 --- a/contrib/cppunit-1.12.1/src/cppunit/cppunit.vcproj +++ b/contrib/cppunit-1.12.1/src/cppunit/cppunit.vcproj @@ -653,11 +653,11 @@ @@ -2694,11 +2694,11 @@ > diff --git a/doc/dox.h b/doc/dox.h index 83e2b5a56..98601dbc5 100644 --- a/doc/dox.h +++ b/doc/dox.h @@ -964,9 +964,9 @@ bool xxxxImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, // ------------------------------------------------------------------------------- // Get list of file extensions handled by this loader -void xxxxImporter::GetExtensionList(std::string& append) +void xxxxImporter::GetExtensionList(std::set& extensions) { - append.append("*.xxx"); + extensions.insert("xxx"); } // ------------------------------------------------------------------------------- diff --git a/include/assimp.hpp b/include/assimp.hpp index 5ab9e2a2c..959f7728f 100644 --- a/include/assimp.hpp +++ b/include/assimp.hpp @@ -329,7 +329,9 @@ public: * automatically. However, to enable automatic detection of the file * format, the input path *must* not have an extension at all. */ - const aiScene* ReadFile( const char* pFile, unsigned int pFlags); + const aiScene* ReadFile( + const char* pFile, + unsigned int pFlags); // ------------------------------------------------------------------- /** Reads the given file from a memory buffer and returns its @@ -367,7 +369,8 @@ public: * external scripts. f you need the full functionality, provide * a custom IOSystem to make Assimp find these files. */ - const aiScene* ReadFileFromMemory( const void* pBuffer, + const aiScene* ReadFileFromMemory( + const void* pBuffer, size_t pLength, unsigned int pFlags, const char* pHint = ""); @@ -389,8 +392,7 @@ public: * cause the scene to be reset to NULL. * * @note The method does nothing if no scene is currently bound - * to the #Importer instance. - */ + * to the #Importer instance. */ const aiScene* ApplyPostProcessing(unsigned int pFlags); // ------------------------------------------------------------------- @@ -398,17 +400,17 @@ public: * * This function is provided for backward compatibility. * See the const char* version for detailled docs. - * @see ReadFile(const char*, pFlags) - */ - const aiScene* ReadFile( const std::string& pFile, unsigned int pFlags); + * @see ReadFile(const char*, pFlags) */ + const aiScene* ReadFile( + const std::string& pFile, + unsigned int pFlags); // ------------------------------------------------------------------- /** Frees the current scene. * * The function does nothing if no scene has previously been * read via ReadFile(). FreeScene() is called automatically by the - * destructor and ReadFile() itself. - */ + * destructor and ReadFile() itself. */ void FreeScene( ); // ------------------------------------------------------------------- @@ -419,65 +421,66 @@ public: * error occurred. The string is never NULL. * * @note The returned function remains valid until one of the - * following methods is called: #ReadFile(), #FreeScene(). - */ + * following methods is called: #ReadFile(), #FreeScene(). */ const char* GetErrorString() const; + // ------------------------------------------------------------------- /** Returns whether a given file extension is supported by ASSIMP. * * @param szExtension Extension to be checked. * Must include a trailing dot '.'. Example: ".3ds", ".md3". * Cases-insensitive. - * @return true if the extension is supported, false otherwise - */ + * @return true if the extension is supported, false otherwise */ bool IsExtensionSupported(const char* szExtension); // ------------------------------------------------------------------- /** @brief Returns whether a given file extension is supported by ASSIMP. * * This function is provided for backward compatibility. - * See the const char* version for detailled docs. - * @see IsExtensionSupported(const char*) - */ + * See the const char* version for detailed and up-to-date docs. + * @see IsExtensionSupported(const char*) */ inline bool IsExtensionSupported(const std::string& szExtension); + // ------------------------------------------------------------------- /** Get a full list of all file extensions supported by ASSIMP. * * If a file extension is contained in the list this does of course not - * mean that ASSIMP is able to load all files with this extension. - * @param szOut String to receive the extension list. It just means there - * is a loader which handles such files. - * Format of the list: "*.3ds;*.obj;*.dae". - */ + * mean that ASSIMP is able to load all files with this extension --- + * it simply means there is an importer loaded which claims to handle + * files with this file extension. + * @param szOut String to receive the extension list. + * Format of the list: "*.3ds;*.obj;*.dae". This is useful for + * use with the WinAPI call GetOpenFileName(Ex). */ void GetExtensionList(aiString& szOut); // ------------------------------------------------------------------- /** @brief Get a full list of all file extensions supported by ASSIMP. * * This function is provided for backward compatibility. - * See the aiString version for detailled docs. - * @see GetExtensionList(aiString&) - */ + * See the aiString version for detailed and up-to-date docs. + * @see GetExtensionList(aiString&)*/ inline void GetExtensionList(std::string& szOut); + // ------------------------------------------------------------------- /** Find the loader corresponding to a specific file extension. * * This is quite similar to IsExtensionSupported() except a * BaseImporter instance is returned. - * @param szExtension Extension to be checked, cases insensitive, - * must include a trailing dot. - * @return NULL if there is no loader for the extension. - */ + * @param szExtension Extension to check for. The following formats + * are recgnized (BAH being the file extension): "BAH" (comparison + * is case-insensitive), ".bah", "*.bah" (wild card and dot + * characters at the beginning of the extension are skipped). + * @return NULL if there is no loader for the extension.*/ BaseImporter* FindLoader (const char* szExtension); + // ------------------------------------------------------------------- /** Returns the scene loaded by the last successful call to ReadFile() * - * @return Current scene or NULL if there is currently no scene loaded - */ + * @return Current scene or NULL if there is currently no scene loaded */ const aiScene* GetScene() const; // ------------------------------------------------------------------- @@ -488,9 +491,9 @@ public: * will return NULL - until a new scene has been loaded via ReadFile(). * * @return Current scene or NULL if there is currently no scene loaded - * @note Under windows, deleting the returned scene manually will - * probably not work properly in applications using static runtime linkage. - */ + * @note --- you know that the aiScene is allocated on Assimp's heap, + * so you need to call Assimp's delete if the heap is not shared? + * And that's why you shouldn't use this method at all. Thanks.*/ aiScene* GetOrphanedScene(); // ------------------------------------------------------------------- @@ -499,17 +502,18 @@ public: * * This refers to the currently loaded file, see #ReadFile(). * @param in Data structure to be filled. - */ + * @note The returned memory statistics refer to the actual + * size of the use data of the aiScene. Heap-related overhead + * is (naturally) not included.*/ void GetMemoryRequirements(aiMemoryInfo& in) const; // ------------------------------------------------------------------- /** Enables "extra verbose" mode. * - * In this mode the data structure is validated after every single - * post processing step to make sure everyone modifies the data - * structure in the defined manner. This is a debug feature and not - * intended for public use. - */ + * 'Extra verbose' means the data structure is validated after *every* + * single post processing step to make sure everyone modifies the data + * structure in a well-defined manner. This is a debug feature and not + * intended for use in production environments. */ void SetExtraVerbose(bool bDo); protected: diff --git a/test/unit/Main.cpp b/test/unit/Main.cpp index 6f4994ab2..7b79bad79 100644 --- a/test/unit/Main.cpp +++ b/test/unit/Main.cpp @@ -30,6 +30,7 @@ int main (int argc, char* argv[]) aiDefaultLogStream_FILE, "AssimpLog_C.txt")); + // ............................................................................ // Informiert Test-Listener ueber Testresultate diff --git a/test/unit/utImporter.cpp b/test/unit/utImporter.cpp index 4c57e58da..307d05899 100644 --- a/test/unit/utImporter.cpp +++ b/test/unit/utImporter.cpp @@ -2,7 +2,6 @@ #include "UnitTestPCH.h" #include "utImporter.h" - #define InputData_BLOCK_SIZE 1310 // test data for Importer::ReadFileFromMemory() - ./test/3DS/CameraRollAnim.3ds @@ -71,9 +70,12 @@ bool TestPlugin :: CanRead( const std::string& pFile, extension == ".linux" || extension == ".windows" ); } -void TestPlugin :: GetExtensionList(std::string& append) +void TestPlugin :: GetExtensionList(std::set& extensions) { - append.append("*.apple;*.mac;*.linux;*.windows"); + extensions.insert("apple"); + extensions.insert("mac"); + extensions.insert("linux"); + extensions.insert("windows"); } void TestPlugin :: InternReadFile( const std::string& pFile, @@ -135,12 +137,13 @@ void ImporterTest :: testStringProperty (void) void ImporterTest :: testPluginInterface (void) { + pImp->RegisterLoader(new TestPlugin()); CPPUNIT_ASSERT(pImp->IsExtensionSupported(".apple")); CPPUNIT_ASSERT(pImp->IsExtensionSupported(".mac")); - CPPUNIT_ASSERT(pImp->IsExtensionSupported(".linux")); - CPPUNIT_ASSERT(pImp->IsExtensionSupported(".windows")); - CPPUNIT_ASSERT(pImp->IsExtensionSupported(".x")); /* x and 3ds must be available of course */ + CPPUNIT_ASSERT(pImp->IsExtensionSupported("*.linux")); + CPPUNIT_ASSERT(pImp->IsExtensionSupported("windows")); + CPPUNIT_ASSERT(pImp->IsExtensionSupported(".x")); /* x and 3ds must be available in this Assimp build, of course! */ CPPUNIT_ASSERT(pImp->IsExtensionSupported(".3ds")); CPPUNIT_ASSERT(!pImp->IsExtensionSupported(".")); diff --git a/test/unit/utImporter.h b/test/unit/utImporter.h index 5e2be6fd3..b03660844 100644 --- a/test/unit/utImporter.h +++ b/test/unit/utImporter.h @@ -49,7 +49,7 @@ public: IOSystem* pIOHandler, bool test) const; // overriden - void GetExtensionList(std::string& append); + void GetExtensionList(std::set& extensions); // overriden void InternReadFile( const std::string& pFile, diff --git a/test/unit/utLimitBoneWeights.cpp b/test/unit/utLimitBoneWeights.cpp index 719c1889b..01e8125e5 100644 --- a/test/unit/utLimitBoneWeights.cpp +++ b/test/unit/utLimitBoneWeights.cpp @@ -37,15 +37,15 @@ void LimitBoneWeightsTest :: setUp (void) // ------------------------------------------------------------------------------------------------ void LimitBoneWeightsTest :: tearDown (void) { - delete this->pcMesh; - delete this->piProcess; + delete pcMesh; + delete piProcess; } // ------------------------------------------------------------------------------------------------ void LimitBoneWeightsTest :: testProcess(void) { // execute the step on the given data - this->piProcess->ProcessMesh(this->pcMesh); + piProcess->ProcessMesh(pcMesh); // check whether everything is ok ... typedef std::vector VertexWeightList; diff --git a/tools/assimp_cmd/Main.cpp b/tools/assimp_cmd/Main.cpp index b0cab8bb0..25d1a7981 100644 --- a/tools/assimp_cmd/Main.cpp +++ b/tools/assimp_cmd/Main.cpp @@ -48,6 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. const char* AICMD_MSG_ABOUT = "------------------------------------------------------ \n" "Open Asset Import Library (Assimp) \n" +"http://assimp.sourceforge.net \n" "Command-line tools \n" "------------------------------------------------------ \n\n" @@ -58,8 +59,15 @@ const char* AICMD_MSG_ABOUT = const char* AICMD_MSG_HELP = -"todo help"; - +"assimp \n\n" +"\tverbs:\n" +"\t\tversion - Display Assimp version\n" +"\t\tlistext - List all known file extension\n" +"\t\tknowext - Check whether a file extension is recognized by Assimp\n" +"\t\textract - Extract an embedded texture from a model\n" +"\t\tdump - Convert a model to binary or XML dumps (ASSBIN/ASSXML)\n" +"\n\n\tUse \'assimp --help\' to get detailed help for a command.\n" +; /*extern*/ Assimp::Importer* globalImporter = NULL; @@ -103,6 +111,28 @@ int main (int argc, char* argv[]) Assimp::Importer imp; globalImporter = &imp; + // assimp listext + // List all file extensions supported by Assimp + if (! ::strcmp(argv[1], "listext")) { + aiString s; + imp.GetExtensionList(s); + + printf(s.data); + return 0; + } + + // assimp knowext + // Check whether a particular file extension is known by us, return 0 on success + if (! ::strcmp(argv[1], "knowext")) { + if (argc<3) { + printf("Expected a file extension to check for!"); + return -10; + } + const bool b = imp.IsExtensionSupported(argv[2]); + printf("File extension %s is %sknown",argv[2],(b?"":"not ")); + return b?0:-1; + } + // assimp dump // Dump a model to a file if (! ::strcmp(argv[1], "dump")) { diff --git a/tools/assimp_cmd/WriteDumb.cpp b/tools/assimp_cmd/WriteDumb.cpp index 683da16e6..8e050cc6a 100644 --- a/tools/assimp_cmd/WriteDumb.cpp +++ b/tools/assimp_cmd/WriteDumb.cpp @@ -934,7 +934,7 @@ void WriteDump(const aiScene* scene, FILE* out, const char* src, const char* cmd int Assimp_Dump (const char** params, unsigned int num) { if (num < 1) { - ::printf("assimp dump: Invalid number of arguments. See \'assimp extract --help\'\r\n"); + ::printf("assimp dump: Invalid number of arguments. See \'assimp dump --help\'\r\n"); return 1; } diff --git a/workspaces/vc8/assimp.vcproj b/workspaces/vc8/assimp.vcproj index 93eab1239..461ad052d 100644 --- a/workspaces/vc8/assimp.vcproj +++ b/workspaces/vc8/assimp.vcproj @@ -3410,6 +3410,14 @@ UsePrecompiledHeader="0" /> + + + @@ -3418,6 +3426,14 @@ UsePrecompiledHeader="0" /> + + + @@ -3426,6 +3442,14 @@ UsePrecompiledHeader="0" /> + + + @@ -3434,6 +3458,14 @@ UsePrecompiledHeader="0" /> + + + @@ -3442,6 +3474,14 @@ UsePrecompiledHeader="0" /> + + + @@ -3450,6 +3490,14 @@ UsePrecompiledHeader="0" /> + + + @@ -3458,6 +3506,14 @@ UsePrecompiledHeader="0" /> + + + @@ -3466,6 +3522,14 @@ UsePrecompiledHeader="0" /> + + +