MD5 bugfix.
WIP version of the OptimizeGraph-Step. Added hashes to some string routines (speedup). Improved property system for float and strings. Refactoring code for computing normals from smoothinggroups. Implemented C-ASSIMP. git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@116 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
This commit is contained in:
173
code/Assimp.cpp
173
code/Assimp.cpp
@@ -40,14 +40,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/** @file Implementation of the Plain-C API */
|
||||
|
||||
// CRT headers
|
||||
#include <map>
|
||||
|
||||
// public ASSIMP headers
|
||||
#include "../include/assimp.h"
|
||||
#include "../include/aiFileIO.h"
|
||||
#include "../include/assimp.hpp"
|
||||
#include "../include/DefaultLogger.h"
|
||||
#include "../include/aiAssert.h"
|
||||
#include "../include/IOStream.h"
|
||||
#include "../include/IOSystem.h"
|
||||
|
||||
#include "GenericProperty.h"
|
||||
|
||||
// boost headers
|
||||
#define AI_C_THREADSAFE
|
||||
@@ -67,19 +70,158 @@ static ImporterMap gActiveImports;
|
||||
/** Error message of the last failed import process */
|
||||
static std::string gLastErrorString;
|
||||
|
||||
/** Configuration properties */
|
||||
static Importer::IntPropertyMap gIntProperties;
|
||||
static Importer::FloatPropertyMap gFloatProperties;
|
||||
static Importer::StringPropertyMap gStringProperties;
|
||||
|
||||
#if (defined AI_C_THREADSAFE)
|
||||
/** Global mutex to manage the access to the importer map */
|
||||
static boost::mutex gMutex;
|
||||
#endif
|
||||
|
||||
class CIOSystemWrapper;
|
||||
class CIOStreamWrapper;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Custom IOStream implementation for the C-API
|
||||
class CIOStreamWrapper : public IOStream
|
||||
{
|
||||
friend class CIOSystemWrapper;
|
||||
public:
|
||||
|
||||
CIOStreamWrapper(aiFile* pFile)
|
||||
: mFile(pFile)
|
||||
{}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
size_t Read(void* pvBuffer,
|
||||
size_t pSize,
|
||||
size_t pCount)
|
||||
{
|
||||
// need to typecast here as C has no void*
|
||||
return mFile->ReadProc(mFile,(char*)pvBuffer,pSize,pCount);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
size_t Write(const void* pvBuffer,
|
||||
size_t pSize,
|
||||
size_t pCount)
|
||||
{
|
||||
// need to typecast here as C has no void*
|
||||
return mFile->WriteProc(mFile,(const char*)pvBuffer,pSize,pCount);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
aiReturn Seek(size_t pOffset,
|
||||
aiOrigin pOrigin)
|
||||
{
|
||||
return mFile->SeekProc(mFile,pOffset,pOrigin);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
size_t Tell(void) const
|
||||
{
|
||||
return mFile->TellProc(mFile);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
size_t FileSize() const
|
||||
{
|
||||
return mFile->FileSizeProc(mFile);
|
||||
}
|
||||
|
||||
private:
|
||||
aiFile* mFile;
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Custom IOStream implementation for the C-API
|
||||
class CIOSystemWrapper : public IOSystem
|
||||
{
|
||||
public:
|
||||
|
||||
CIOSystemWrapper(aiFileIO* pFile)
|
||||
: mFileSystem(pFile)
|
||||
{}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
bool Exists( const std::string& pFile) const
|
||||
{
|
||||
CIOSystemWrapper* pip = const_cast<CIOSystemWrapper*>(this);
|
||||
IOStream* p = pip->Open(pFile);
|
||||
if (p){pip->Close(p);return true;}
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
std::string getOsSeparator() const
|
||||
{
|
||||
return "/";
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
IOStream* Open(const std::string& pFile,
|
||||
const std::string& pMode = std::string("rb"))
|
||||
{
|
||||
aiFile* p = mFileSystem->OpenProc(mFileSystem,pFile.c_str(),pMode.c_str());
|
||||
if (!p)return NULL;
|
||||
return new CIOStreamWrapper(p);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
void Close( IOStream* pFile)
|
||||
{
|
||||
if (!pFile)return;
|
||||
mFileSystem->CloseProc(mFileSystem,((CIOStreamWrapper*) pFile)->mFile);
|
||||
delete pFile;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
aiFileIO* mFileSystem;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ReportSceneNotFoundError()
|
||||
{
|
||||
DefaultLogger::get()->error("Unable to find the Importer instance for this scene. "
|
||||
"Are you sure it has been created by aiImportFile(ex)(...)?");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Reads the given file and returns its content.
|
||||
const aiScene* aiImportFile( const char* pFile, unsigned int pFlags)
|
||||
{
|
||||
return aiImportFileEx(pFile,pFlags,NULL);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags,
|
||||
aiFileIO* pFS)
|
||||
{
|
||||
ai_assert(NULL != pFile);
|
||||
|
||||
// create an Importer for this file
|
||||
Assimp::Importer* imp = new Assimp::Importer;
|
||||
|
||||
// copy the global property lists to the Importer instance
|
||||
// (we are a friend of Importer)
|
||||
imp->mIntProperties = gIntProperties;
|
||||
imp->mFloatProperties = gFloatProperties;
|
||||
imp->mStringProperties = gStringProperties;
|
||||
|
||||
// setup a custom IO system if necessary
|
||||
if (pFS)
|
||||
{
|
||||
imp->SetIOHandler( new CIOSystemWrapper (pFS) );
|
||||
}
|
||||
|
||||
// and have it read the file
|
||||
const aiScene* scene = imp->ReadFile( pFile, pFlags);
|
||||
|
||||
@@ -118,8 +260,7 @@ void aiReleaseImport( const aiScene* pScene)
|
||||
// it should be there... else the user is playing fools with us
|
||||
if( it == gActiveImports.end())
|
||||
{
|
||||
DefaultLogger::get()->error("Unable to find the Importer instance for this scene. "
|
||||
"Are you sure it has been created by aiImportFile(ex)(...)?");
|
||||
ReportSceneNotFoundError();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -196,11 +337,31 @@ void aiGetMemoryRequirements(const C_STRUCT aiScene* pIn,
|
||||
// it should be there... else the user is playing fools with us
|
||||
if( it == gActiveImports.end())
|
||||
{
|
||||
DefaultLogger::get()->error("Unable to find the Importer instance for this scene. "
|
||||
"Are you sure it has been created by aiImportFile(ex)(...)?");
|
||||
ReportSceneNotFoundError();
|
||||
return;
|
||||
}
|
||||
// get memory statistics
|
||||
it->second->GetMemoryRequirements(*in);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ASSIMP_API void aiSetImportPropertyInteger(const char* szName, int value)
|
||||
{
|
||||
SetGenericProperty<int>(gIntProperties,szName,value,NULL);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ASSIMP_API void aiSetImportPropertyFloat(const char* szName, float value)
|
||||
{
|
||||
SetGenericProperty<float>(gFloatProperties,szName,value,NULL);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ASSIMP_API void aiSetImportPropertyString(const char* szName,
|
||||
const C_STRUCT aiString* st)
|
||||
{
|
||||
if (!st)return;
|
||||
|
||||
SetGenericProperty<std::string>(gStringProperties,szName,
|
||||
std::string( st->data ),NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user