You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-07 12:30:27 +00:00
assimp: Sync with upstream 0201fc5
(cherry picked from commit 78b22393a8)
This commit is contained in:
292
thirdparty/assimp/code/Common/Importer.cpp
vendored
292
thirdparty/assimp/code/Common/Importer.cpp
vendored
@@ -3,9 +3,7 @@
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2019, assimp team
|
||||
|
||||
|
||||
Copyright (c) 2006-2020, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
@@ -78,6 +76,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <assimp/TinyFormatter.h>
|
||||
#include <assimp/Exceptional.h>
|
||||
#include <assimp/Profiler.h>
|
||||
#include <assimp/commonMetaData.h>
|
||||
|
||||
#include <set>
|
||||
#include <memory>
|
||||
#include <cctype>
|
||||
@@ -119,7 +119,7 @@ void* AllocateFromAssimpHeap::operator new ( size_t num_bytes, const std::nothro
|
||||
return AllocateFromAssimpHeap::operator new( num_bytes );
|
||||
}
|
||||
catch( ... ) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,9 +134,8 @@ void* AllocateFromAssimpHeap::operator new[] ( size_t num_bytes) {
|
||||
void* AllocateFromAssimpHeap::operator new[] ( size_t num_bytes, const std::nothrow_t& ) throw() {
|
||||
try {
|
||||
return AllocateFromAssimpHeap::operator new[]( num_bytes );
|
||||
}
|
||||
catch( ... ) {
|
||||
return NULL;
|
||||
} catch( ... ) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +147,7 @@ void AllocateFromAssimpHeap::operator delete[] ( void* data) {
|
||||
// Importer constructor.
|
||||
Importer::Importer()
|
||||
: pimpl( new ImporterPimpl ) {
|
||||
pimpl->mScene = NULL;
|
||||
pimpl->mScene = nullptr;
|
||||
pimpl->mErrorString = "";
|
||||
|
||||
// Allocate a default IO handler
|
||||
@@ -174,14 +173,14 @@ Importer::Importer()
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Destructor of Importer
|
||||
Importer::~Importer()
|
||||
{
|
||||
Importer::~Importer() {
|
||||
// Delete all import plugins
|
||||
DeleteImporterInstanceList(pimpl->mImporter);
|
||||
|
||||
// Delete all post-processing plug-ins
|
||||
for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++)
|
||||
for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); ++a ) {
|
||||
delete pimpl->mPostProcessingSteps[a];
|
||||
}
|
||||
|
||||
// Delete the assigned IO and progress handler
|
||||
delete pimpl->mIOHandler;
|
||||
@@ -199,9 +198,9 @@ Importer::~Importer()
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Register a custom post-processing step
|
||||
aiReturn Importer::RegisterPPStep(BaseProcess* pImp)
|
||||
{
|
||||
ai_assert(NULL != pImp);
|
||||
aiReturn Importer::RegisterPPStep(BaseProcess* pImp) {
|
||||
ai_assert( nullptr != pImp );
|
||||
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
|
||||
pimpl->mPostProcessingSteps.push_back(pImp);
|
||||
@@ -213,9 +212,9 @@ aiReturn Importer::RegisterPPStep(BaseProcess* pImp)
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Register a custom loader plugin
|
||||
aiReturn Importer::RegisterLoader(BaseImporter* pImp)
|
||||
{
|
||||
ai_assert(NULL != pImp);
|
||||
aiReturn Importer::RegisterLoader(BaseImporter* pImp) {
|
||||
ai_assert(nullptr != pImp);
|
||||
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
@@ -242,13 +241,13 @@ aiReturn Importer::RegisterLoader(BaseImporter* pImp)
|
||||
pimpl->mImporter.push_back(pImp);
|
||||
ASSIMP_LOG_INFO_F("Registering custom importer for these file extensions: ", baked);
|
||||
ASSIMP_END_EXCEPTION_REGION(aiReturn);
|
||||
|
||||
return AI_SUCCESS;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Unregister a custom loader plugin
|
||||
aiReturn Importer::UnregisterLoader(BaseImporter* pImp)
|
||||
{
|
||||
aiReturn Importer::UnregisterLoader(BaseImporter* pImp) {
|
||||
if(!pImp) {
|
||||
// unregistering a NULL importer is no problem for us ... really!
|
||||
return AI_SUCCESS;
|
||||
@@ -265,13 +264,13 @@ aiReturn Importer::UnregisterLoader(BaseImporter* pImp)
|
||||
}
|
||||
ASSIMP_LOG_WARN("Unable to remove custom importer: I can't find you ...");
|
||||
ASSIMP_END_EXCEPTION_REGION(aiReturn);
|
||||
|
||||
return AI_FAILURE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Unregister a custom loader plugin
|
||||
aiReturn Importer::UnregisterPPStep(BaseProcess* pImp)
|
||||
{
|
||||
aiReturn Importer::UnregisterPPStep(BaseProcess* pImp) {
|
||||
if(!pImp) {
|
||||
// unregistering a NULL ppstep is no problem for us ... really!
|
||||
return AI_SUCCESS;
|
||||
@@ -288,24 +287,22 @@ aiReturn Importer::UnregisterPPStep(BaseProcess* pImp)
|
||||
}
|
||||
ASSIMP_LOG_WARN("Unable to remove custom post-processing step: I can't find you ..");
|
||||
ASSIMP_END_EXCEPTION_REGION(aiReturn);
|
||||
|
||||
return AI_FAILURE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Supplies a custom IO handler to the importer to open and access files.
|
||||
void Importer::SetIOHandler( IOSystem* pIOHandler)
|
||||
{
|
||||
void Importer::SetIOHandler( IOSystem* pIOHandler) {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
// If the new handler is zero, allocate a default IO implementation.
|
||||
if (!pIOHandler)
|
||||
{
|
||||
if (!pIOHandler) {
|
||||
// Release pointer in the possession of the caller
|
||||
pimpl->mIOHandler = new DefaultIOSystem();
|
||||
pimpl->mIsDefaultHandler = true;
|
||||
}
|
||||
// Otherwise register the custom handler
|
||||
else if (pimpl->mIOHandler != pIOHandler)
|
||||
{
|
||||
} else if (pimpl->mIOHandler != pIOHandler) { // Otherwise register the custom handler
|
||||
delete pimpl->mIOHandler;
|
||||
pimpl->mIOHandler = pIOHandler;
|
||||
pimpl->mIsDefaultHandler = false;
|
||||
@@ -316,29 +313,32 @@ void Importer::SetIOHandler( IOSystem* pIOHandler)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get the currently set IO handler
|
||||
IOSystem* Importer::GetIOHandler() const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
return pimpl->mIOHandler;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Check whether a custom IO handler is currently set
|
||||
bool Importer::IsDefaultIOHandler() const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
return pimpl->mIsDefaultHandler;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Supplies a custom progress handler to get regular callbacks during importing
|
||||
void Importer::SetProgressHandler ( ProgressHandler* pHandler ) {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
|
||||
// If the new handler is zero, allocate a default implementation.
|
||||
if (!pHandler)
|
||||
{
|
||||
if (!pHandler) {
|
||||
// Release pointer in the possession of the caller
|
||||
pimpl->mProgressHandler = new DefaultProgressHandler();
|
||||
pimpl->mIsDefaultProgressHandler = true;
|
||||
}
|
||||
// Otherwise register the custom handler
|
||||
else if (pimpl->mProgressHandler != pHandler)
|
||||
{
|
||||
} else if (pimpl->mProgressHandler != pHandler) { // Otherwise register the custom handler
|
||||
delete pimpl->mProgressHandler;
|
||||
pimpl->mProgressHandler = pHandler;
|
||||
pimpl->mIsDefaultProgressHandler = false;
|
||||
@@ -349,19 +349,22 @@ void Importer::SetProgressHandler ( ProgressHandler* pHandler ) {
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get the currently set progress handler
|
||||
ProgressHandler* Importer::GetProgressHandler() const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
return pimpl->mProgressHandler;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Check whether a custom progress handler is currently set
|
||||
bool Importer::IsDefaultProgressHandler() const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
return pimpl->mIsDefaultProgressHandler;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Validate post process step flags
|
||||
bool _ValidateFlags(unsigned int pFlags)
|
||||
{
|
||||
bool _ValidateFlags(unsigned int pFlags) {
|
||||
if (pFlags & aiProcess_GenSmoothNormals && pFlags & aiProcess_GenNormals) {
|
||||
ASSIMP_LOG_ERROR("#aiProcess_GenSmoothNormals and #aiProcess_GenNormals are incompatible");
|
||||
return false;
|
||||
@@ -375,12 +378,13 @@ bool _ValidateFlags(unsigned int pFlags)
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Free the current scene
|
||||
void Importer::FreeScene( )
|
||||
{
|
||||
void Importer::FreeScene( ) {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
|
||||
delete pimpl->mScene;
|
||||
pimpl->mScene = NULL;
|
||||
pimpl->mScene = nullptr;
|
||||
|
||||
pimpl->mErrorString = "";
|
||||
ASSIMP_END_EXCEPTION_REGION(void);
|
||||
@@ -388,44 +392,48 @@ void Importer::FreeScene( )
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get the current error string, if any
|
||||
const char* Importer::GetErrorString() const
|
||||
{
|
||||
/* Must remain valid as long as ReadFile() or FreeFile() are not called */
|
||||
const char* Importer::GetErrorString() const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
// Must remain valid as long as ReadFile() or FreeFile() are not called
|
||||
return pimpl->mErrorString.c_str();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Enable extra-verbose mode
|
||||
void Importer::SetExtraVerbose(bool bDo)
|
||||
{
|
||||
void Importer::SetExtraVerbose(bool bDo) {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
pimpl->bExtraVerbose = bDo;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get the current scene
|
||||
const aiScene* Importer::GetScene() const
|
||||
{
|
||||
const aiScene* Importer::GetScene() const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
return pimpl->mScene;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Orphan the current scene and return it.
|
||||
aiScene* Importer::GetOrphanedScene()
|
||||
{
|
||||
aiScene* Importer::GetOrphanedScene() {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
aiScene* s = pimpl->mScene;
|
||||
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
pimpl->mScene = NULL;
|
||||
pimpl->mScene = nullptr;
|
||||
|
||||
pimpl->mErrorString = ""; /* reset error string */
|
||||
pimpl->mErrorString = ""; // reset error string
|
||||
ASSIMP_END_EXCEPTION_REGION(aiScene*);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Validate post-processing flags
|
||||
bool Importer::ValidateFlags(unsigned int pFlags) const
|
||||
{
|
||||
bool Importer::ValidateFlags(unsigned int pFlags) const {
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
// run basic checks for mutually exclusive flags
|
||||
if(!_ValidateFlags(pFlags)) {
|
||||
@@ -467,8 +475,9 @@ bool Importer::ValidateFlags(unsigned int pFlags) const
|
||||
const aiScene* Importer::ReadFileFromMemory( const void* pBuffer,
|
||||
size_t pLength,
|
||||
unsigned int pFlags,
|
||||
const char* pHint /*= ""*/)
|
||||
{
|
||||
const char* pHint /*= ""*/) {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
if (!pHint) {
|
||||
pHint = "";
|
||||
@@ -476,12 +485,12 @@ const aiScene* Importer::ReadFileFromMemory( const void* pBuffer,
|
||||
|
||||
if (!pBuffer || !pLength || strlen(pHint) > MaxLenHint ) {
|
||||
pimpl->mErrorString = "Invalid parameters passed to ReadFileFromMemory()";
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// prevent deletion of the previous IOHandler
|
||||
IOSystem* io = pimpl->mIOHandler;
|
||||
pimpl->mIOHandler = NULL;
|
||||
pimpl->mIOHandler = nullptr;
|
||||
|
||||
SetIOHandler(new MemoryIOSystem((const uint8_t*)pBuffer,pLength,io));
|
||||
|
||||
@@ -493,13 +502,13 @@ const aiScene* Importer::ReadFileFromMemory( const void* pBuffer,
|
||||
ReadFile(fbuff,pFlags);
|
||||
SetIOHandler(io);
|
||||
|
||||
ASSIMP_END_EXCEPTION_REGION(const aiScene*);
|
||||
ASSIMP_END_EXCEPTION_REGION_WITH_ERROR_STRING(const aiScene*, pimpl->mErrorString);
|
||||
return pimpl->mScene;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void WriteLogOpening(const std::string& file)
|
||||
{
|
||||
void WriteLogOpening(const std::string& file) {
|
||||
|
||||
ASSIMP_LOG_INFO_F("Load ", file);
|
||||
|
||||
// print a full version dump. This is nice because we don't
|
||||
@@ -550,8 +559,9 @@ void WriteLogOpening(const std::string& file)
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Reads the given file and returns its contents if successful.
|
||||
const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
|
||||
{
|
||||
const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
const std::string pFile(_pFile);
|
||||
|
||||
@@ -580,7 +590,7 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
|
||||
|
||||
pimpl->mErrorString = "Unable to open file \"" + pFile + "\".";
|
||||
ASSIMP_LOG_ERROR(pimpl->mErrorString);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Profiler> profiler(GetPropertyInteger(AI_CONFIG_GLOB_MEASURE_TIME,0)?new Profiler():NULL);
|
||||
@@ -589,7 +599,7 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
|
||||
}
|
||||
|
||||
// Find an worker class which can handle the file
|
||||
BaseImporter* imp = NULL;
|
||||
BaseImporter* imp = nullptr;
|
||||
SetPropertyInteger("importerIndex", -1);
|
||||
for( unsigned int a = 0; a < pimpl->mImporter.size(); a++) {
|
||||
|
||||
@@ -617,7 +627,7 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
|
||||
if( !imp) {
|
||||
pimpl->mErrorString = "No suitable reader found for the file format of file \"" + pFile + "\".";
|
||||
ASSIMP_LOG_ERROR(pimpl->mErrorString);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -633,7 +643,7 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
|
||||
// Dispatch the reading to the worker class for this format
|
||||
const aiImporterDesc *desc( imp->GetInfo() );
|
||||
std::string ext( "unknown" );
|
||||
if ( NULL != desc ) {
|
||||
if ( nullptr != desc ) {
|
||||
ext = desc->mName;
|
||||
}
|
||||
ASSIMP_LOG_INFO("Found a matching importer for this file format: " + ext + "." );
|
||||
@@ -654,15 +664,20 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
|
||||
|
||||
// If successful, apply all active post processing steps to the imported data
|
||||
if( pimpl->mScene) {
|
||||
if (!pimpl->mScene->mMetaData || !pimpl->mScene->mMetaData->HasKey(AI_METADATA_SOURCE_FORMAT)) {
|
||||
if (!pimpl->mScene->mMetaData) {
|
||||
pimpl->mScene->mMetaData = new aiMetadata;
|
||||
}
|
||||
pimpl->mScene->mMetaData->Add(AI_METADATA_SOURCE_FORMAT, aiString(ext));
|
||||
}
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
|
||||
// The ValidateDS process is an exception. It is executed first, even before ScenePreprocessor is called.
|
||||
if (pFlags & aiProcess_ValidateDataStructure)
|
||||
{
|
||||
if (pFlags & aiProcess_ValidateDataStructure) {
|
||||
ValidateDSProcess ds;
|
||||
ds.ExecuteOnScene (this);
|
||||
if (!pimpl->mScene) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
#endif // no validation
|
||||
@@ -695,8 +710,7 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
|
||||
}
|
||||
}
|
||||
#ifdef ASSIMP_CATCH_GLOBAL_EXCEPTIONS
|
||||
catch (std::exception &e)
|
||||
{
|
||||
catch (std::exception &e) {
|
||||
#if (defined _MSC_VER) && (defined _CPPRTTI)
|
||||
// if we have RTTI get the full name of the exception that occurred
|
||||
pimpl->mErrorString = std::string(typeid( e ).name()) + ": " + e.what();
|
||||
@@ -705,24 +719,26 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
|
||||
#endif
|
||||
|
||||
ASSIMP_LOG_ERROR(pimpl->mErrorString);
|
||||
delete pimpl->mScene; pimpl->mScene = NULL;
|
||||
delete pimpl->mScene; pimpl->mScene = nullptr;
|
||||
}
|
||||
#endif // ! ASSIMP_CATCH_GLOBAL_EXCEPTIONS
|
||||
|
||||
// either successful or failure - the pointer expresses it anyways
|
||||
ASSIMP_END_EXCEPTION_REGION(const aiScene*);
|
||||
ASSIMP_END_EXCEPTION_REGION_WITH_ERROR_STRING(const aiScene*, pimpl->mErrorString);
|
||||
|
||||
return pimpl->mScene;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Apply post-processing to the currently bound scene
|
||||
const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags)
|
||||
{
|
||||
const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags) {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
// Return immediately if no scene is active
|
||||
if (!pimpl->mScene) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// If no flags are given, return the current scene with no further action
|
||||
@@ -737,12 +753,11 @@ const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags)
|
||||
#ifndef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
|
||||
// The ValidateDS process plays an exceptional role. It isn't contained in the global
|
||||
// list of post-processing steps, so we need to call it manually.
|
||||
if (pFlags & aiProcess_ValidateDataStructure)
|
||||
{
|
||||
if (pFlags & aiProcess_ValidateDataStructure) {
|
||||
ValidateDSProcess ds;
|
||||
ds.ExecuteOnScene (this);
|
||||
if (!pimpl->mScene) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
#endif // no validation
|
||||
@@ -762,11 +777,9 @@ const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags)
|
||||
|
||||
std::unique_ptr<Profiler> profiler(GetPropertyInteger(AI_CONFIG_GLOB_MEASURE_TIME,0)?new Profiler():NULL);
|
||||
for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++) {
|
||||
|
||||
BaseProcess* process = pimpl->mPostProcessingSteps[a];
|
||||
pimpl->mProgressHandler->UpdatePostProcess(static_cast<int>(a), static_cast<int>(pimpl->mPostProcessingSteps.size()) );
|
||||
if( process->IsActive( pFlags)) {
|
||||
|
||||
if (profiler) {
|
||||
profiler->BeginRegion("postprocess");
|
||||
}
|
||||
@@ -803,24 +816,28 @@ const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags)
|
||||
static_cast<int>(pimpl->mPostProcessingSteps.size()) );
|
||||
|
||||
// update private scene flags
|
||||
if( pimpl->mScene )
|
||||
if( pimpl->mScene ) {
|
||||
ScenePriv(pimpl->mScene)->mPPStepsApplied |= pFlags;
|
||||
}
|
||||
|
||||
// clear any data allocated by post-process steps
|
||||
pimpl->mPPShared->Clean();
|
||||
ASSIMP_LOG_INFO("Leaving post processing pipeline");
|
||||
|
||||
ASSIMP_END_EXCEPTION_REGION(const aiScene*);
|
||||
|
||||
return pimpl->mScene;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const aiScene* Importer::ApplyCustomizedPostProcessing( BaseProcess *rootProcess, bool requestValidation ) {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
|
||||
// Return immediately if no scene is active
|
||||
if ( NULL == pimpl->mScene ) {
|
||||
return NULL;
|
||||
if ( nullptr == pimpl->mScene ) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// If no flags are given, return the current scene with no further action
|
||||
@@ -839,7 +856,7 @@ const aiScene* Importer::ApplyCustomizedPostProcessing( BaseProcess *rootProcess
|
||||
ValidateDSProcess ds;
|
||||
ds.ExecuteOnScene( this );
|
||||
if ( !pimpl->mScene ) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
#endif // no validation
|
||||
@@ -890,46 +907,50 @@ const aiScene* Importer::ApplyCustomizedPostProcessing( BaseProcess *rootProcess
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Helper function to check whether an extension is supported by ASSIMP
|
||||
bool Importer::IsExtensionSupported(const char* szExtension) const
|
||||
{
|
||||
bool Importer::IsExtensionSupported(const char* szExtension) const {
|
||||
return nullptr != GetImporter(szExtension);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
size_t Importer::GetImporterCount() const
|
||||
{
|
||||
size_t Importer::GetImporterCount() const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
return pimpl->mImporter.size();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const aiImporterDesc* Importer::GetImporterInfo(size_t index) const
|
||||
{
|
||||
const aiImporterDesc* Importer::GetImporterInfo(size_t index) const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
if (index >= pimpl->mImporter.size()) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
return pimpl->mImporter[index]->GetInfo();
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
BaseImporter* Importer::GetImporter (size_t index) const
|
||||
{
|
||||
BaseImporter* Importer::GetImporter (size_t index) const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
if (index >= pimpl->mImporter.size()) {
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
return pimpl->mImporter[index];
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Find a loader plugin for a given file extension
|
||||
BaseImporter* Importer::GetImporter (const char* szExtension) const
|
||||
{
|
||||
BaseImporter* Importer::GetImporter (const char* szExtension) const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
return GetImporter(GetImporterIndex(szExtension));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Find a loader plugin for a given file extension
|
||||
size_t Importer::GetImporterIndex (const char* szExtension) const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
ai_assert(nullptr != szExtension);
|
||||
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
@@ -960,8 +981,9 @@ size_t Importer::GetImporterIndex (const char* szExtension) const {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Helper function to build a list of all file extensions supported by ASSIMP
|
||||
void Importer::GetExtensionList(aiString& szOut) const
|
||||
{
|
||||
void Importer::GetExtensionList(aiString& szOut) const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
std::set<std::string> str;
|
||||
for (std::vector<BaseImporter*>::const_iterator i = pimpl->mImporter.begin();i != pimpl->mImporter.end();++i) {
|
||||
@@ -985,8 +1007,9 @@ void Importer::GetExtensionList(aiString& szOut) const
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
bool Importer::SetPropertyInteger(const char* szName, int iValue)
|
||||
{
|
||||
bool Importer::SetPropertyInteger(const char* szName, int iValue) {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
bool existing;
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
existing = SetGenericProperty<int>(pimpl->mIntProperties, szName,iValue);
|
||||
@@ -996,8 +1019,9 @@ bool Importer::SetPropertyInteger(const char* szName, int iValue)
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
bool Importer::SetPropertyFloat(const char* szName, ai_real iValue)
|
||||
{
|
||||
bool Importer::SetPropertyFloat(const char* szName, ai_real iValue) {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
bool existing;
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
existing = SetGenericProperty<ai_real>(pimpl->mFloatProperties, szName,iValue);
|
||||
@@ -1007,8 +1031,9 @@ bool Importer::SetPropertyFloat(const char* szName, ai_real iValue)
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
bool Importer::SetPropertyString(const char* szName, const std::string& value)
|
||||
{
|
||||
bool Importer::SetPropertyString(const char* szName, const std::string& value) {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
bool existing;
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
existing = SetGenericProperty<std::string>(pimpl->mStringProperties, szName,value);
|
||||
@@ -1018,8 +1043,9 @@ bool Importer::SetPropertyString(const char* szName, const std::string& value)
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
bool Importer::SetPropertyMatrix(const char* szName, const aiMatrix4x4& value)
|
||||
{
|
||||
bool Importer::SetPropertyMatrix(const char* szName, const aiMatrix4x4& value) {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
bool existing;
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
existing = SetGenericProperty<aiMatrix4x4>(pimpl->mMatrixProperties, szName,value);
|
||||
@@ -1029,40 +1055,43 @@ bool Importer::SetPropertyMatrix(const char* szName, const aiMatrix4x4& value)
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get a configuration property
|
||||
int Importer::GetPropertyInteger(const char* szName,
|
||||
int iErrorReturn /*= 0xffffffff*/) const
|
||||
{
|
||||
int Importer::GetPropertyInteger(const char* szName, int iErrorReturn /*= 0xffffffff*/) const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
return GetGenericProperty<int>(pimpl->mIntProperties,szName,iErrorReturn);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get a configuration property
|
||||
ai_real Importer::GetPropertyFloat(const char* szName,
|
||||
ai_real iErrorReturn /*= 10e10*/) const
|
||||
{
|
||||
ai_real Importer::GetPropertyFloat(const char* szName, ai_real iErrorReturn /*= 10e10*/) const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
return GetGenericProperty<ai_real>(pimpl->mFloatProperties,szName,iErrorReturn);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get a configuration property
|
||||
const std::string Importer::GetPropertyString(const char* szName,
|
||||
const std::string& iErrorReturn /*= ""*/) const
|
||||
{
|
||||
std::string Importer::GetPropertyString(const char* szName, const std::string& iErrorReturn /*= ""*/) const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
return GetGenericProperty<std::string>(pimpl->mStringProperties,szName,iErrorReturn);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get a configuration property
|
||||
const aiMatrix4x4 Importer::GetPropertyMatrix(const char* szName,
|
||||
const aiMatrix4x4& iErrorReturn /*= aiMatrix4x4()*/) const
|
||||
{
|
||||
aiMatrix4x4 Importer::GetPropertyMatrix(const char* szName, const aiMatrix4x4& iErrorReturn /*= aiMatrix4x4()*/) const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
return GetGenericProperty<aiMatrix4x4>(pimpl->mMatrixProperties,szName,iErrorReturn);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get the memory requirements of a single node
|
||||
inline void AddNodeWeight(unsigned int& iScene,const aiNode* pcNode)
|
||||
{
|
||||
inline
|
||||
void AddNodeWeight(unsigned int& iScene,const aiNode* pcNode) {
|
||||
if ( nullptr == pcNode ) {
|
||||
return;
|
||||
}
|
||||
iScene += sizeof(aiNode);
|
||||
iScene += sizeof(unsigned int) * pcNode->mNumMeshes;
|
||||
iScene += sizeof(void*) * pcNode->mNumChildren;
|
||||
@@ -1074,21 +1103,20 @@ inline void AddNodeWeight(unsigned int& iScene,const aiNode* pcNode)
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get the memory requirements of the scene
|
||||
void Importer::GetMemoryRequirements(aiMemoryInfo& in) const
|
||||
{
|
||||
void Importer::GetMemoryRequirements(aiMemoryInfo& in) const {
|
||||
ai_assert(nullptr != pimpl);
|
||||
|
||||
in = aiMemoryInfo();
|
||||
aiScene* mScene = pimpl->mScene;
|
||||
|
||||
// return if we have no scene loaded
|
||||
if (!pimpl->mScene)
|
||||
if (!mScene)
|
||||
return;
|
||||
|
||||
|
||||
in.total = sizeof(aiScene);
|
||||
|
||||
// add all meshes
|
||||
for (unsigned int i = 0; i < mScene->mNumMeshes;++i)
|
||||
{
|
||||
for (unsigned int i = 0; i < mScene->mNumMeshes;++i) {
|
||||
in.meshes += sizeof(aiMesh);
|
||||
if (mScene->mMeshes[i]->HasPositions()) {
|
||||
in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices;
|
||||
@@ -1105,14 +1133,16 @@ void Importer::GetMemoryRequirements(aiMemoryInfo& in) const
|
||||
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;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
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;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
if (mScene->mMeshes[i]->HasBones()) {
|
||||
in.meshes += sizeof(void*) * mScene->mMeshes[i]->mNumBones;
|
||||
@@ -1131,8 +1161,9 @@ void Importer::GetMemoryRequirements(aiMemoryInfo& in) const
|
||||
in.textures += sizeof(aiTexture);
|
||||
if (pc->mHeight) {
|
||||
in.textures += 4 * pc->mHeight * pc->mWidth;
|
||||
} else {
|
||||
in.textures += pc->mWidth;
|
||||
}
|
||||
else in.textures += pc->mWidth;
|
||||
}
|
||||
in.total += in.textures;
|
||||
|
||||
@@ -1170,5 +1201,6 @@ void Importer::GetMemoryRequirements(aiMemoryInfo& in) const
|
||||
in.materials += pc->mProperties[a]->mDataLength;
|
||||
}
|
||||
}
|
||||
|
||||
in.total += in.materials;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user