2008-05-09 17:24:28 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
2008-05-22 10:20:31 +00:00
|
|
|
Open Asset Import Library (ASSIMP)
|
2008-05-09 17:24:28 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
Copyright (c) 2006-2008, ASSIMP Development Team
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
* 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 Development Team.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
#include "AssimpPCH.h"
|
2008-05-05 12:36:31 +00:00
|
|
|
#include "../include/assimp.h"
|
2008-08-28 17:35:36 +00:00
|
|
|
#include "../include/aiFileIO.h"
|
|
|
|
|
|
|
|
#include "GenericProperty.h"
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#ifdef AI_C_THREADSAFE
|
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
|
|
|
|
{
|
|
|
|
/** Stores the importer objects for all active import processes */
|
|
|
|
typedef std::map<const aiScene*, Assimp::Importer*> ImporterMap;
|
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 import processes */
|
|
|
|
static ImporterMap gActiveImports;
|
2009-05-28 11:32:54 +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;
|
|
|
|
}
|
2009-05-28 11:32:54 +00:00
|
|
|
|
2008-08-28 17:35:36 +00:00
|
|
|
/** Configuration properties */
|
2009-05-28 11:32:54 +00:00
|
|
|
static ImporterPimpl::IntPropertyMap gIntProperties;
|
|
|
|
static ImporterPimpl::FloatPropertyMap gFloatProperties;
|
|
|
|
static ImporterPimpl::StringPropertyMap gStringProperties;
|
2008-08-28 17:35:36 +00:00
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
#ifdef AI_C_THREADSAFE
|
2008-05-09 17:24:28 +00:00
|
|
|
/** Global mutex to manage the access to the importer map */
|
|
|
|
static boost::mutex gMutex;
|
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
|
|
|
class CIOSystemWrapper;
|
|
|
|
class CIOStreamWrapper;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Custom IOStream implementation for the C-API
|
|
|
|
class CIOStreamWrapper : public IOStream
|
|
|
|
{
|
|
|
|
friend class CIOSystemWrapper;
|
|
|
|
public:
|
|
|
|
|
|
|
|
CIOStreamWrapper(aiFile* pFile)
|
|
|
|
: mFile(pFile)
|
|
|
|
{}
|
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// ...................................................................
|
2009-01-12 22:06:54 +00:00
|
|
|
size_t Read(void* pvBuffer,
|
2008-08-28 17:35:36 +00:00
|
|
|
size_t pSize,
|
2009-05-28 11:32:54 +00:00
|
|
|
size_t pCount
|
|
|
|
){
|
2008-08-28 17:35:36 +00:00
|
|
|
// need to typecast here as C has no void*
|
|
|
|
return mFile->ReadProc(mFile,(char*)pvBuffer,pSize,pCount);
|
|
|
|
}
|
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// ...................................................................
|
2009-01-12 22:06:54 +00:00
|
|
|
size_t Write(const void* pvBuffer,
|
2008-08-28 17:35:36 +00:00
|
|
|
size_t pSize,
|
2009-05-28 11:32:54 +00:00
|
|
|
size_t pCount
|
|
|
|
){
|
2009-01-12 22:06:54 +00:00
|
|
|
// need to typecast here as C has no void*
|
|
|
|
return mFile->WriteProc(mFile,(const char*)pvBuffer,pSize,pCount);
|
|
|
|
}
|
2008-08-28 17:35:36 +00:00
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// ...................................................................
|
2008-08-28 17:35:36 +00:00
|
|
|
aiReturn Seek(size_t pOffset,
|
2009-05-28 11:32:54 +00:00
|
|
|
aiOrigin pOrigin
|
|
|
|
){
|
2008-08-28 17:35:36 +00:00
|
|
|
return mFile->SeekProc(mFile,pOffset,pOrigin);
|
|
|
|
}
|
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// ...................................................................
|
|
|
|
size_t Tell(void) const {
|
2008-08-28 17:35:36 +00:00
|
|
|
return mFile->TellProc(mFile);
|
|
|
|
}
|
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// ...................................................................
|
|
|
|
size_t FileSize() const {
|
2008-08-28 17:35:36 +00:00
|
|
|
return mFile->FileSizeProc(mFile);
|
|
|
|
}
|
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// ...................................................................
|
|
|
|
void Flush () {
|
2009-01-12 22:06:54 +00:00
|
|
|
return mFile->FlushProc(mFile);
|
|
|
|
}
|
|
|
|
|
2008-08-28 17:35:36 +00:00
|
|
|
private:
|
|
|
|
aiFile* mFile;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Custom IOStream implementation for the C-API
|
|
|
|
class CIOSystemWrapper : public IOSystem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CIOSystemWrapper(aiFileIO* pFile)
|
|
|
|
: mFileSystem(pFile)
|
|
|
|
{}
|
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// ...................................................................
|
|
|
|
bool Exists( const char* pFile) const {
|
2008-08-28 17:35:36 +00:00
|
|
|
CIOSystemWrapper* pip = const_cast<CIOSystemWrapper*>(this);
|
|
|
|
IOStream* p = pip->Open(pFile);
|
2009-01-12 22:06:54 +00:00
|
|
|
if (p){
|
|
|
|
pip->Close(p);
|
|
|
|
return true;
|
|
|
|
}
|
2008-08-28 17:35:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// ...................................................................
|
|
|
|
char getOsSeparator() const {
|
|
|
|
#ifndef _WIN32
|
2009-01-23 21:06:43 +00:00
|
|
|
return '/';
|
2009-05-28 11:32:54 +00:00
|
|
|
#else
|
|
|
|
return '\\';
|
|
|
|
#endif
|
2008-08-28 17:35:36 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// ...................................................................
|
|
|
|
IOStream* Open(const char* pFile,const char* pMode = "rb") {
|
2009-01-23 21:06:43 +00:00
|
|
|
aiFile* p = mFileSystem->OpenProc(mFileSystem,pFile,pMode);
|
2009-05-28 11:32:54 +00:00
|
|
|
if (!p) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-08-28 17:35:36 +00:00
|
|
|
return new CIOStreamWrapper(p);
|
|
|
|
}
|
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// ...................................................................
|
|
|
|
void Close( IOStream* pFile) {
|
|
|
|
if (!pFile) {
|
|
|
|
return;
|
|
|
|
}
|
2008-08-28 17:35:36 +00:00
|
|
|
mFileSystem->CloseProc(mFileSystem,((CIOStreamWrapper*) pFile)->mFile);
|
|
|
|
delete pFile;
|
|
|
|
}
|
2009-05-28 11:32:54 +00:00
|
|
|
private:
|
|
|
|
aiFileIO* mFileSystem;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// 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() {
|
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
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. "
|
|
|
|
"Are you playing fools with us? Don't mix cpp and c API. Thanks.");
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags,
|
|
|
|
aiFileIO* pFS)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
ai_assert(NULL != pFile);
|
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
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
boost::mutex::scoped_lock lock(gMutex);
|
|
|
|
#endif
|
2008-08-28 17:35:36 +00:00
|
|
|
// copy the global property lists to the Importer instance
|
2009-04-24 20:53:24 +00:00
|
|
|
imp->pimpl->mIntProperties = gIntProperties;
|
|
|
|
imp->pimpl->mFloatProperties = gFloatProperties;
|
|
|
|
imp->pimpl->mStringProperties = gStringProperties;
|
2008-08-28 17:35:36 +00:00
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
lock.unlock();
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
const aiScene* scene = imp->ReadFile( pFile, pFlags);
|
|
|
|
|
|
|
|
// if succeeded, place it in the collection of active processes
|
2009-05-28 11:32:54 +00:00
|
|
|
if( scene) {
|
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
lock.lock();
|
2008-05-09 17:24:28 +00:00
|
|
|
#endif
|
2008-05-05 12:36:31 +00:00
|
|
|
gActiveImports[scene] = imp;
|
|
|
|
}
|
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
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != pBuffer && 0 != pLength);
|
|
|
|
|
|
|
|
// create an Importer for this file
|
|
|
|
Assimp::Importer* imp = new Assimp::Importer();
|
|
|
|
|
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
boost::mutex::scoped_lock lock(gMutex);
|
|
|
|
#endif
|
|
|
|
// copy the global property lists to the Importer instance
|
|
|
|
imp->pimpl->mIntProperties = gIntProperties;
|
|
|
|
imp->pimpl->mFloatProperties = gFloatProperties;
|
|
|
|
imp->pimpl->mStringProperties = gStringProperties;
|
|
|
|
|
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
lock.unlock();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// and have it read the file from the memory buffer
|
|
|
|
const aiScene* scene = imp->ReadFileFromMemory( pBuffer, pLength, pFlags,pHint);
|
|
|
|
|
|
|
|
// if succeeded, place it in the collection of active processes
|
|
|
|
if( scene) {
|
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
lock.lock();
|
|
|
|
#endif
|
|
|
|
gActiveImports[scene] = 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
|
|
|
|
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
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
#ifdef AI_C_THREADSAFE
|
2008-05-09 17:24:28 +00:00
|
|
|
boost::mutex::scoped_lock lock(gMutex);
|
|
|
|
#endif
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// find the importer associated with this data
|
|
|
|
ImporterMap::iterator it = gActiveImports.find( pScene);
|
|
|
|
// it should be there... else the user is playing fools with us
|
2009-05-28 11:32:54 +00:00
|
|
|
if( it == gActiveImports.end()) {
|
2008-08-28 17:35:36 +00:00
|
|
|
ReportSceneNotFoundError();
|
2008-05-05 12:36:31 +00:00
|
|
|
return;
|
2008-08-08 18:29:05 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// kill the importer, the data dies with it
|
|
|
|
delete it->second;
|
|
|
|
gActiveImports.erase( it);
|
|
|
|
}
|
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API const aiScene* aiApplyPostProcessing(const aiScene* pScene,
|
|
|
|
unsigned int pFlags)
|
|
|
|
{
|
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
boost::mutex::scoped_lock lock(gMutex);
|
|
|
|
#endif
|
|
|
|
// find the importer associated with this data
|
|
|
|
ImporterMap::iterator it = gActiveImports.find( pScene);
|
|
|
|
// it should be there... else the user is playing fools with us
|
|
|
|
if( it == gActiveImports.end()) {
|
|
|
|
ReportSceneNotFoundError();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
lock.unlock();
|
|
|
|
#endif
|
|
|
|
const aiScene* sc = it->second->ApplyPostProcessing(pFlags);
|
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
lock.lock();
|
|
|
|
#endif
|
|
|
|
if (!sc) {
|
|
|
|
// kill the importer, the data dies with it
|
|
|
|
delete it->second;
|
|
|
|
gActiveImports.erase( it);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return it->first;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
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;
|
|
|
|
LogStream* stream = LogStream::createDefaultStream(pStream,file);
|
|
|
|
if (!stream) {
|
|
|
|
sout.callback = NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sout.callback = &CallbackToLogRedirector;
|
|
|
|
sout.user = (char*)stream;
|
|
|
|
}
|
|
|
|
gPredefinedStreams.push_back(stream);
|
|
|
|
return sout;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiAttachLogStream( const aiLogStream* stream )
|
|
|
|
{
|
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
boost::mutex::scoped_lock lock(gLogStreamMutex);
|
|
|
|
#endif
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API aiReturn aiDetachLogStream( const aiLogStream* stream)
|
|
|
|
{
|
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
delete it->second;
|
|
|
|
gActiveLogStreams.erase( it);
|
|
|
|
|
|
|
|
if (gActiveLogStreams.empty()) {
|
|
|
|
DefaultLogger::kill();
|
|
|
|
}
|
|
|
|
return AI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiDetachAllLogStreams(void)
|
|
|
|
{
|
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
boost::mutex::scoped_lock lock(gLogStreamMutex);
|
|
|
|
#endif
|
|
|
|
for (LogStreamMap::iterator it = gActiveLogStreams.begin(); it != gActiveLogStreams.end(); ++it) {
|
|
|
|
delete it->second;
|
|
|
|
}
|
|
|
|
gActiveLogStreams.clear();
|
|
|
|
DefaultLogger::kill();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
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);
|
2009-05-28 11:32:54 +00:00
|
|
|
#ifdef AI_C_THREADSAFE
|
2008-05-09 17:24:28 +00:00
|
|
|
boost::mutex::scoped_lock lock(gMutex);
|
|
|
|
#endif
|
|
|
|
|
2009-01-23 21:06:43 +00:00
|
|
|
if (!gActiveImports.empty()) {
|
2009-05-28 11:32:54 +00:00
|
|
|
return ((*(gActiveImports.begin())).second->IsExtensionSupported( szExtension )) ? AI_TRUE : AI_FALSE;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2009-01-23 21:06:43 +00:00
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
// fixme: no need to create a temporary Importer instance just for that ..
|
|
|
|
Assimp::Importer tmp;
|
|
|
|
return tmp.IsExtensionSupported(std::string(szExtension)) ? AI_TRUE : AI_FALSE;
|
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);
|
2009-05-28 11:32:54 +00:00
|
|
|
#ifdef AI_C_THREADSAFE
|
2008-05-09 17:24:28 +00:00
|
|
|
boost::mutex::scoped_lock lock(gMutex);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!gActiveImports.empty())
|
|
|
|
{
|
2009-01-23 21:06:43 +00:00
|
|
|
(*(gActiveImports.begin())).second->GetExtensionList(*szOut);
|
2008-05-09 17:24:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-05-28 11:32:54 +00:00
|
|
|
// fixme: no need to create a temporary Importer instance just for that ..
|
|
|
|
Assimp::Importer tmp;
|
|
|
|
tmp.GetExtensionList(*szOut);
|
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
|
|
|
{
|
2009-05-28 11:32:54 +00:00
|
|
|
#ifdef AI_C_THREADSAFE
|
2008-08-08 18:29:05 +00:00
|
|
|
boost::mutex::scoped_lock lock(gMutex);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// find the importer associated with this data
|
|
|
|
ImporterMap::iterator it = gActiveImports.find( pIn);
|
|
|
|
// it should be there... else the user is playing fools with us
|
2009-05-28 11:32:54 +00:00
|
|
|
if( it == gActiveImports.end()) {
|
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
|
|
|
}
|
|
|
|
// get memory statistics
|
2009-05-28 11:32:54 +00:00
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
lock.unlock();
|
|
|
|
#endif
|
2008-08-08 18:29:05 +00:00
|
|
|
it->second->GetMemoryRequirements(*in);
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-08-28 17:35:36 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-05-28 11:32:54 +00:00
|
|
|
// Importer::SetPropertyInteger
|
2008-08-28 17:35:36 +00:00
|
|
|
ASSIMP_API void aiSetImportPropertyInteger(const char* szName, int value)
|
|
|
|
{
|
2009-05-28 11:32:54 +00:00
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
boost::mutex::scoped_lock lock(gMutex);
|
|
|
|
#endif
|
2008-08-28 17:35:36 +00:00
|
|
|
SetGenericProperty<int>(gIntProperties,szName,value,NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-05-28 11:32:54 +00:00
|
|
|
// Importer::SetPropertyFloat
|
2008-08-28 17:35:36 +00:00
|
|
|
ASSIMP_API void aiSetImportPropertyFloat(const char* szName, float value)
|
|
|
|
{
|
2009-05-28 11:32:54 +00:00
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
boost::mutex::scoped_lock lock(gMutex);
|
|
|
|
#endif
|
2008-08-28 17:35:36 +00:00
|
|
|
SetGenericProperty<float>(gFloatProperties,szName,value,NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-05-28 11:32:54 +00:00
|
|
|
// Importer::SetPropertyString
|
2008-08-28 17:35:36 +00:00
|
|
|
ASSIMP_API void aiSetImportPropertyString(const char* szName,
|
|
|
|
const C_STRUCT aiString* st)
|
|
|
|
{
|
2009-05-28 11:32:54 +00:00
|
|
|
if (!st) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#ifdef AI_C_THREADSAFE
|
|
|
|
boost::mutex::scoped_lock lock(gMutex);
|
|
|
|
#endif
|
2008-08-28 17:35:36 +00:00
|
|
|
SetGenericProperty<std::string>(gStringProperties,szName,
|
|
|
|
std::string( st->data ),NULL);
|
|
|
|
}
|
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
|
|
|
|
ASSIMP_API void aiTransformVecByMatrix3(C_STRUCT aiVector3D* vec,
|
|
|
|
const C_STRUCT aiMatrix3x3* mat)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != mat && NULL != vec);
|
|
|
|
*vec *= (*mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiTransformVecByMatrix4(C_STRUCT aiVector3D* vec,
|
|
|
|
const C_STRUCT aiMatrix4x4* mat)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != mat && NULL != vec);
|
|
|
|
*vec *= (*mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Matrix multiplication
|
|
|
|
ASSIMP_API void aiMultiplyMatrix4(
|
|
|
|
C_STRUCT aiMatrix4x4* dst,
|
|
|
|
const C_STRUCT aiMatrix4x4* src)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != dst && NULL != src);
|
|
|
|
*dst = (*dst) * (*src);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiMultiplyMatrix3(
|
|
|
|
C_STRUCT aiMatrix3x3* dst,
|
|
|
|
const C_STRUCT aiMatrix3x3* src)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != dst && NULL != src);
|
|
|
|
*dst = (*dst) * (*src);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Matrix identity
|
|
|
|
ASSIMP_API void aiIdentityMatrix3(
|
|
|
|
C_STRUCT aiMatrix3x3* mat)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != mat);
|
|
|
|
*mat = aiMatrix3x3();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
ASSIMP_API void aiIdentityMatrix4(
|
|
|
|
C_STRUCT aiMatrix4x4* mat)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != mat);
|
|
|
|
*mat = aiMatrix4x4();
|
|
|
|
}
|
|
|
|
|
2009-05-28 11:32:54 +00:00
|
|
|
|