- Redesign the C interface to allow per-import settings.

- Make C-API threadsafe even without boost (no longer a global importer <-> scene map).
- Cleanup headers.
- Change the way how Importer::pimpl is accessed - all users are no longer friends of Importer to avoid spoiling the public interface. Rather, pimpl is exposed via a public member function and anyone having the definition of ImporterPimpl can access it.

THIS IS A BREAKING API CHANGE for anyone using properties with the C API. It is, however, a huge step forward and finally makes our C API functionally equivalent to the C++ interface.

I hope we can adapt all ports as soon as possible. I'd be grateful if the respective maintainers could do this.

Documentation is not yet up to date.

All this is in anticipation to the upcoming 3.0 release, which I'm actively working on.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1111 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/5/head
aramis_acg 2012-01-13 14:07:58 +00:00
parent 20495de804
commit 3f369342d6
8 changed files with 208 additions and 170 deletions

View File

@ -59,9 +59,8 @@ using namespace Assimp;
namespace Assimp namespace Assimp
{ {
// underlying structure for aiPropertyStore
/** Stores the importer objects for all active import processes */ typedef BatchLoader::PropertyMap PropertyMap;
typedef std::map<const aiScene*, Assimp::Importer*> ImporterMap;
/** Stores the LogStream objects for all active C log streams */ /** Stores the LogStream objects for all active C log streams */
struct mpred { struct mpred {
@ -74,9 +73,6 @@ namespace Assimp
/** Stores the LogStream objects allocated by #aiGetPredefinedLogStream */ /** Stores the LogStream objects allocated by #aiGetPredefinedLogStream */
typedef std::list<Assimp::LogStream*> PredefLogStreamMap; typedef std::list<Assimp::LogStream*> PredefLogStreamMap;
/** Local storage of all active import processes */
static ImporterMap gActiveImports;
/** Local storage of all active log streams */ /** Local storage of all active log streams */
static LogStreamMap gActiveLogStreams; static LogStreamMap gActiveLogStreams;
@ -90,22 +86,13 @@ namespace Assimp
static aiBool gVerboseLogging = false; static aiBool gVerboseLogging = false;
} }
/** Configuration properties */
static ImporterPimpl::IntPropertyMap gIntProperties;
static ImporterPimpl::FloatPropertyMap gFloatProperties;
static ImporterPimpl::StringPropertyMap gStringProperties;
#ifdef AI_C_THREADSAFE #ifdef AI_C_THREADSAFE
/** Global mutex to manage the access to the importer map */
static boost::mutex gMutex;
/** Global mutex to manage the access to the logstream map */ /** Global mutex to manage the access to the logstream map */
static boost::mutex gLogStreamMutex; static boost::mutex gLogStreamMutex;
#endif #endif
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Custom LogStream implementation for the C-API // Custom LogStream implementation for the C-API
class LogToCallbackRedirector : public LogStream class LogToCallbackRedirector : public LogStream
@ -147,7 +134,7 @@ private:
void ReportSceneNotFoundError() void ReportSceneNotFoundError()
{ {
DefaultLogger::get()->error("Unable to find the Assimp::Importer for this aiScene. " DefaultLogger::get()->error("Unable to find the Assimp::Importer for this aiScene. "
"Are you playing fools with us? Don't mix cpp and c API. Thanks."); "The C-API does not accept scenes produced by the C++ API and vice versa");
assert(false); assert(false);
} }
@ -160,8 +147,15 @@ const aiScene* aiImportFile( const char* pFile, unsigned int pFlags)
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags, const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags, aiFileIO* pFS)
aiFileIO* pFS) {
return aiImportFileExWithProperties(pFile, pFlags, pFS, NULL);
}
// ------------------------------------------------------------------------------------------------
const aiScene* aiImportFileExWithProperties( const char* pFile, unsigned int pFlags,
aiFileIO* pFS,
const aiPropertyStore* props)
{ {
ai_assert(NULL != pFile); ai_assert(NULL != pFile);
@ -171,18 +165,14 @@ const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags,
// create an Importer for this file // create an Importer for this file
Assimp::Importer* imp = new Assimp::Importer(); Assimp::Importer* imp = new Assimp::Importer();
#ifdef AI_C_THREADSAFE // copy properties
boost::mutex::scoped_lock lock(gMutex); if(props) {
#endif const PropertyMap* pp = reinterpret_cast<const PropertyMap*>(props);
// copy the global property lists to the Importer instance ImporterPimpl* pimpl = imp->Pimpl();
imp->pimpl->mIntProperties = gIntProperties; pimpl->mIntProperties = pp->ints;
imp->pimpl->mFloatProperties = gFloatProperties; pimpl->mFloatProperties = pp->floats;
imp->pimpl->mStringProperties = gStringProperties; pimpl->mStringProperties = pp->strings;
}
#ifdef AI_C_THREADSAFE
lock.unlock();
#endif
// setup a custom IO system if necessary // setup a custom IO system if necessary
if (pFS) { if (pFS) {
imp->SetIOHandler( new CIOSystemWrapper (pFS) ); imp->SetIOHandler( new CIOSystemWrapper (pFS) );
@ -191,12 +181,10 @@ const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags,
// and have it read the file // and have it read the file
scene = imp->ReadFile( pFile, pFlags); scene = imp->ReadFile( pFile, pFlags);
// if succeeded, place it in the collection of active processes // if succeeded, store the importer in the scene and keep it alive
if( scene) { if( scene) {
#ifdef AI_C_THREADSAFE ScenePrivateData* priv = const_cast<ScenePrivateData*>( ScenePriv(scene) );
lock.lock(); priv->mOrigImporter = imp;
#endif
gActiveImports[scene] = imp;
} }
else { else {
// if failed, extract error code and destroy the import // if failed, extract error code and destroy the import
@ -215,6 +203,17 @@ const aiScene* aiImportFileFromMemory(
unsigned int pLength, unsigned int pLength,
unsigned int pFlags, unsigned int pFlags,
const char* pHint) const char* pHint)
{
return aiImportFileFromMemoryWithProperties(pBuffer, pLength, pFlags, pHint, NULL);
}
// ------------------------------------------------------------------------------------------------
const aiScene* aiImportFileFromMemoryWithProperties(
const char* pBuffer,
unsigned int pLength,
unsigned int pFlags,
const char* pHint,
const aiPropertyStore* props)
{ {
ai_assert(NULL != pBuffer && 0 != pLength); ai_assert(NULL != pBuffer && 0 != pLength);
@ -224,27 +223,22 @@ const aiScene* aiImportFileFromMemory(
// create an Importer for this file // create an Importer for this file
Assimp::Importer* imp = new Assimp::Importer(); Assimp::Importer* imp = new Assimp::Importer();
#ifdef AI_C_THREADSAFE // copy properties
boost::mutex::scoped_lock lock(gMutex); if(props) {
#endif const PropertyMap* pp = reinterpret_cast<const PropertyMap*>(props);
// copy the global property lists to the Importer instance ImporterPimpl* pimpl = imp->Pimpl();
imp->pimpl->mIntProperties = gIntProperties; pimpl->mIntProperties = pp->ints;
imp->pimpl->mFloatProperties = gFloatProperties; pimpl->mFloatProperties = pp->floats;
imp->pimpl->mStringProperties = gStringProperties; pimpl->mStringProperties = pp->strings;
}
#ifdef AI_C_THREADSAFE
lock.unlock();
#endif
// and have it read the file from the memory buffer // and have it read the file from the memory buffer
scene = imp->ReadFileFromMemory( pBuffer, pLength, pFlags,pHint); scene = imp->ReadFileFromMemory( pBuffer, pLength, pFlags,pHint);
// if succeeded, place it in the collection of active processes // if succeeded, store the importer in the scene and keep it alive
if( scene) { if( scene) {
#ifdef AI_C_THREADSAFE ScenePrivateData* priv = const_cast<ScenePrivateData*>( ScenePriv(scene) );
lock.lock(); priv->mOrigImporter = imp;
#endif
gActiveImports[scene] = imp;
} }
else { else {
// if failed, extract error code and destroy the import // if failed, extract error code and destroy the import
@ -266,21 +260,16 @@ void aiReleaseImport( const aiScene* pScene)
ASSIMP_BEGIN_EXCEPTION_REGION(); ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE
boost::mutex::scoped_lock lock(gMutex);
#endif
// find the importer associated with this data // find the importer associated with this data
ImporterMap::iterator it = gActiveImports.find( pScene); const ScenePrivateData* priv = ScenePriv(pScene);
// it should be there... else the user is playing fools with us if( !priv || !priv->mOrigImporter) {
if( it == gActiveImports.end()) { delete pScene;
ReportSceneNotFoundError(); }
return; else {
// deleting the Importer also deletes the scene
delete priv->mOrigImporter;
} }
// kill the importer, the data dies with it
delete it->second;
gActiveImports.erase( it);
ASSIMP_END_EXCEPTION_REGION(void); ASSIMP_END_EXCEPTION_REGION(void);
} }
@ -293,27 +282,17 @@ ASSIMP_API const aiScene* aiApplyPostProcessing(const aiScene* pScene,
ASSIMP_BEGIN_EXCEPTION_REGION(); ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE
boost::mutex::scoped_lock lock(gMutex);
#endif
// find the importer associated with this data // find the importer associated with this data
ImporterMap::iterator it = gActiveImports.find( pScene); const ScenePrivateData* priv = ScenePriv(pScene);
// it should be there... else the user is playing fools with us if( !priv || !priv->mOrigImporter) {
if( it == gActiveImports.end()) {
ReportSceneNotFoundError(); ReportSceneNotFoundError();
return NULL; return NULL;
} }
#ifdef AI_C_THREADSAFE
lock.unlock(); sc = priv->mOrigImporter->ApplyPostProcessing(pFlags);
#endif
sc = it->second->ApplyPostProcessing(pFlags);
#ifdef AI_C_THREADSAFE
lock.lock();
#endif
if (!sc) { if (!sc) {
// kill the importer, the data dies with it aiReleaseImport(pScene);
delete it->second;
gActiveImports.erase( it);
return NULL; return NULL;
} }
@ -435,15 +414,7 @@ aiBool aiIsExtensionSupported(const char* szExtension)
aiBool candoit=AI_FALSE; aiBool candoit=AI_FALSE;
ASSIMP_BEGIN_EXCEPTION_REGION(); ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE // FIXME: no need to create a temporary Importer instance just for that ..
boost::mutex::scoped_lock lock(gMutex);
#endif
if (!gActiveImports.empty()) {
return ((*(gActiveImports.begin())).second->IsExtensionSupported( szExtension )) ? AI_TRUE : AI_FALSE;
}
// fixme: no need to create a temporary Importer instance just for that ..
Assimp::Importer tmp; Assimp::Importer tmp;
candoit = tmp.IsExtensionSupported(std::string(szExtension)) ? AI_TRUE : AI_FALSE; candoit = tmp.IsExtensionSupported(std::string(szExtension)) ? AI_TRUE : AI_FALSE;
@ -458,15 +429,7 @@ void aiGetExtensionList(aiString* szOut)
ai_assert(NULL != szOut); ai_assert(NULL != szOut);
ASSIMP_BEGIN_EXCEPTION_REGION(); ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE // FIXME: no need to create a temporary Importer instance just for that ..
boost::mutex::scoped_lock lock(gMutex);
#endif
if (!gActiveImports.empty()) {
(*(gActiveImports.begin())).second->GetExtensionList(*szOut);
return;
}
// fixme: no need to create a temporary Importer instance just for that ..
Assimp::Importer tmp; Assimp::Importer tmp;
tmp.GetExtensionList(*szOut); tmp.GetExtensionList(*szOut);
@ -479,63 +442,62 @@ void aiGetMemoryRequirements(const C_STRUCT aiScene* pIn,
C_STRUCT aiMemoryInfo* in) C_STRUCT aiMemoryInfo* in)
{ {
ASSIMP_BEGIN_EXCEPTION_REGION(); ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE
boost::mutex::scoped_lock lock(gMutex);
#endif
// find the importer associated with this data // find the importer associated with this data
ImporterMap::iterator it = gActiveImports.find( pIn); const ScenePrivateData* priv = ScenePriv(pIn);
// it should be there... else the user is playing fools with us if( !priv || !priv->mOrigImporter) {
if( it == gActiveImports.end()) {
ReportSceneNotFoundError(); ReportSceneNotFoundError();
return; return;
} }
// get memory statistics
#ifdef AI_C_THREADSAFE return priv->mOrigImporter->GetMemoryRequirements(*in);
lock.unlock();
#endif
it->second->GetMemoryRequirements(*in);
ASSIMP_END_EXCEPTION_REGION(void); ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------
ASSIMP_API aiPropertyStore* aiCreatePropertyStore(void)
{
return reinterpret_cast<aiPropertyStore*>( new PropertyMap() );
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API void aiReleasePropertyStore(aiPropertyStore* p)
{
delete reinterpret_cast<PropertyMap*>(p);
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Importer::SetPropertyInteger // Importer::SetPropertyInteger
ASSIMP_API void aiSetImportPropertyInteger(const char* szName, int value) ASSIMP_API void aiSetImportPropertyInteger(aiPropertyStore* p, const char* szName, int value)
{ {
ASSIMP_BEGIN_EXCEPTION_REGION(); ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
boost::mutex::scoped_lock lock(gMutex); SetGenericProperty<int>(pp->ints,szName,value,NULL);
#endif
SetGenericProperty<int>(gIntProperties,szName,value,NULL);
ASSIMP_END_EXCEPTION_REGION(void); ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Importer::SetPropertyFloat // Importer::SetPropertyFloat
ASSIMP_API void aiSetImportPropertyFloat(const char* szName, float value) ASSIMP_API void aiSetImportPropertyFloat(aiPropertyStore* p, const char* szName, float value)
{ {
ASSIMP_BEGIN_EXCEPTION_REGION(); ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
boost::mutex::scoped_lock lock(gMutex); SetGenericProperty<float>(pp->floats,szName,value,NULL);
#endif
SetGenericProperty<float>(gFloatProperties,szName,value,NULL);
ASSIMP_END_EXCEPTION_REGION(void); ASSIMP_END_EXCEPTION_REGION(void);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Importer::SetPropertyString // Importer::SetPropertyString
ASSIMP_API void aiSetImportPropertyString(const char* szName, ASSIMP_API void aiSetImportPropertyString(aiPropertyStore* p, const char* szName,
const C_STRUCT aiString* st) const C_STRUCT aiString* st)
{ {
if (!st) { if (!st) {
return; return;
} }
ASSIMP_BEGIN_EXCEPTION_REGION(); ASSIMP_BEGIN_EXCEPTION_REGION();
#ifdef AI_C_THREADSAFE PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
boost::mutex::scoped_lock lock(gMutex); SetGenericProperty<std::string>(pp->strings,szName,std::string(st->C_Str()),NULL);
#endif
SetGenericProperty<std::string>(gStringProperties,szName,
std::string( st->data ),NULL);
ASSIMP_END_EXCEPTION_REGION(void); ASSIMP_END_EXCEPTION_REGION(void);
} }
@ -574,16 +536,16 @@ ASSIMP_API void aiTransposeMatrix4(aiMatrix4x4* mat)
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Vector transformation // Vector transformation
ASSIMP_API void aiTransformVecByMatrix3(C_STRUCT aiVector3D* vec, ASSIMP_API void aiTransformVecByMatrix3(aiVector3D* vec,
const C_STRUCT aiMatrix3x3* mat) const aiMatrix3x3* mat)
{ {
ai_assert(NULL != mat && NULL != vec); ai_assert(NULL != mat && NULL != vec);
*vec *= (*mat); *vec *= (*mat);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
ASSIMP_API void aiTransformVecByMatrix4(C_STRUCT aiVector3D* vec, ASSIMP_API void aiTransformVecByMatrix4(aiVector3D* vec,
const C_STRUCT aiMatrix4x4* mat) const aiMatrix4x4* mat)
{ {
ai_assert(NULL != mat && NULL != vec); ai_assert(NULL != mat && NULL != vec);
*vec *= (*mat); *vec *= (*mat);
@ -592,8 +554,8 @@ ASSIMP_API void aiTransformVecByMatrix4(C_STRUCT aiVector3D* vec,
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Matrix multiplication // Matrix multiplication
ASSIMP_API void aiMultiplyMatrix4( ASSIMP_API void aiMultiplyMatrix4(
C_STRUCT aiMatrix4x4* dst, aiMatrix4x4* dst,
const C_STRUCT aiMatrix4x4* src) const aiMatrix4x4* src)
{ {
ai_assert(NULL != dst && NULL != src); ai_assert(NULL != dst && NULL != src);
*dst = (*dst) * (*src); *dst = (*dst) * (*src);
@ -601,8 +563,8 @@ ASSIMP_API void aiMultiplyMatrix4(
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
ASSIMP_API void aiMultiplyMatrix3( ASSIMP_API void aiMultiplyMatrix3(
C_STRUCT aiMatrix3x3* dst, aiMatrix3x3* dst,
const C_STRUCT aiMatrix3x3* src) const aiMatrix3x3* src)
{ {
ai_assert(NULL != dst && NULL != src); ai_assert(NULL != dst && NULL != src);
*dst = (*dst) * (*src); *dst = (*dst) * (*src);
@ -611,7 +573,7 @@ ASSIMP_API void aiMultiplyMatrix3(
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Matrix identity // Matrix identity
ASSIMP_API void aiIdentityMatrix3( ASSIMP_API void aiIdentityMatrix3(
C_STRUCT aiMatrix3x3* mat) aiMatrix3x3* mat)
{ {
ai_assert(NULL != mat); ai_assert(NULL != mat);
*mat = aiMatrix3x3(); *mat = aiMatrix3x3();
@ -619,7 +581,7 @@ ASSIMP_API void aiIdentityMatrix3(
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
ASSIMP_API void aiIdentityMatrix4( ASSIMP_API void aiIdentityMatrix4(
C_STRUCT aiMatrix4x4* mat) aiMatrix4x4* mat)
{ {
ai_assert(NULL != mat); ai_assert(NULL != mat);
*mat = aiMatrix4x4(); *mat = aiMatrix4x4();

View File

@ -507,9 +507,10 @@ void BatchLoader::LoadAll()
pp |= aiProcess_ValidateDataStructure; pp |= aiProcess_ValidateDataStructure;
#endif #endif
// setup config properties if necessary // setup config properties if necessary
data->pImporter->pimpl->mFloatProperties = (*it).map.floats; ImporterPimpl* pimpl = data->pImporter->Pimpl();
data->pImporter->pimpl->mIntProperties = (*it).map.ints; pimpl->mFloatProperties = (*it).map.floats;
data->pImporter->pimpl->mStringProperties = (*it).map.strings; pimpl->mIntProperties = (*it).map.ints;
pimpl->mStringProperties = (*it).map.strings;
if (!DefaultLogger::isNullLogger()) if (!DefaultLogger::isNullLogger())
{ {

View File

@ -67,7 +67,7 @@ BaseProcess::~BaseProcess()
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void BaseProcess::ExecuteOnScene( Importer* pImp) void BaseProcess::ExecuteOnScene( Importer* pImp)
{ {
ai_assert(NULL != pImp && NULL != pImp->pimpl->mScene); ai_assert(NULL != pImp && NULL != pImp->Pimpl()->mScene);
progress = pImp->GetProgressHandler(); progress = pImp->GetProgressHandler();
ai_assert(progress); ai_assert(progress);
@ -77,17 +77,17 @@ void BaseProcess::ExecuteOnScene( Importer* pImp)
// catch exceptions thrown inside the PostProcess-Step // catch exceptions thrown inside the PostProcess-Step
try try
{ {
Execute(pImp->pimpl->mScene); Execute(pImp->Pimpl()->mScene);
} catch( const std::exception& err ) { } catch( const std::exception& err ) {
// extract error description // extract error description
pImp->pimpl->mErrorString = err.what(); pImp->Pimpl()->mErrorString = err.what();
DefaultLogger::get()->error(pImp->pimpl->mErrorString); DefaultLogger::get()->error(pImp->Pimpl()->mErrorString);
// and kill the partially imported data // and kill the partially imported data
delete pImp->pimpl->mScene; delete pImp->Pimpl()->mScene;
pImp->pimpl->mScene = NULL; pImp->Pimpl()->mScene = NULL;
} }
} }

View File

@ -46,12 +46,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Assimp { namespace Assimp {
class Importer;
struct ScenePrivateData { struct ScenePrivateData {
ScenePrivateData() ScenePrivateData()
: mPPStepsApplied() : mOrigImporter()
, mPPStepsApplied()
{} {}
// Importer that originally loaded the scene though the C-API
// If set, this object is owned by this private data instance.
Assimp::Importer* mOrigImporter;
// List of postprocessing steps already applied to the scene. // List of postprocessing steps already applied to the scene.
unsigned int mPPStepsApplied; unsigned int mPPStepsApplied;
}; };

View File

@ -70,6 +70,19 @@ struct aiLogStream
char* user; char* user;
}; };
// --------------------------------------------------------------------------------
/** C-API: Represents an opaque set of settings to be used during importing.
* @see aiCreatePropertyStore
* @see aiReleasePropertyStore
* @see aiImportFileExWithProperties
* @see aiSetPropertyInteger
* @see aiSetPropertyFloat
* @see aiSetPropertyString
*/
// --------------------------------------------------------------------------------
struct aiPropertyStore {};
/** Our own C boolean type */ /** Our own C boolean type */
typedef int aiBool; typedef int aiBool;
@ -112,7 +125,8 @@ ASSIMP_API const C_STRUCT aiScene* aiImportFile(
* a successful import. Provide a bitwise combination of the * a successful import. Provide a bitwise combination of the
* #aiPostProcessSteps flags. * #aiPostProcessSteps flags.
* @param pFS aiFileIO structure. Will be used to open the model file itself * @param pFS aiFileIO structure. Will be used to open the model file itself
* and any other files the loader needs to open. * and any other files the loader needs to open. Pass NULL to use the default
* implementation.
* @return Pointer to the imported data or NULL if the import failed. * @return Pointer to the imported data or NULL if the import failed.
* @note Include <aiFileIO.h> for the definition of #aiFileIO. * @note Include <aiFileIO.h> for the definition of #aiFileIO.
*/ */
@ -121,6 +135,18 @@ ASSIMP_API const C_STRUCT aiScene* aiImportFileEx(
unsigned int pFlags, unsigned int pFlags,
C_STRUCT aiFileIO* pFS); C_STRUCT aiFileIO* pFS);
// --------------------------------------------------------------------------------
/** Same as #aiImportFileEx, but adds an extra parameter containing importer settings.
*
* @param pProps #aiPropertyStore instance containing import settings.
* @see aiImportFileEx
*/
ASSIMP_API const C_STRUCT aiScene* aiImportFileExWithProperties(
const char* pFile,
unsigned int pFlags,
C_STRUCT aiFileIO* pFS,
const C_STRUCT aiPropertyStore* pProps);
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
/** Reads the given file from a given memory buffer, /** Reads the given file from a given memory buffer,
* *
@ -156,6 +182,19 @@ ASSIMP_API const C_STRUCT aiScene* aiImportFileFromMemory(
unsigned int pFlags, unsigned int pFlags,
const char* pHint); const char* pHint);
// --------------------------------------------------------------------------------
/** Same as #aiImportFileFromMemory, but adds an extra parameter containing importer settings.
*
* @param pProps #aiPropertyStore instance containing import settings.
* @see aiImportFileFromMemory
*/
ASSIMP_API const C_STRUCT aiScene* aiImportFileFromMemoryWithProperties(
const char* pBuffer,
unsigned int pLength,
unsigned int pFlags,
const char* pHint,
const C_STRUCT aiPropertyStore* pProps);
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
/** Apply post-processing to an already-imported scene. /** Apply post-processing to an already-imported scene.
* *
@ -283,7 +322,7 @@ ASSIMP_API void aiGetExtensionList(
C_STRUCT aiString* szOut); C_STRUCT aiString* szOut);
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
/** Get the storage required by an imported asset /** Get the approximated storage required by an imported asset
* @param pIn Input asset. * @param pIn Input asset.
* @param in Data structure to be filled. * @param in Data structure to be filled.
*/ */
@ -291,6 +330,22 @@ ASSIMP_API void aiGetMemoryRequirements(
const C_STRUCT aiScene* pIn, const C_STRUCT aiScene* pIn,
C_STRUCT aiMemoryInfo* in); C_STRUCT aiMemoryInfo* in);
// --------------------------------------------------------------------------------
/** Create an empty property store. Property stores are used to collect import
* settings.
* @return New property store. Property stores need to be manually destroyed using
* the #aiReleasePropertyStore API function.
*/
ASSIMP_API C_STRUCT aiPropertyStore* aiCreatePropertyStore(void);
// --------------------------------------------------------------------------------
/** Delete a property store.
* @param p Property store to be deleted.
*/
ASSIMP_API void aiReleasePropertyStore(aiPropertyStore* p);
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
/** Set an integer property. /** Set an integer property.
* *
@ -303,6 +358,7 @@ ASSIMP_API void aiGetMemoryRequirements(
* @param value New value for the property * @param value New value for the property
*/ */
ASSIMP_API void aiSetImportPropertyInteger( ASSIMP_API void aiSetImportPropertyInteger(
aiPropertyStore* store,
const char* szName, const char* szName,
int value); int value);
@ -318,6 +374,7 @@ ASSIMP_API void aiSetImportPropertyInteger(
* @param value New value for the property * @param value New value for the property
*/ */
ASSIMP_API void aiSetImportPropertyFloat( ASSIMP_API void aiSetImportPropertyFloat(
aiPropertyStore* store,
const char* szName, const char* szName,
float value); float value);
@ -328,11 +385,13 @@ ASSIMP_API void aiSetImportPropertyFloat(
* interface, properties are always shared by all imports. It is not possible to * interface, properties are always shared by all imports. It is not possible to
* specify them per import. * specify them per import.
* *
* @param property store to modify. Use #aiCreatePropertyStore to obtain a store.
* @param szName Name of the configuration property to be set. All supported * @param szName Name of the configuration property to be set. All supported
* public properties are defined in the aiConfig.h header file (#AI_CONFIG_XXX). * public properties are defined in the aiConfig.h header file (#AI_CONFIG_XXX).
* @param value New value for the property * @param value New value for the property
*/ */
ASSIMP_API void aiSetImportPropertyString( ASSIMP_API void aiSetImportPropertyString(
aiPropertyStore* store,
const char* szName, const char* szName,
const C_STRUCT aiString* st); const C_STRUCT aiString* st);

View File

@ -83,10 +83,6 @@ namespace Assimp {
#define AI_PROPERTY_WAS_NOT_EXISTING 0xffffffff #define AI_PROPERTY_WAS_NOT_EXISTING 0xffffffff
struct aiScene; struct aiScene;
struct aiFileIO;
extern "C" ASSIMP_API const aiScene* aiImportFileEx( const char*, unsigned int, aiFileIO*);
extern "C" ASSIMP_API const aiScene* aiImportFileFromMemory( const char*,
unsigned int,unsigned int,const char*);
/** @namespace Assimp Assimp's CPP-API and all internal APIs */ /** @namespace Assimp Assimp's CPP-API and all internal APIs */
namespace Assimp { namespace Assimp {
@ -117,13 +113,6 @@ namespace Assimp {
*/ */
class ASSIMP_API Importer { class ASSIMP_API Importer {
// for internal use
friend class BaseProcess;
friend class BatchLoader;
friend const aiScene* ::aiImportFileEx( const char*, unsigned int, aiFileIO*);
friend const aiScene* ::aiImportFileFromMemory( const char*,
unsigned int,unsigned int,const char*);
public: public:
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@ -579,6 +568,12 @@ public:
* intended for use in production environments. */ * intended for use in production environments. */
void SetExtraVerbose(bool bDo); void SetExtraVerbose(bool bDo);
// -------------------------------------------------------------------
/** Private, do not use. */
ImporterPimpl* Pimpl() { return pimpl; };
const ImporterPimpl* Pimpl() const { return pimpl; };
protected: protected:
// Just because we don't want you to know how we're hacking around. // Just because we don't want you to know how we're hacking around.

View File

@ -54,7 +54,7 @@ extern "C" {
#endif #endif
struct aiScene; // aiScene.h struct aiScene; // aiScene.h
struct aiFileIO; // aiFileIO.h
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
/** Describes an file format which Assimp can export to. Use #aiGetExportFormatCount() to /** Describes an file format which Assimp can export to. Use #aiGetExportFormatCount() to
@ -102,7 +102,8 @@ ASSIMP_API const C_STRUCT aiExportFormatDesc* aiGetExportFormatDescription( size
* @param pIn Valid scene to be copied * @param pIn Valid scene to be copied
* @param pOut User-allocated scene to be filled. * @param pOut User-allocated scene to be filled.
*/ */
ASSIMP_API void aiCopyScene(const C_STRUCT aiScene* pIn, C_STRUCT aiScene** pOut); ASSIMP_API void aiCopyScene(const C_STRUCT aiScene* pIn,
C_STRUCT aiScene** pOut);
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
/** Exports the given scene to a chosen file format and writes the result file(s) to disk. /** Exports the given scene to a chosen file format and writes the result file(s) to disk.
@ -138,7 +139,10 @@ ASSIMP_API void aiCopyScene(const C_STRUCT aiScene* pIn, C_STRUCT aiScene** pOut
* triangulate data so they would run the step anyway. * triangulate data so they would run the step anyway.
* @return a status code indicating the result of the export * @return a status code indicating the result of the export
*/ */
ASSIMP_API aiReturn aiExportScene( const C_STRUCT aiScene* pScene, const char* pFormatId, const char* pFileName, unsigned int pPreprocessing); ASSIMP_API aiReturn aiExportScene( const C_STRUCT aiScene* pScene,
const char* pFormatId,
const char* pFileName,
unsigned int pPreprocessing);
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
@ -149,11 +153,16 @@ ASSIMP_API aiReturn aiExportScene( const C_STRUCT aiScene* pScene, const char* p
* @param pFileName Output file to write * @param pFileName Output file to write
* @param pIO custom IO implementation to be used. Use this if you use your own storage methods. * @param pIO custom IO implementation to be used. Use this if you use your own storage methods.
* If none is supplied, a default implementation using standard file IO is used. Note that * If none is supplied, a default implementation using standard file IO is used. Note that
* #aiExportSceneToBlob is provided as convienience function to export to memory buffers. * #aiExportSceneToBlob is provided as convenience function to export to memory buffers.
* @param pPreprocessing Please see the documentation for #aiExportScene * @param pPreprocessing Please see the documentation for #aiExportScene
* @return a status code indicating the result of the export * @return a status code indicating the result of the export
* @note Include <aiFileIO.h> for the definition of #aiFileIO.
*/ */
ASSIMP_API aiReturn aiExportSceneEx( const C_STRUCT aiScene* pScene, const char* pFormatId, const char* pFileName, C_STRUCT aiFileIO* pIO, unsigned int pPreprocessing ); ASSIMP_API aiReturn aiExportSceneEx( const C_STRUCT aiScene* pScene,
const char* pFormatId,
const char* pFileName,
C_STRUCT aiFileIO* pIO,
unsigned int pPreprocessing );
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------

View File

@ -148,15 +148,16 @@ DWORD WINAPI LoadThreadProc(LPVOID lpParameter)
// get current time // get current time
double fCur = (double)timeGetTime(); double fCur = (double)timeGetTime();
aiSetImportPropertyInteger(AI_CONFIG_IMPORT_TER_MAKE_UVS,1); aiPropertyStore* props = aiCreatePropertyStore();
aiSetImportPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE,g_smoothAngle); aiSetImportPropertyInteger(props,AI_CONFIG_IMPORT_TER_MAKE_UVS,1);
aiSetImportPropertyInteger(AI_CONFIG_PP_SBP_REMOVE,nopointslines ? aiPrimitiveType_LINE | aiPrimitiveType_POINT : 0 ); aiSetImportPropertyFloat(props,AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE,g_smoothAngle);
aiSetImportPropertyInteger(props,AI_CONFIG_PP_SBP_REMOVE,nopointslines ? aiPrimitiveType_LINE | aiPrimitiveType_POINT : 0 );
aiSetImportPropertyInteger(AI_CONFIG_GLOB_MEASURE_TIME,1); aiSetImportPropertyInteger(props,AI_CONFIG_GLOB_MEASURE_TIME,1);
//aiSetImportPropertyInteger(AI_CONFIG_PP_PTV_KEEP_HIERARCHY,1); //aiSetImportPropertyInteger(props,AI_CONFIG_PP_PTV_KEEP_HIERARCHY,1);
// Call ASSIMPs C-API to load the file // Call ASSIMPs C-API to load the file
g_pcAsset->pcScene = (aiScene*)aiImportFile(g_szFileName, g_pcAsset->pcScene = (aiScene*)aiImportFileExWithProperties(g_szFileName,
ppsteps | /* configurable pp steps */ ppsteps | /* configurable pp steps */
aiProcess_GenSmoothNormals | // generate smooth normal vectors if not existing aiProcess_GenSmoothNormals | // generate smooth normal vectors if not existing
@ -164,7 +165,11 @@ DWORD WINAPI LoadThreadProc(LPVOID lpParameter)
aiProcess_Triangulate | // triangulate polygons with more than 3 edges aiProcess_Triangulate | // triangulate polygons with more than 3 edges
aiProcess_ConvertToLeftHanded | // convert everything to D3D left handed space aiProcess_ConvertToLeftHanded | // convert everything to D3D left handed space
aiProcess_SortByPType | // make 'clean' meshes which consist of a single typ of primitives aiProcess_SortByPType | // make 'clean' meshes which consist of a single typ of primitives
0); 0,
NULL,
props);
aiReleasePropertyStore(props);
// get the end time of zje operation, calculate delta t // get the end time of zje operation, calculate delta t
double fEnd = (double)timeGetTime(); double fEnd = (double)timeGetTime();