2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2018-01-28 18:42:05 +00:00
|
|
|
Copyright (c) 2006-2018, assimp team
|
|
|
|
|
2017-05-09 17:57:36 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
2015-05-19 03:48:29 +00:00
|
|
|
conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 03:52:10 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2015-05-19 03:48:29 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 03:52:10 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 03:52:10 +00:00
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
2015-05-19 03:48:29 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
/** @file Assimp.cpp
|
|
|
|
* @brief Implementation of the Plain-C API
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assimp/cimport.h>
|
|
|
|
#include <assimp/LogStream.hpp>
|
|
|
|
#include <assimp/DefaultLogger.hpp>
|
|
|
|
#include <assimp/Importer.hpp>
|
|
|
|
#include <assimp/importerdesc.h>
|
|
|
|
#include <assimp/scene.h>
|
|
|
|
|
2018-01-06 00:18:33 +00:00
|
|
|
#include <assimp/GenericProperty.h>
|
2015-05-19 03:48:29 +00:00
|
|
|
#include "CInterfaceIOWrapper.h"
|
|
|
|
#include "Importer.h"
|
2018-01-06 00:18:33 +00:00
|
|
|
#include <assimp/Exceptional.h>
|
2015-05-19 03:48:29 +00:00
|
|
|
#include "ScenePrivate.h"
|
2018-01-06 00:18:33 +00:00
|
|
|
#include <assimp/BaseImporter.h>
|
2015-05-19 03:48:29 +00:00
|
|
|
#include <list>
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#ifndef ASSIMP_BUILD_SINGLETHREADED
|
2016-04-05 20:27:40 +00:00
|
|
|
# include <thread>
|
|
|
|
# include <mutex>
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
using namespace Assimp;
|
|
|
|
|
2017-05-29 20:00:13 +00:00
|
|
|
namespace Assimp {
|
2015-05-19 03:57:13 +00:00
|
|
|
// underlying structure for aiPropertyStore
|
|
|
|
typedef BatchLoader::PropertyMap PropertyMap;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Stores the LogStream objects for all active C log streams */
|
|
|
|
struct mpred {
|
|
|
|
bool operator () (const aiLogStream& s0, const aiLogStream& s1) const {
|
|
|
|
return s0.callback<s1.callback&&s0.user<s1.user;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
typedef std::map<aiLogStream, Assimp::LogStream*, mpred> LogStreamMap;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Stores the LogStream objects allocated by #aiGetPredefinedLogStream */
|
|
|
|
typedef std::list<Assimp::LogStream*> PredefLogStreamMap;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Local storage of all active log streams */
|
|
|
|
static LogStreamMap gActiveLogStreams;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Local storage of LogStreams allocated by #aiGetPredefinedLogStream */
|
|
|
|
static PredefLogStreamMap gPredefinedStreams;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Error message of the last failed import process */
|
|
|
|
static std::string gLastErrorString;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** Verbose logging active or not? */
|
|
|
|
static aiBool gVerboseLogging = false;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
/** will return all registered importers. */
|
|
|
|
void GetImporterInstanceList(std::vector< BaseImporter* >& out);
|
|
|
|
|
2016-01-16 14:02:45 +00:00
|
|
|
/** will delete all registered importers. */
|
|
|
|
void DeleteImporterInstanceList(std::vector< BaseImporter* >& out);
|
2015-05-19 03:48:29 +00:00
|
|
|
} // namespace assimp
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef ASSIMP_BUILD_SINGLETHREADED
|
2016-01-27 17:49:01 +00:00
|
|
|
/** Global mutex to manage the access to the log-stream map */
|
2016-04-05 20:27:40 +00:00
|
|
|
static std::mutex gLogStreamMutex;
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Custom LogStream implementation for the C-API
|
2017-05-29 20:00:13 +00:00
|
|
|
class LogToCallbackRedirector : public LogStream {
|
2015-05-19 03:48:29 +00:00
|
|
|
public:
|
2015-10-29 12:04:23 +00:00
|
|
|
explicit LogToCallbackRedirector(const aiLogStream& s)
|
2017-05-29 20:00:13 +00:00
|
|
|
: stream (s) {
|
|
|
|
ai_assert(NULL != s.callback);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
~LogToCallbackRedirector() {
|
2015-05-19 03:48:29 +00:00
|
|
|
#ifndef ASSIMP_BUILD_SINGLETHREADED
|
2016-04-05 20:27:40 +00:00
|
|
|
std::lock_guard<std::mutex> lock(gLogStreamMutex);
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
2015-05-19 03:57:13 +00:00
|
|
|
// (HACK) Check whether the 'stream.user' pointer points to a
|
|
|
|
// custom LogStream allocated by #aiGetPredefinedLogStream.
|
|
|
|
// In this case, we need to delete it, too. Of course, this
|
|
|
|
// might cause strange problems, but the chance is quite low.
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
PredefLogStreamMap::iterator it = std::find(gPredefinedStreams.begin(),
|
|
|
|
gPredefinedStreams.end(), (Assimp::LogStream*)stream.user);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
if (it != gPredefinedStreams.end()) {
|
|
|
|
delete *it;
|
|
|
|
gPredefinedStreams.erase(it);
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
/** @copydoc LogStream::write */
|
|
|
|
void write(const char* message) {
|
|
|
|
stream.callback(message,stream.user);
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
private:
|
2015-05-19 03:57:13 +00:00
|
|
|
aiLogStream stream;
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-05-29 20:00:13 +00:00
|
|
|
void ReportSceneNotFoundError() {
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_ERROR("Unable to find the Assimp::Importer for this aiScene. "
|
2015-05-19 03:57:13 +00:00
|
|
|
"The C-API does not accept scenes produced by the C++ API and vice versa");
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2016-11-22 20:17:47 +00:00
|
|
|
ai_assert(false);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
// Reads the given file and returns its content.
|
2017-05-29 20:00:13 +00:00
|
|
|
const aiScene* aiImportFile( const char* pFile, unsigned int pFlags) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return aiImportFileEx(pFile,pFlags,NULL);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-05-29 20:00:13 +00:00
|
|
|
const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags, aiFileIO* pFS) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return aiImportFileExWithProperties(pFile, pFlags, pFS, NULL);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-05-29 20:00:13 +00:00
|
|
|
const aiScene* aiImportFileExWithProperties( const char* pFile, unsigned int pFlags,
|
|
|
|
aiFileIO* pFS, const aiPropertyStore* props) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ai_assert(NULL != pFile);
|
|
|
|
|
|
|
|
const aiScene* scene = NULL;
|
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
|
|
|
|
// create an Importer for this file
|
|
|
|
Assimp::Importer* imp = new Assimp::Importer();
|
|
|
|
|
|
|
|
// copy properties
|
|
|
|
if(props) {
|
|
|
|
const PropertyMap* pp = reinterpret_cast<const PropertyMap*>(props);
|
|
|
|
ImporterPimpl* pimpl = imp->Pimpl();
|
|
|
|
pimpl->mIntProperties = pp->ints;
|
|
|
|
pimpl->mFloatProperties = pp->floats;
|
|
|
|
pimpl->mStringProperties = pp->strings;
|
|
|
|
pimpl->mMatrixProperties = pp->matrices;
|
|
|
|
}
|
|
|
|
// setup a custom IO system if necessary
|
2017-05-29 20:00:13 +00:00
|
|
|
if (pFS) {
|
2015-05-19 03:57:13 +00:00
|
|
|
imp->SetIOHandler( new CIOSystemWrapper (pFS) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// and have it read the file
|
|
|
|
scene = imp->ReadFile( pFile, pFlags);
|
|
|
|
|
|
|
|
// if succeeded, store the importer in the scene and keep it alive
|
|
|
|
if( scene) {
|
|
|
|
ScenePrivateData* priv = const_cast<ScenePrivateData*>( ScenePriv(scene) );
|
|
|
|
priv->mOrigImporter = imp;
|
2017-05-29 20:00:13 +00:00
|
|
|
} else {
|
2015-05-19 03:57:13 +00:00
|
|
|
// if failed, extract error code and destroy the import
|
|
|
|
gLastErrorString = imp->GetErrorString();
|
|
|
|
delete imp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return imported data. If the import failed the pointer is NULL anyways
|
|
|
|
ASSIMP_END_EXCEPTION_REGION(const aiScene*);
|
2017-05-29 20:00:13 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
return scene;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
const aiScene* aiImportFileFromMemory(
|
2015-05-19 03:57:13 +00:00
|
|
|
const char* pBuffer,
|
|
|
|
unsigned int pLength,
|
|
|
|
unsigned int pFlags,
|
|
|
|
const char* pHint)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
return aiImportFileFromMemoryWithProperties(pBuffer, pLength, pFlags, pHint, NULL);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
const aiScene* aiImportFileFromMemoryWithProperties(
|
2015-05-19 03:57:13 +00:00
|
|
|
const char* pBuffer,
|
|
|
|
unsigned int pLength,
|
|
|
|
unsigned int pFlags,
|
|
|
|
const char* pHint,
|
|
|
|
const aiPropertyStore* props)
|
|
|
|
{
|
2016-01-27 17:49:01 +00:00
|
|
|
ai_assert( NULL != pBuffer );
|
|
|
|
ai_assert( 0 != pLength );
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
const aiScene* scene = NULL;
|
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
|
|
|
|
// create an Importer for this file
|
|
|
|
Assimp::Importer* imp = new Assimp::Importer();
|
|
|
|
|
|
|
|
// copy properties
|
|
|
|
if(props) {
|
|
|
|
const PropertyMap* pp = reinterpret_cast<const PropertyMap*>(props);
|
|
|
|
ImporterPimpl* pimpl = imp->Pimpl();
|
|
|
|
pimpl->mIntProperties = pp->ints;
|
|
|
|
pimpl->mFloatProperties = pp->floats;
|
|
|
|
pimpl->mStringProperties = pp->strings;
|
|
|
|
pimpl->mMatrixProperties = pp->matrices;
|
|
|
|
}
|
|
|
|
|
|
|
|
// and have it read the file from the memory buffer
|
|
|
|
scene = imp->ReadFileFromMemory( pBuffer, pLength, pFlags,pHint);
|
|
|
|
|
|
|
|
// if succeeded, store the importer in the scene and keep it alive
|
|
|
|
if( scene) {
|
|
|
|
ScenePrivateData* priv = const_cast<ScenePrivateData*>( ScenePriv(scene) );
|
|
|
|
priv->mOrigImporter = imp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// if failed, extract error code and destroy the import
|
|
|
|
gLastErrorString = imp->GetErrorString();
|
|
|
|
delete imp;
|
|
|
|
}
|
|
|
|
// return imported data. If the import failed the pointer is NULL anyways
|
|
|
|
ASSIMP_END_EXCEPTION_REGION(const aiScene*);
|
|
|
|
return scene;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
// Releases all resources associated with the given import process.
|
2015-05-19 03:48:29 +00:00
|
|
|
void aiReleaseImport( const aiScene* pScene)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
if (!pScene) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2018-07-25 13:11:24 +00:00
|
|
|
aiReleaseDefaultMaterial();
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// find the importer associated with this data
|
|
|
|
const ScenePrivateData* priv = ScenePriv(pScene);
|
|
|
|
if( !priv || !priv->mOrigImporter) {
|
|
|
|
delete pScene;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// deleting the Importer also deletes the scene
|
|
|
|
// Note: the reason that this is not written as 'delete priv->mOrigImporter'
|
|
|
|
// is a suspected bug in gcc 4.4+ (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52339)
|
|
|
|
Importer* importer = priv->mOrigImporter;
|
|
|
|
delete importer;
|
|
|
|
}
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API const aiScene* aiApplyPostProcessing(const aiScene* pScene,
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int pFlags)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
const aiScene* sc = NULL;
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// find the importer associated with this data
|
|
|
|
const ScenePrivateData* priv = ScenePriv(pScene);
|
|
|
|
if( !priv || !priv->mOrigImporter) {
|
|
|
|
ReportSceneNotFoundError();
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
sc = priv->mOrigImporter->ApplyPostProcessing(pFlags);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
if (!sc) {
|
|
|
|
aiReleaseImport(pScene);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(const aiScene*);
|
|
|
|
return sc;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
2016-01-27 17:49:01 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2016-04-05 20:27:40 +00:00
|
|
|
ASSIMP_API const aiScene *aiApplyCustomizedPostProcessing( const aiScene *scene,
|
|
|
|
BaseProcess* process,
|
2016-01-27 17:49:01 +00:00
|
|
|
bool requestValidation ) {
|
|
|
|
const aiScene* sc( NULL );
|
|
|
|
|
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
|
|
|
|
// find the importer associated with this data
|
|
|
|
const ScenePrivateData* priv = ScenePriv( scene );
|
|
|
|
if ( NULL == priv || NULL == priv->mOrigImporter ) {
|
|
|
|
ReportSceneNotFoundError();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc = priv->mOrigImporter->ApplyCustomizedPostProcessing( process, requestValidation );
|
|
|
|
|
|
|
|
if ( !sc ) {
|
|
|
|
aiReleaseImport( scene );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSIMP_END_EXCEPTION_REGION( const aiScene* );
|
2016-04-05 20:27:40 +00:00
|
|
|
|
2016-01-27 17:49:01 +00:00
|
|
|
return sc;
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void CallbackToLogRedirector (const char* msg, char* dt)
|
|
|
|
{
|
2016-01-27 17:49:01 +00:00
|
|
|
ai_assert( NULL != msg );
|
|
|
|
ai_assert( NULL != dt );
|
2015-05-19 03:57:13 +00:00
|
|
|
LogStream* s = (LogStream*)dt;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
s->write(msg);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API aiLogStream aiGetPredefinedLogStream(aiDefaultLogStream pStream,const char* file)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
aiLogStream sout;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
LogStream* stream = LogStream::createDefaultStream(pStream,file);
|
|
|
|
if (!stream) {
|
|
|
|
sout.callback = NULL;
|
|
|
|
sout.user = NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sout.callback = &CallbackToLogRedirector;
|
|
|
|
sout.user = (char*)stream;
|
|
|
|
}
|
|
|
|
gPredefinedStreams.push_back(stream);
|
|
|
|
ASSIMP_END_EXCEPTION_REGION(aiLogStream);
|
|
|
|
return sout;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiAttachLogStream( const aiLogStream* stream )
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
#ifndef ASSIMP_BUILD_SINGLETHREADED
|
2016-04-05 20:27:40 +00:00
|
|
|
std::lock_guard<std::mutex> lock(gLogStreamMutex);
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
LogStream* lg = new LogToCallbackRedirector(*stream);
|
|
|
|
gActiveLogStreams[*stream] = lg;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
if (DefaultLogger::isNullLogger()) {
|
|
|
|
DefaultLogger::create(NULL,(gVerboseLogging == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL));
|
|
|
|
}
|
|
|
|
DefaultLogger::get()->attachStream(lg);
|
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API aiReturn aiDetachLogStream( const aiLogStream* stream)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
#ifndef ASSIMP_BUILD_SINGLETHREADED
|
2016-04-05 20:27:40 +00:00
|
|
|
std::lock_guard<std::mutex> lock(gLogStreamMutex);
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
2016-01-27 17:49:01 +00:00
|
|
|
// find the log-stream associated with this data
|
2015-05-19 03:57:13 +00:00
|
|
|
LogStreamMap::iterator it = gActiveLogStreams.find( *stream);
|
|
|
|
// it should be there... else the user is playing fools with us
|
|
|
|
if( it == gActiveLogStreams.end()) {
|
|
|
|
return AI_FAILURE;
|
|
|
|
}
|
|
|
|
DefaultLogger::get()->detatchStream( it->second );
|
|
|
|
delete it->second;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
gActiveLogStreams.erase( it);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
if (gActiveLogStreams.empty()) {
|
|
|
|
DefaultLogger::kill();
|
|
|
|
}
|
|
|
|
ASSIMP_END_EXCEPTION_REGION(aiReturn);
|
|
|
|
return AI_SUCCESS;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiDetachAllLogStreams(void)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
2015-05-19 03:48:29 +00:00
|
|
|
#ifndef ASSIMP_BUILD_SINGLETHREADED
|
2016-04-05 20:27:40 +00:00
|
|
|
std::lock_guard<std::mutex> lock(gLogStreamMutex);
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
2016-02-04 19:43:02 +00:00
|
|
|
Logger *logger( DefaultLogger::get() );
|
|
|
|
if ( NULL == logger ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
for (LogStreamMap::iterator it = gActiveLogStreams.begin(); it != gActiveLogStreams.end(); ++it) {
|
2016-02-04 19:43:02 +00:00
|
|
|
logger->detatchStream( it->second );
|
2015-05-19 03:57:13 +00:00
|
|
|
delete it->second;
|
|
|
|
}
|
|
|
|
gActiveLogStreams.clear();
|
|
|
|
DefaultLogger::kill();
|
2016-04-05 20:27:40 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiEnableVerboseLogging(aiBool d)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
if (!DefaultLogger::isNullLogger()) {
|
|
|
|
DefaultLogger::get()->setLogSeverity((d == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL));
|
|
|
|
}
|
|
|
|
gVerboseLogging = d;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
// Returns the error text of the last failed import process.
|
2015-05-19 03:48:29 +00:00
|
|
|
const char* aiGetErrorString()
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
return gLastErrorString.c_str();
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------------------------
|
|
|
|
// Return the description of a importer given its index
|
|
|
|
const aiImporterDesc* aiGetImportFormatDescription( size_t pIndex)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
return Importer().GetImporterInfo(pIndex);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------------------------
|
|
|
|
// Return the number of importers
|
|
|
|
size_t aiGetImportFormatCount(void)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
return Importer().GetImporterCount();
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
// Returns the error text of the last failed import process.
|
2015-05-19 03:48:29 +00:00
|
|
|
aiBool aiIsExtensionSupported(const char* szExtension)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
ai_assert(NULL != szExtension);
|
|
|
|
aiBool candoit=AI_FALSE;
|
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// FIXME: no need to create a temporary Importer instance just for that ..
|
|
|
|
Assimp::Importer tmp;
|
|
|
|
candoit = tmp.IsExtensionSupported(std::string(szExtension)) ? AI_TRUE : AI_FALSE;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(aiBool);
|
|
|
|
return candoit;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Get a list of all file extensions supported by ASSIMP
|
|
|
|
void aiGetExtensionList(aiString* szOut)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
ai_assert(NULL != szOut);
|
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// FIXME: no need to create a temporary Importer instance just for that ..
|
|
|
|
Assimp::Importer tmp;
|
|
|
|
tmp.GetExtensionList(*szOut);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Get the memory requirements for a particular import.
|
|
|
|
void aiGetMemoryRequirements(const C_STRUCT aiScene* pIn,
|
2015-05-19 03:57:13 +00:00
|
|
|
C_STRUCT aiMemoryInfo* in)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// find the importer associated with this data
|
|
|
|
const ScenePrivateData* priv = ScenePriv(pIn);
|
|
|
|
if( !priv || !priv->mOrigImporter) {
|
|
|
|
ReportSceneNotFoundError();
|
|
|
|
return;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
return priv->mOrigImporter->GetMemoryRequirements(*in);
|
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API aiPropertyStore* aiCreatePropertyStore(void)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
return reinterpret_cast<aiPropertyStore*>( new PropertyMap() );
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiReleasePropertyStore(aiPropertyStore* p)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
delete reinterpret_cast<PropertyMap*>(p);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Importer::SetPropertyInteger
|
|
|
|
ASSIMP_API void aiSetImportPropertyInteger(aiPropertyStore* p, const char* szName, int value)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
|
|
|
|
SetGenericProperty<int>(pp->ints,szName,value);
|
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Importer::SetPropertyFloat
|
2016-07-15 03:20:16 +00:00
|
|
|
ASSIMP_API void aiSetImportPropertyFloat(aiPropertyStore* p, const char* szName, ai_real value)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
|
2016-07-15 03:20:16 +00:00
|
|
|
SetGenericProperty<ai_real>(pp->floats,szName,value);
|
2015-05-19 03:57:13 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Importer::SetPropertyString
|
|
|
|
ASSIMP_API void aiSetImportPropertyString(aiPropertyStore* p, const char* szName,
|
2015-05-19 03:57:13 +00:00
|
|
|
const C_STRUCT aiString* st)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
if (!st) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
|
|
|
|
SetGenericProperty<std::string>(pp->strings,szName,std::string(st->C_Str()));
|
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Importer::SetPropertyMatrix
|
|
|
|
ASSIMP_API void aiSetImportPropertyMatrix(aiPropertyStore* p, const char* szName,
|
2015-05-19 03:57:13 +00:00
|
|
|
const C_STRUCT aiMatrix4x4* mat)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
if (!mat) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
|
|
|
|
SetGenericProperty<aiMatrix4x4>(pp->matrices,szName,*mat);
|
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Rotation matrix to quaternion
|
|
|
|
ASSIMP_API void aiCreateQuaternionFromMatrix(aiQuaternion* quat,const aiMatrix3x3* mat)
|
|
|
|
{
|
2016-01-27 17:49:01 +00:00
|
|
|
ai_assert( NULL != quat );
|
|
|
|
ai_assert( NULL != mat );
|
2015-05-19 03:57:13 +00:00
|
|
|
*quat = aiQuaternion(*mat);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Matrix decomposition
|
|
|
|
ASSIMP_API void aiDecomposeMatrix(const aiMatrix4x4* mat,aiVector3D* scaling,
|
2015-05-19 03:57:13 +00:00
|
|
|
aiQuaternion* rotation,
|
|
|
|
aiVector3D* position)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2016-01-27 17:49:01 +00:00
|
|
|
ai_assert( NULL != rotation );
|
|
|
|
ai_assert( NULL != position );
|
|
|
|
ai_assert( NULL != scaling );
|
|
|
|
ai_assert( NULL != mat );
|
2015-05-19 03:57:13 +00:00
|
|
|
mat->Decompose(*scaling,*rotation,*position);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Matrix transpose
|
|
|
|
ASSIMP_API void aiTransposeMatrix3(aiMatrix3x3* mat)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
ai_assert(NULL != mat);
|
|
|
|
mat->Transpose();
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiTransposeMatrix4(aiMatrix4x4* mat)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
ai_assert(NULL != mat);
|
|
|
|
mat->Transpose();
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Vector transformation
|
2015-05-19 03:52:10 +00:00
|
|
|
ASSIMP_API void aiTransformVecByMatrix3(aiVector3D* vec,
|
2015-05-19 03:57:13 +00:00
|
|
|
const aiMatrix3x3* mat)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2016-01-27 17:49:01 +00:00
|
|
|
ai_assert( NULL != mat );
|
|
|
|
ai_assert( NULL != vec);
|
2015-05-19 03:57:13 +00:00
|
|
|
*vec *= (*mat);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
ASSIMP_API void aiTransformVecByMatrix4(aiVector3D* vec,
|
2015-05-19 03:57:13 +00:00
|
|
|
const aiMatrix4x4* mat)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2016-01-27 17:49:01 +00:00
|
|
|
ai_assert( NULL != mat );
|
|
|
|
ai_assert( NULL != vec );
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
*vec *= (*mat);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Matrix multiplication
|
|
|
|
ASSIMP_API void aiMultiplyMatrix4(
|
2015-05-19 03:57:13 +00:00
|
|
|
aiMatrix4x4* dst,
|
|
|
|
const aiMatrix4x4* src)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2016-01-27 17:49:01 +00:00
|
|
|
ai_assert( NULL != dst );
|
|
|
|
ai_assert( NULL != src );
|
2015-05-19 03:57:13 +00:00
|
|
|
*dst = (*dst) * (*src);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiMultiplyMatrix3(
|
2015-05-19 03:57:13 +00:00
|
|
|
aiMatrix3x3* dst,
|
|
|
|
const aiMatrix3x3* src)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2016-01-27 17:49:01 +00:00
|
|
|
ai_assert( NULL != dst );
|
|
|
|
ai_assert( NULL != src );
|
2015-05-19 03:57:13 +00:00
|
|
|
*dst = (*dst) * (*src);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Matrix identity
|
|
|
|
ASSIMP_API void aiIdentityMatrix3(
|
2015-05-19 03:57:13 +00:00
|
|
|
aiMatrix3x3* mat)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
ai_assert(NULL != mat);
|
|
|
|
*mat = aiMatrix3x3();
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiIdentityMatrix4(
|
2015-05-19 03:57:13 +00:00
|
|
|
aiMatrix4x4* mat)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
ai_assert(NULL != mat);
|
|
|
|
*mat = aiMatrix4x4();
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API C_STRUCT const aiImporterDesc* aiGetImporterDesc( const char *extension ) {
|
|
|
|
if( NULL == extension ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
const aiImporterDesc *desc( NULL );
|
|
|
|
std::vector< BaseImporter* > out;
|
|
|
|
GetImporterInstanceList( out );
|
|
|
|
for( size_t i = 0; i < out.size(); ++i ) {
|
|
|
|
if( 0 == strncmp( out[ i ]->GetInfo()->mFileExtensions, extension, strlen( extension ) ) ) {
|
|
|
|
desc = out[ i ]->GetInfo();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-16 14:02:45 +00:00
|
|
|
DeleteImporterInstanceList(out);
|
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|