Added Importer::RegisterLoader() and Importer::UnregisterLoader().

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@105 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/1/head
aramis_acg 2008-08-11 17:49:02 +00:00
parent 9bc8e8701f
commit cefecc1fe7
3 changed files with 122 additions and 9 deletions

View File

@ -281,6 +281,65 @@ Importer::~Importer()
delete mScene;
}
// ------------------------------------------------------------------------------------------------
// Empty and private copy constructor
Importer::Importer(const Importer &other)
{
// empty
}
// ------------------------------------------------------------------------------------------------
aiReturn Importer::RegisterLoader(BaseImporter* pImp)
{
ai_assert(NULL != pImp);
// check whether we would have two loaders for the same file extension now
std::string st;
pImp->GetExtensionList(st);
#ifdef _DEBUG
const char* sz = ::strtok(st.c_str(),";");
while (sz)
{
if (IsExtensionSupported(std::string(sz)))
{
DefaultLogger::get()->error(std::string( "The file extension " ) + sz + " is already in use");
return AI_FAILURE;
}
sz = ::strtok(NULL,";");
}
#endif
// add the loader
this->mImporter.push_back(pImp);
DefaultLogger::get()->info("Registering custom importer: " + st);
return AI_SUCCESS;
}
// ------------------------------------------------------------------------------------------------
aiReturn Importer::UnregisterLoader(BaseImporter* pImp)
{
ai_assert(NULL != pImp);
for (std::vector<BaseImporter*>::iterator
it = mImporter.begin(),end = mImporter.end();
it != end;++it)
{
if (pImp == (*it))
{
mImporter.erase(it);
std::string st;
pImp->GetExtensionList(st);
DefaultLogger::get()->info("Unregistering custom importer: " + st);
return AI_SUCCESS;
}
}
DefaultLogger::get()->warn("Unable to remove importer: importer not found");
return AI_FAILURE;
}
// ------------------------------------------------------------------------------------------------
// Supplies a custom IO handler to the importer to open and access files.
void Importer::SetIOHandler( IOSystem* pIOHandler)
@ -299,16 +358,19 @@ void Importer::SetIOHandler( IOSystem* pIOHandler)
}
return;
}
// ------------------------------------------------------------------------------------------------
IOSystem* Importer::GetIOHandler()
{
return mIOHandler;
}
// ------------------------------------------------------------------------------------------------
bool Importer::IsDefaultIOHandler()
{
return mIsDefaultHandler;
}
#ifdef _DEBUG
// ------------------------------------------------------------------------------------------------
// Validate post process step flags
@ -325,6 +387,7 @@ bool ValidateFlags(unsigned int pFlags)
return true;
}
#endif // ! DEBUG
// ------------------------------------------------------------------------------------------------
// Reads the given file and returns its contents if successful.
const aiScene* Importer::ReadFile( const std::string& pFile, unsigned int pFlags)
@ -383,6 +446,8 @@ const aiScene* Importer::ReadFile( const std::string& pFile, unsigned int pFlags
// TODO: temporary solution, clean up later
mScene->mFlags |= 0x80000000;
}
#else
if (bExtraVerbose)DefaultLogger::get()->warn("Not a debug build, ignoring extra verbose setting");
#endif // ! DEBUG
for( unsigned int a = 0; a < mPostProcessingSteps.size(); a++)
{
@ -420,13 +485,6 @@ const aiScene* Importer::ReadFile( const std::string& pFile, unsigned int pFlags
return mScene;
}
// ------------------------------------------------------------------------------------------------
// Empty and private copy constructor
Importer::Importer(const Importer &other)
{
// empty
}
// ------------------------------------------------------------------------------------------------
// Helper function to check whether an extension is supported by ASSIMP
bool Importer::IsExtensionSupported(const std::string& szExtension)
@ -440,6 +498,7 @@ bool Importer::IsExtensionSupported(const std::string& szExtension)
}
return false;
}
// ------------------------------------------------------------------------------------------------
// Helper function to build a list of all file extensions supported by ASSIMP
void Importer::GetExtensionList(std::string& szOut)
@ -457,6 +516,7 @@ void Importer::GetExtensionList(std::string& szOut)
}
return;
}
// ------------------------------------------------------------------------------------------------
// Set a configuration property
int Importer::SetProperty(const char* szName, int iValue)
@ -482,6 +542,7 @@ int Importer::SetProperty(const char* szName, int iValue)
me.value = iValue;
return AI_PROPERTY_WAS_NOT_EXISTING;
}
// ------------------------------------------------------------------------------------------------
// Get a configuration property
int Importer::GetProperty(const char* szName,
@ -510,6 +571,7 @@ void AddNodeWeight(unsigned int& iScene,const aiNode* pcNode)
for (unsigned int i = 0; i < pcNode->mNumChildren;++i)
AddNodeWeight(iScene,pcNode->mChildren[i]);
}
// ------------------------------------------------------------------------------------------------
// Get the memory requirements of the scene
void Importer::GetMemoryRequirements(aiMemoryInfo& in) const

View File

@ -12,6 +12,7 @@ void Assimp::aiAssert (bool expression, const std::string &message, unsigned int
{
if (!expression)
{
// FIX (Aramis): changed std::cerr to std::cout that the message appears in VS' output window ...
std::cout << "File :" << file << ", line " << uiLine << " : " << message << std::endl;
#ifdef _WIN32

View File

@ -55,6 +55,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "aiTypes.h"
#include "aiConfig.h"
// internal ASSIMP headers - for plugin development
#include "./../code/BaseImporter.h"
#include "./../code/BaseProcess.h"
#define AI_PROPERTY_WAS_NOT_EXISTING 0xffffffff
@ -132,11 +135,58 @@ public:
~Importer();
// -------------------------------------------------------------------
/** Registers a new loader.
*
* @param pImp Importer to be added. The Importer instance takes
* ownership of the pointer, so it will be automatically deleted
* with the Importer instance.
* @return AI_SUCCESS if the loader has been added. The registration
* fails if there is already a loader for a specific file extension.
*/
aiReturn RegisterLoader(BaseImporter* pImp);
// -------------------------------------------------------------------
/** Unregisters a loader.
*
* @param pImp Importer to be unregistered.
* @return AI_SUCCESS if the loader has been removed. The function
* fails if the loader is currently in use (this could happen
* if the #Importer instance is used by more than one thread) or
* if it has not yet been registered.
*/
aiReturn UnregisterLoader(BaseImporter* pImp);
#if 0
// -------------------------------------------------------------------
/** Registers a new post-process step.
*
* @param pImp Post-process step to be added. The Importer instance
* takes ownership of the pointer, so it will be automatically
* deleted with the Importer instance.
* @return AI_SUCCESS if the step has been added.
*/
aiReturn RegisterPPStep(BaseProcess* pImp);
// -------------------------------------------------------------------
/** Unregisters a post-process step.
*
* @param pImp Step to be unregistered.
* @return AI_SUCCESS if the step has been removed. The function
* fails if the step is currently in use (this could happen
* if the #Importer instance is used by more than one thread) or
* if it has not yet been registered.
*/
aiReturn UnregisterPPStep(BaseProcess* pImp);
#endif
// -------------------------------------------------------------------
/** Set a configuration property.
* @param szName Name of the property. All supported properties
* are defined in the aiConfig.g header (the constants start
* with AI_CONFIG_XXX).
* are defined in the aiConfig.g header (the constants share the
* prefix AI_CONFIG_XXX).
* @param iValue New value of the property
* @return Old value of the property or AI_PROPERTY_WAS_NOT_EXISTING
* if the property has not yet been set.