2008-05-09 17:24:28 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
2012-02-03 03:38:30 +00:00
|
|
|
Open Asset Import Library (assimp)
|
2008-05-09 17:24:28 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
Copyright (c) 2006-2012, assimp team
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
|
|
|
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.
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
* Neither the name of the assimp team, nor the names of its
|
2008-05-09 17:24:28 +00:00
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
2012-02-03 03:38:30 +00:00
|
|
|
written permission of the assimp team.
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
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
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
2009-05-28 11:32:54 +00:00
|
|
|
/** @file Assimp.cpp
|
|
|
|
* @brief Implementation of the Plain-C API
|
|
|
|
*/
|
2008-10-13 16:45:48 +00:00
|
|
|
|
2012-02-03 17:04:06 +00:00
|
|
|
#include "../include/assimp/cimport.h"
|
2015-04-15 23:00:17 +00:00
|
|
|
#include "../include/assimp/LogStream.hpp"
|
|
|
|
#include "../include/assimp/DefaultLogger.hpp"
|
|
|
|
#include "../include/assimp/importerdesc.h"
|
|
|
|
#include "../include/assimp/scene.h"
|
2008-08-28 17:35:36 +00:00
|
|
|
|
|
|
|
#include "GenericProperty.h"
|
2011-03-08 16:09:54 +00:00
|
|
|
#include "CInterfaceIOWrapper.h"
|
2015-04-15 23:00:17 +00:00
|
|
|
#include "Importer.h"
|
|
|
|
#include "Exceptional.h"
|
|
|
|
#include "ScenePrivate.h"
|
|
|
|
#include "BaseImporter.h"
|
|
|
|
#include <list>
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2014-01-16 09:57:51 +00:00
|
|
|
#ifndef ASSIMP_BUILD_SINGLETHREADED
|
2008-05-09 17:24:28 +00:00
|
|
|
# include <boost/thread/thread.hpp>
|
|
|
|
# include <boost/thread/mutex.hpp>
|
|
|
|
#endif
|
2009-05-28 11:32:54 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-08-08 18:29:05 +00:00
|
|
|
using namespace Assimp;
|
2009-05-28 11:32:54 +00:00
|
|
|
|
2009-08-18 16:17:27 +00:00
|
|
|
namespace Assimp
|
|
|
|
{
|
2012-01-13 14:07:58 +00:00
|
|
|
// underlying structure for aiPropertyStore
|
|
|
|
typedef BatchLoader::PropertyMap PropertyMap;
|
2009-05-28 11:32:54 +00:00
|
|
|
|
2009-08-18 16:17:27 +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;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2009-08-18 16:17:27 +00:00
|
|
|
/** Stores the LogStream objects allocated by #aiGetPredefinedLogStream */
|
|
|
|
typedef std::list<Assimp::LogStream*> PredefLogStreamMap;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2009-08-18 16:17:27 +00:00
|
|
|
/** Local storage of all active log streams */
|
|
|
|
static LogStreamMap gActiveLogStreams;
|
2009-05-28 11:32:54 +00:00
|
|
|
|
2009-08-18 16:17:27 +00:00
|
|
|
/** Local storage of LogStreams allocated by #aiGetPredefinedLogStream */
|
|
|
|
static PredefLogStreamMap gPredefinedStreams;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2009-08-18 16:17:27 +00:00
|
|
|
/** Error message of the last failed import process */
|
|
|
|
static std::string gLastErrorString;
|
|
|
|
|
|
|
|
/** Verbose logging active or not? */
|
|
|
|
static aiBool gVerboseLogging = false;
|
2014-12-01 19:34:15 +00:00
|
|
|
|
|
|
|
/** will return all registered importers. */
|
|
|
|
void GetImporterInstanceList(std::vector< BaseImporter* >& out);
|
|
|
|
|
|
|
|
} // namespace assimp
|
2009-05-28 11:32:54 +00:00
|
|
|
|
2008-08-28 17:35:36 +00:00
|
|
|
|
2014-01-16 09:57:51 +00:00
|
|
|
#ifndef ASSIMP_BUILD_SINGLETHREADED
|
2009-05-28 11:32:54 +00:00
|
|
|
/** Global mutex to manage the access to the logstream map */
|
|
|
|
static boost::mutex gLogStreamMutex;
|
2008-05-09 17:24:28 +00:00
|
|
|
#endif
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-08-28 17:35:36 +00:00
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Custom LogStream implementation for the C-API
|
|
|
|
class LogToCallbackRedirector : public LogStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LogToCallbackRedirector(const aiLogStream& s)
|
|
|
|
: stream (s) {
|
|
|
|
ai_assert(NULL != s.callback);
|
|
|
|
}
|
2008-08-28 17:35:36 +00:00
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
~LogToCallbackRedirector() {
|
2014-01-16 09:57:51 +00:00
|
|
|
#ifndef ASSIMP_BUILD_SINGLETHREADED
|
2009-05-28 11:32:54 +00:00
|
|
|
boost::mutex::scoped_lock lock(gLogStreamMutex);
|
|
|
|
#endif
|
|
|
|
// (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.
|
2009-01-12 22:06:54 +00:00
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
PredefLogStreamMap::iterator it = std::find(gPredefinedStreams.begin(),
|
|
|
|
gPredefinedStreams.end(), (Assimp::LogStream*)stream.user);
|
2008-08-28 17:35:36 +00:00
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
if (it != gPredefinedStreams.end()) {
|
|
|
|
delete *it;
|
|
|
|
gPredefinedStreams.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @copydoc LogStream::write */
|
|
|
|
void write(const char* message) {
|
|
|
|
stream.callback(message,stream.user);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
aiLogStream stream;
|
2008-08-28 17:35:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void ReportSceneNotFoundError()
|
|
|
|
{
|
2009-05-28 11:32:54 +00:00
|
|
|
DefaultLogger::get()->error("Unable to find the Assimp::Importer for this aiScene. "
|
2012-01-13 14:07:58 +00:00
|
|
|
"The C-API does not accept scenes produced by the C++ API and vice versa");
|
2009-05-28 11:32:54 +00:00
|
|
|
|
|
|
|
assert(false);
|
2008-08-28 17:35:36 +00:00
|
|
|
}
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Reads the given file and returns its content.
|
|
|
|
const aiScene* aiImportFile( const char* pFile, unsigned int pFlags)
|
2008-08-28 17:35:36 +00:00
|
|
|
{
|
|
|
|
return aiImportFileEx(pFile,pFlags,NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-01-13 14:07:58 +00:00
|
|
|
const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags, aiFileIO* pFS)
|
|
|
|
{
|
|
|
|
return aiImportFileExWithProperties(pFile, pFlags, pFS, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
const aiScene* aiImportFileExWithProperties( const char* pFile, unsigned int pFlags,
|
|
|
|
aiFileIO* pFS,
|
|
|
|
const aiPropertyStore* props)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
ai_assert(NULL != pFile);
|
2010-03-18 17:00:12 +00:00
|
|
|
|
|
|
|
const aiScene* scene = NULL;
|
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// create an Importer for this file
|
2009-06-21 19:44:48 +00:00
|
|
|
Assimp::Importer* imp = new Assimp::Importer();
|
2008-08-28 17:35:36 +00:00
|
|
|
|
2012-01-13 14:07:58 +00:00
|
|
|
// 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;
|
2014-02-28 14:21:10 +00:00
|
|
|
pimpl->mMatrixProperties = pp->matrices;
|
2012-01-13 14:07:58 +00:00
|
|
|
}
|
2008-08-28 17:35:36 +00:00
|
|
|
// setup a custom IO system if necessary
|
2009-05-28 11:32:54 +00:00
|
|
|
if (pFS) {
|
2008-08-28 17:35:36 +00:00
|
|
|
imp->SetIOHandler( new CIOSystemWrapper (pFS) );
|
|
|
|
}
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// and have it read the file
|
2010-03-18 17:00:12 +00:00
|
|
|
scene = imp->ReadFile( pFile, pFlags);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2012-01-13 14:07:58 +00:00
|
|
|
// if succeeded, store the importer in the scene and keep it alive
|
2009-05-28 11:32:54 +00:00
|
|
|
if( scene) {
|
2012-01-13 14:07:58 +00:00
|
|
|
ScenePrivateData* priv = const_cast<ScenePrivateData*>( ScenePriv(scene) );
|
|
|
|
priv->mOrigImporter = imp;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2009-05-28 11:32:54 +00:00
|
|
|
else {
|
2008-05-05 12:36:31 +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
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(const aiScene*);
|
2008-05-05 12:36:31 +00:00
|
|
|
return scene;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-06-21 19:44:48 +00:00
|
|
|
const aiScene* aiImportFileFromMemory(
|
|
|
|
const char* pBuffer,
|
|
|
|
unsigned int pLength,
|
|
|
|
unsigned int pFlags,
|
|
|
|
const char* pHint)
|
2012-01-13 14:07:58 +00:00
|
|
|
{
|
|
|
|
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)
|
2009-06-21 19:44:48 +00:00
|
|
|
{
|
|
|
|
ai_assert(NULL != pBuffer && 0 != pLength);
|
|
|
|
|
2010-03-18 17:00:12 +00:00
|
|
|
const aiScene* scene = NULL;
|
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
|
2009-06-21 19:44:48 +00:00
|
|
|
// create an Importer for this file
|
|
|
|
Assimp::Importer* imp = new Assimp::Importer();
|
|
|
|
|
2012-01-13 14:07:58 +00:00
|
|
|
// 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;
|
2014-02-28 14:21:10 +00:00
|
|
|
pimpl->mMatrixProperties = pp->matrices;
|
2012-01-13 14:07:58 +00:00
|
|
|
}
|
2009-06-21 19:44:48 +00:00
|
|
|
|
|
|
|
// and have it read the file from the memory buffer
|
2010-03-18 17:00:12 +00:00
|
|
|
scene = imp->ReadFileFromMemory( pBuffer, pLength, pFlags,pHint);
|
2009-06-21 19:44:48 +00:00
|
|
|
|
2012-01-13 14:07:58 +00:00
|
|
|
// if succeeded, store the importer in the scene and keep it alive
|
2009-06-21 19:44:48 +00:00
|
|
|
if( scene) {
|
2012-01-13 14:07:58 +00:00
|
|
|
ScenePrivateData* priv = const_cast<ScenePrivateData*>( ScenePriv(scene) );
|
|
|
|
priv->mOrigImporter = imp;
|
2009-06-21 19:44:48 +00:00
|
|
|
}
|
|
|
|
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
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(const aiScene*);
|
2009-06-21 19:44:48 +00:00
|
|
|
return scene;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-05 12:36:31 +00:00
|
|
|
// Releases all resources associated with the given import process.
|
|
|
|
void aiReleaseImport( const aiScene* pScene)
|
|
|
|
{
|
2009-05-28 11:32:54 +00:00
|
|
|
if (!pScene) {
|
|
|
|
return;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// find the importer associated with this data
|
2012-01-13 14:07:58 +00:00
|
|
|
const ScenePrivateData* priv = ScenePriv(pScene);
|
|
|
|
if( !priv || !priv->mOrigImporter) {
|
|
|
|
delete pScene;
|
2008-08-08 18:29:05 +00:00
|
|
|
}
|
2012-01-13 14:07:58 +00:00
|
|
|
else {
|
|
|
|
// deleting the Importer also deletes the scene
|
2012-02-23 14:10:18 +00:00
|
|
|
// 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;
|
2012-01-13 14:07:58 +00:00
|
|
|
}
|
|
|
|
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API const aiScene* aiApplyPostProcessing(const aiScene* pScene,
|
|
|
|
unsigned int pFlags)
|
|
|
|
{
|
2010-03-18 17:00:12 +00:00
|
|
|
const aiScene* sc = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// find the importer associated with this data
|
2012-01-13 14:07:58 +00:00
|
|
|
const ScenePrivateData* priv = ScenePriv(pScene);
|
|
|
|
if( !priv || !priv->mOrigImporter) {
|
2009-05-28 11:32:54 +00:00
|
|
|
ReportSceneNotFoundError();
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-01-13 14:07:58 +00:00
|
|
|
|
|
|
|
sc = priv->mOrigImporter->ApplyPostProcessing(pFlags);
|
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
if (!sc) {
|
2012-01-13 14:07:58 +00:00
|
|
|
aiReleaseImport(pScene);
|
2009-05-28 11:32:54 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(const aiScene*);
|
|
|
|
return sc;
|
2009-05-28 11:32:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void CallbackToLogRedirector (const char* msg, char* dt)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != msg && NULL != dt);
|
|
|
|
LogStream* s = (LogStream*)dt;
|
|
|
|
|
|
|
|
s->write(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API aiLogStream aiGetPredefinedLogStream(aiDefaultLogStream pStream,const char* file)
|
|
|
|
{
|
|
|
|
aiLogStream sout;
|
2010-03-18 17:00:12 +00:00
|
|
|
|
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
2009-05-28 11:32:54 +00:00
|
|
|
LogStream* stream = LogStream::createDefaultStream(pStream,file);
|
|
|
|
if (!stream) {
|
|
|
|
sout.callback = NULL;
|
2010-02-06 23:52:41 +00:00
|
|
|
sout.user = NULL;
|
2009-05-28 11:32:54 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
sout.callback = &CallbackToLogRedirector;
|
|
|
|
sout.user = (char*)stream;
|
|
|
|
}
|
|
|
|
gPredefinedStreams.push_back(stream);
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(aiLogStream);
|
2009-05-28 11:32:54 +00:00
|
|
|
return sout;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiAttachLogStream( const aiLogStream* stream )
|
|
|
|
{
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
|
2014-01-16 09:57:51 +00:00
|
|
|
#ifndef ASSIMP_BUILD_SINGLETHREADED
|
2009-05-28 11:32:54 +00:00
|
|
|
boost::mutex::scoped_lock lock(gLogStreamMutex);
|
|
|
|
#endif
|
2010-03-18 17:00:12 +00:00
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
LogStream* lg = new LogToCallbackRedirector(*stream);
|
|
|
|
gActiveLogStreams[*stream] = lg;
|
|
|
|
|
|
|
|
if (DefaultLogger::isNullLogger()) {
|
|
|
|
DefaultLogger::create(NULL,(gVerboseLogging == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL));
|
|
|
|
}
|
|
|
|
DefaultLogger::get()->attachStream(lg);
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2009-05-28 11:32:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API aiReturn aiDetachLogStream( const aiLogStream* stream)
|
|
|
|
{
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
|
2014-01-16 09:57:51 +00:00
|
|
|
#ifndef ASSIMP_BUILD_SINGLETHREADED
|
2009-05-28 11:32:54 +00:00
|
|
|
boost::mutex::scoped_lock lock(gLogStreamMutex);
|
|
|
|
#endif
|
|
|
|
// find the logstream associated with this data
|
|
|
|
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;
|
|
|
|
}
|
2010-04-10 15:00:36 +00:00
|
|
|
DefaultLogger::get()->detatchStream( it->second );
|
2009-05-28 11:32:54 +00:00
|
|
|
delete it->second;
|
2010-04-10 15:00:36 +00:00
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
gActiveLogStreams.erase( it);
|
|
|
|
|
|
|
|
if (gActiveLogStreams.empty()) {
|
|
|
|
DefaultLogger::kill();
|
|
|
|
}
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(aiReturn);
|
2009-05-28 11:32:54 +00:00
|
|
|
return AI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiDetachAllLogStreams(void)
|
|
|
|
{
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
2014-01-16 09:57:51 +00:00
|
|
|
#ifndef ASSIMP_BUILD_SINGLETHREADED
|
2009-05-28 11:32:54 +00:00
|
|
|
boost::mutex::scoped_lock lock(gLogStreamMutex);
|
|
|
|
#endif
|
|
|
|
for (LogStreamMap::iterator it = gActiveLogStreams.begin(); it != gActiveLogStreams.end(); ++it) {
|
2010-04-10 15:00:36 +00:00
|
|
|
DefaultLogger::get()->detatchStream( it->second );
|
2009-05-28 11:32:54 +00:00
|
|
|
delete it->second;
|
|
|
|
}
|
|
|
|
gActiveLogStreams.clear();
|
|
|
|
DefaultLogger::kill();
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2009-05-28 11:32:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiEnableVerboseLogging(aiBool d)
|
|
|
|
{
|
|
|
|
if (!DefaultLogger::isNullLogger()) {
|
|
|
|
DefaultLogger::get()->setLogSeverity((d == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL));
|
|
|
|
}
|
|
|
|
gVerboseLogging = d;
|
|
|
|
}
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Returns the error text of the last failed import process.
|
|
|
|
const char* aiGetErrorString()
|
|
|
|
{
|
|
|
|
return gLastErrorString.c_str();
|
|
|
|
}
|
2009-01-23 21:06:43 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Returns the error text of the last failed import process.
|
2009-05-28 11:32:54 +00:00
|
|
|
aiBool aiIsExtensionSupported(const char* szExtension)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
ai_assert(NULL != szExtension);
|
2010-03-18 17:00:12 +00:00
|
|
|
aiBool candoit=AI_FALSE;
|
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
|
2012-01-13 14:07:58 +00:00
|
|
|
// FIXME: no need to create a temporary Importer instance just for that ..
|
2009-05-28 11:32:54 +00:00
|
|
|
Assimp::Importer tmp;
|
2010-03-18 17:00:12 +00:00
|
|
|
candoit = tmp.IsExtensionSupported(std::string(szExtension)) ? AI_TRUE : AI_FALSE;
|
|
|
|
|
|
|
|
ASSIMP_END_EXCEPTION_REGION(aiBool);
|
|
|
|
return candoit;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2009-01-23 21:06:43 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Get a list of all file extensions supported by ASSIMP
|
|
|
|
void aiGetExtensionList(aiString* szOut)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != szOut);
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
|
2012-01-13 14:07:58 +00:00
|
|
|
// FIXME: no need to create a temporary Importer instance just for that ..
|
2009-05-28 11:32:54 +00:00
|
|
|
Assimp::Importer tmp;
|
|
|
|
tmp.GetExtensionList(*szOut);
|
2010-03-18 17:00:12 +00:00
|
|
|
|
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2009-01-23 21:06:43 +00:00
|
|
|
|
2008-08-08 18:29:05 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-05-28 11:32:54 +00:00
|
|
|
// Get the memory requirements for a particular import.
|
2008-08-08 18:29:05 +00:00
|
|
|
void aiGetMemoryRequirements(const C_STRUCT aiScene* pIn,
|
2008-08-08 18:34:14 +00:00
|
|
|
C_STRUCT aiMemoryInfo* in)
|
2008-08-08 18:29:05 +00:00
|
|
|
{
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
2008-08-08 18:29:05 +00:00
|
|
|
|
|
|
|
// find the importer associated with this data
|
2012-01-13 14:07:58 +00:00
|
|
|
const ScenePrivateData* priv = ScenePriv(pIn);
|
|
|
|
if( !priv || !priv->mOrigImporter) {
|
2008-08-28 17:35:36 +00:00
|
|
|
ReportSceneNotFoundError();
|
2008-08-08 18:34:14 +00:00
|
|
|
return;
|
2008-08-08 18:29:05 +00:00
|
|
|
}
|
2012-01-13 14:07:58 +00:00
|
|
|
|
|
|
|
return priv->mOrigImporter->GetMemoryRequirements(*in);
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2008-08-08 18:29:05 +00:00
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2012-01-13 14:07:58 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API aiPropertyStore* aiCreatePropertyStore(void)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<aiPropertyStore*>( new PropertyMap() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiReleasePropertyStore(aiPropertyStore* p)
|
|
|
|
{
|
|
|
|
delete reinterpret_cast<PropertyMap*>(p);
|
|
|
|
}
|
|
|
|
|
2008-08-28 17:35:36 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-05-28 11:32:54 +00:00
|
|
|
// Importer::SetPropertyInteger
|
2012-01-13 14:07:58 +00:00
|
|
|
ASSIMP_API void aiSetImportPropertyInteger(aiPropertyStore* p, const char* szName, int value)
|
2008-08-28 17:35:36 +00:00
|
|
|
{
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
2012-01-13 14:07:58 +00:00
|
|
|
PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
|
|
|
|
SetGenericProperty<int>(pp->ints,szName,value,NULL);
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2008-08-28 17:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-05-28 11:32:54 +00:00
|
|
|
// Importer::SetPropertyFloat
|
2012-01-13 14:07:58 +00:00
|
|
|
ASSIMP_API void aiSetImportPropertyFloat(aiPropertyStore* p, const char* szName, float value)
|
2008-08-28 17:35:36 +00:00
|
|
|
{
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
2012-01-13 14:07:58 +00:00
|
|
|
PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
|
|
|
|
SetGenericProperty<float>(pp->floats,szName,value,NULL);
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2008-08-28 17:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-05-28 11:32:54 +00:00
|
|
|
// Importer::SetPropertyString
|
2012-01-13 14:07:58 +00:00
|
|
|
ASSIMP_API void aiSetImportPropertyString(aiPropertyStore* p, const char* szName,
|
2008-08-28 17:35:36 +00:00
|
|
|
const C_STRUCT aiString* st)
|
|
|
|
{
|
2009-05-28 11:32:54 +00:00
|
|
|
if (!st) {
|
|
|
|
return;
|
|
|
|
}
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
2012-01-13 14:07:58 +00:00
|
|
|
PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
|
|
|
|
SetGenericProperty<std::string>(pp->strings,szName,std::string(st->C_Str()),NULL);
|
2010-03-18 17:00:12 +00:00
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
2008-08-28 17:35:36 +00:00
|
|
|
}
|
2009-04-27 15:16:32 +00:00
|
|
|
|
2014-02-28 14:21:10 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Importer::SetPropertyMatrix
|
|
|
|
ASSIMP_API void aiSetImportPropertyMatrix(aiPropertyStore* p, const char* szName,
|
|
|
|
const C_STRUCT aiMatrix4x4* mat)
|
|
|
|
{
|
|
|
|
if (!mat) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ASSIMP_BEGIN_EXCEPTION_REGION();
|
|
|
|
PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
|
|
|
|
SetGenericProperty<aiMatrix4x4>(pp->matrices,szName,*mat,NULL);
|
|
|
|
ASSIMP_END_EXCEPTION_REGION(void);
|
|
|
|
}
|
|
|
|
|
2009-04-27 15:16:32 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-05-28 11:32:54 +00:00
|
|
|
// Rotation matrix to quaternion
|
2009-04-27 15:43:01 +00:00
|
|
|
ASSIMP_API void aiCreateQuaternionFromMatrix(aiQuaternion* quat,const aiMatrix3x3* mat)
|
2009-04-27 15:16:32 +00:00
|
|
|
{
|
2009-05-28 11:32:54 +00:00
|
|
|
ai_assert(NULL != quat && NULL != mat);
|
2009-04-27 15:16:32 +00:00
|
|
|
*quat = aiQuaternion(*mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-06-20 14:49:49 +00:00
|
|
|
// Matrix decomposition
|
2009-05-28 11:32:54 +00:00
|
|
|
ASSIMP_API void aiDecomposeMatrix(const aiMatrix4x4* mat,aiVector3D* scaling,
|
|
|
|
aiQuaternion* rotation,
|
|
|
|
aiVector3D* position)
|
2009-04-27 15:16:32 +00:00
|
|
|
{
|
2009-05-28 11:32:54 +00:00
|
|
|
ai_assert(NULL != rotation && NULL != position && NULL != scaling && NULL != mat);
|
2009-04-27 15:16:32 +00:00
|
|
|
mat->Decompose(*scaling,*rotation,*position);
|
|
|
|
}
|
2009-05-28 11:32:54 +00:00
|
|
|
|
2009-06-20 14:49:49 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Matrix transpose
|
|
|
|
ASSIMP_API void aiTransposeMatrix3(aiMatrix3x3* mat)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != mat);
|
|
|
|
mat->Transpose();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiTransposeMatrix4(aiMatrix4x4* mat)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != mat);
|
|
|
|
mat->Transpose();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Vector transformation
|
2012-01-13 14:07:58 +00:00
|
|
|
ASSIMP_API void aiTransformVecByMatrix3(aiVector3D* vec,
|
|
|
|
const aiMatrix3x3* mat)
|
2009-06-20 14:49:49 +00:00
|
|
|
{
|
|
|
|
ai_assert(NULL != mat && NULL != vec);
|
|
|
|
*vec *= (*mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-01-13 14:07:58 +00:00
|
|
|
ASSIMP_API void aiTransformVecByMatrix4(aiVector3D* vec,
|
|
|
|
const aiMatrix4x4* mat)
|
2009-06-20 14:49:49 +00:00
|
|
|
{
|
|
|
|
ai_assert(NULL != mat && NULL != vec);
|
|
|
|
*vec *= (*mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Matrix multiplication
|
|
|
|
ASSIMP_API void aiMultiplyMatrix4(
|
2012-01-13 14:07:58 +00:00
|
|
|
aiMatrix4x4* dst,
|
|
|
|
const aiMatrix4x4* src)
|
2009-06-20 14:49:49 +00:00
|
|
|
{
|
|
|
|
ai_assert(NULL != dst && NULL != src);
|
|
|
|
*dst = (*dst) * (*src);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiMultiplyMatrix3(
|
2012-01-13 14:07:58 +00:00
|
|
|
aiMatrix3x3* dst,
|
|
|
|
const aiMatrix3x3* src)
|
2009-06-20 14:49:49 +00:00
|
|
|
{
|
|
|
|
ai_assert(NULL != dst && NULL != src);
|
|
|
|
*dst = (*dst) * (*src);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Matrix identity
|
|
|
|
ASSIMP_API void aiIdentityMatrix3(
|
2012-01-13 14:07:58 +00:00
|
|
|
aiMatrix3x3* mat)
|
2009-06-20 14:49:49 +00:00
|
|
|
{
|
|
|
|
ai_assert(NULL != mat);
|
|
|
|
*mat = aiMatrix3x3();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiIdentityMatrix4(
|
2012-01-13 14:07:58 +00:00
|
|
|
aiMatrix4x4* mat)
|
2009-06-20 14:49:49 +00:00
|
|
|
{
|
|
|
|
ai_assert(NULL != mat);
|
|
|
|
*mat = aiMatrix4x4();
|
|
|
|
}
|
|
|
|
|
2014-12-01 19:34:15 +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;
|
|
|
|
}
|
|
|
|
}
|
2009-05-28 11:32:54 +00:00
|
|
|
|
2014-12-01 19:34:15 +00:00
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|