miniassimp
diff src/Assimp.cpp @ 0:879c81d94345
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 28 Jan 2019 18:19:26 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/Assimp.cpp Mon Jan 28 18:19:26 2019 +0200 1.3 @@ -0,0 +1,695 @@ 1.4 +/* 1.5 +--------------------------------------------------------------------------- 1.6 +Open Asset Import Library (assimp) 1.7 +--------------------------------------------------------------------------- 1.8 + 1.9 +Copyright (c) 2006-2018, assimp team 1.10 + 1.11 + 1.12 + 1.13 +All rights reserved. 1.14 + 1.15 +Redistribution and use of this software in source and binary forms, 1.16 +with or without modification, are permitted provided that the following 1.17 +conditions are met: 1.18 + 1.19 +* Redistributions of source code must retain the above 1.20 + copyright notice, this list of conditions and the 1.21 + following disclaimer. 1.22 + 1.23 +* Redistributions in binary form must reproduce the above 1.24 + copyright notice, this list of conditions and the 1.25 + following disclaimer in the documentation and/or other 1.26 + materials provided with the distribution. 1.27 + 1.28 +* Neither the name of the assimp team, nor the names of its 1.29 + contributors may be used to endorse or promote products 1.30 + derived from this software without specific prior 1.31 + written permission of the assimp team. 1.32 + 1.33 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.34 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.35 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.36 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.37 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.38 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.39 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.40 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.41 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.42 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.43 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.44 +--------------------------------------------------------------------------- 1.45 +*/ 1.46 +/** @file Assimp.cpp 1.47 + * @brief Implementation of the Plain-C API 1.48 + */ 1.49 + 1.50 +#include <miniassimp/cimport.h> 1.51 +#include <miniassimp/LogStream.hpp> 1.52 +#include <miniassimp/DefaultLogger.hpp> 1.53 +#include <miniassimp/Importer.hpp> 1.54 +#include <miniassimp/importerdesc.h> 1.55 +#include <miniassimp/scene.h> 1.56 +#include <miniassimp/GenericProperty.h> 1.57 +#include <miniassimp/Exceptional.h> 1.58 +#include <miniassimp/BaseImporter.h> 1.59 + 1.60 +#include "CInterfaceIOWrapper.h" 1.61 +#include "Importer.h" 1.62 +#include "ScenePrivate.h" 1.63 + 1.64 +#include <list> 1.65 + 1.66 +// ------------------------------------------------------------------------------------------------ 1.67 +#ifndef ASSIMP_BUILD_SINGLETHREADED 1.68 +# include <thread> 1.69 +# include <mutex> 1.70 +#endif 1.71 +// ------------------------------------------------------------------------------------------------ 1.72 +using namespace Assimp; 1.73 + 1.74 +namespace Assimp { 1.75 + // underlying structure for aiPropertyStore 1.76 + typedef BatchLoader::PropertyMap PropertyMap; 1.77 + 1.78 + /** Stores the LogStream objects for all active C log streams */ 1.79 + struct mpred { 1.80 + bool operator () (const aiLogStream& s0, const aiLogStream& s1) const { 1.81 + return s0.callback<s1.callback&&s0.user<s1.user; 1.82 + } 1.83 + }; 1.84 + typedef std::map<aiLogStream, Assimp::LogStream*, mpred> LogStreamMap; 1.85 + 1.86 + /** Stores the LogStream objects allocated by #aiGetPredefinedLogStream */ 1.87 + typedef std::list<Assimp::LogStream*> PredefLogStreamMap; 1.88 + 1.89 + /** Local storage of all active log streams */ 1.90 + static LogStreamMap gActiveLogStreams; 1.91 + 1.92 + /** Local storage of LogStreams allocated by #aiGetPredefinedLogStream */ 1.93 + static PredefLogStreamMap gPredefinedStreams; 1.94 + 1.95 + /** Error message of the last failed import process */ 1.96 + static std::string gLastErrorString; 1.97 + 1.98 + /** Verbose logging active or not? */ 1.99 + static aiBool gVerboseLogging = false; 1.100 + 1.101 + /** will return all registered importers. */ 1.102 + void GetImporterInstanceList(std::vector< BaseImporter* >& out); 1.103 + 1.104 + /** will delete all registered importers. */ 1.105 + void DeleteImporterInstanceList(std::vector< BaseImporter* >& out); 1.106 +} // namespace assimp 1.107 + 1.108 + 1.109 +#ifndef ASSIMP_BUILD_SINGLETHREADED 1.110 +/** Global mutex to manage the access to the log-stream map */ 1.111 +static std::mutex gLogStreamMutex; 1.112 +#endif 1.113 + 1.114 +// ------------------------------------------------------------------------------------------------ 1.115 +// Custom LogStream implementation for the C-API 1.116 +class LogToCallbackRedirector : public LogStream { 1.117 +public: 1.118 + explicit LogToCallbackRedirector(const aiLogStream& s) 1.119 + : stream (s) { 1.120 + ai_assert(NULL != s.callback); 1.121 + } 1.122 + 1.123 + ~LogToCallbackRedirector() { 1.124 +#ifndef ASSIMP_BUILD_SINGLETHREADED 1.125 + std::lock_guard<std::mutex> lock(gLogStreamMutex); 1.126 +#endif 1.127 + // (HACK) Check whether the 'stream.user' pointer points to a 1.128 + // custom LogStream allocated by #aiGetPredefinedLogStream. 1.129 + // In this case, we need to delete it, too. Of course, this 1.130 + // might cause strange problems, but the chance is quite low. 1.131 + 1.132 + PredefLogStreamMap::iterator it = std::find(gPredefinedStreams.begin(), 1.133 + gPredefinedStreams.end(), (Assimp::LogStream*)stream.user); 1.134 + 1.135 + if (it != gPredefinedStreams.end()) { 1.136 + delete *it; 1.137 + gPredefinedStreams.erase(it); 1.138 + } 1.139 + } 1.140 + 1.141 + /** @copydoc LogStream::write */ 1.142 + void write(const char* message) { 1.143 + stream.callback(message,stream.user); 1.144 + } 1.145 + 1.146 +private: 1.147 + aiLogStream stream; 1.148 +}; 1.149 + 1.150 +// ------------------------------------------------------------------------------------------------ 1.151 +void ReportSceneNotFoundError() { 1.152 + ASSIMP_LOG_ERROR("Unable to find the Assimp::Importer for this aiScene. " 1.153 + "The C-API does not accept scenes produced by the C++ API and vice versa"); 1.154 + 1.155 + ai_assert(false); 1.156 +} 1.157 + 1.158 +// ------------------------------------------------------------------------------------------------ 1.159 +// Reads the given file and returns its content. 1.160 +const aiScene* aiImportFile( const char* pFile, unsigned int pFlags) { 1.161 + return aiImportFileEx(pFile,pFlags,NULL); 1.162 +} 1.163 + 1.164 +// ------------------------------------------------------------------------------------------------ 1.165 +const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags, aiFileIO* pFS) { 1.166 + return aiImportFileExWithProperties(pFile, pFlags, pFS, NULL); 1.167 +} 1.168 + 1.169 +// ------------------------------------------------------------------------------------------------ 1.170 +const aiScene* aiImportFileExWithProperties( const char* pFile, unsigned int pFlags, 1.171 + aiFileIO* pFS, const aiPropertyStore* props) { 1.172 + ai_assert(NULL != pFile); 1.173 + 1.174 + const aiScene* scene = NULL; 1.175 + ASSIMP_BEGIN_EXCEPTION_REGION(); 1.176 + 1.177 + // create an Importer for this file 1.178 + Assimp::Importer* imp = new Assimp::Importer(); 1.179 + 1.180 + // copy properties 1.181 + if(props) { 1.182 + const PropertyMap* pp = reinterpret_cast<const PropertyMap*>(props); 1.183 + ImporterPimpl* pimpl = imp->Pimpl(); 1.184 + pimpl->mIntProperties = pp->ints; 1.185 + pimpl->mFloatProperties = pp->floats; 1.186 + pimpl->mStringProperties = pp->strings; 1.187 + pimpl->mMatrixProperties = pp->matrices; 1.188 + } 1.189 + // setup a custom IO system if necessary 1.190 + if (pFS) { 1.191 + imp->SetIOHandler( new CIOSystemWrapper (pFS) ); 1.192 + } 1.193 + 1.194 + // and have it read the file 1.195 + scene = imp->ReadFile( pFile, pFlags); 1.196 + 1.197 + // if succeeded, store the importer in the scene and keep it alive 1.198 + if( scene) { 1.199 + ScenePrivateData* priv = const_cast<ScenePrivateData*>( ScenePriv(scene) ); 1.200 + priv->mOrigImporter = imp; 1.201 + } else { 1.202 + // if failed, extract error code and destroy the import 1.203 + gLastErrorString = imp->GetErrorString(); 1.204 + delete imp; 1.205 + } 1.206 + 1.207 + // return imported data. If the import failed the pointer is NULL anyways 1.208 + ASSIMP_END_EXCEPTION_REGION(const aiScene*); 1.209 + 1.210 + return scene; 1.211 +} 1.212 + 1.213 +// ------------------------------------------------------------------------------------------------ 1.214 +const aiScene* aiImportFileFromMemory( 1.215 + const char* pBuffer, 1.216 + unsigned int pLength, 1.217 + unsigned int pFlags, 1.218 + const char* pHint) 1.219 +{ 1.220 + return aiImportFileFromMemoryWithProperties(pBuffer, pLength, pFlags, pHint, NULL); 1.221 +} 1.222 + 1.223 +// ------------------------------------------------------------------------------------------------ 1.224 +const aiScene* aiImportFileFromMemoryWithProperties( 1.225 + const char* pBuffer, 1.226 + unsigned int pLength, 1.227 + unsigned int pFlags, 1.228 + const char* pHint, 1.229 + const aiPropertyStore* props) 1.230 +{ 1.231 + ai_assert( NULL != pBuffer ); 1.232 + ai_assert( 0 != pLength ); 1.233 + 1.234 + const aiScene* scene = NULL; 1.235 + ASSIMP_BEGIN_EXCEPTION_REGION(); 1.236 + 1.237 + // create an Importer for this file 1.238 + Assimp::Importer* imp = new Assimp::Importer(); 1.239 + 1.240 + // copy properties 1.241 + if(props) { 1.242 + const PropertyMap* pp = reinterpret_cast<const PropertyMap*>(props); 1.243 + ImporterPimpl* pimpl = imp->Pimpl(); 1.244 + pimpl->mIntProperties = pp->ints; 1.245 + pimpl->mFloatProperties = pp->floats; 1.246 + pimpl->mStringProperties = pp->strings; 1.247 + pimpl->mMatrixProperties = pp->matrices; 1.248 + } 1.249 + 1.250 + // and have it read the file from the memory buffer 1.251 + scene = imp->ReadFileFromMemory( pBuffer, pLength, pFlags,pHint); 1.252 + 1.253 + // if succeeded, store the importer in the scene and keep it alive 1.254 + if( scene) { 1.255 + ScenePrivateData* priv = const_cast<ScenePrivateData*>( ScenePriv(scene) ); 1.256 + priv->mOrigImporter = imp; 1.257 + } 1.258 + else { 1.259 + // if failed, extract error code and destroy the import 1.260 + gLastErrorString = imp->GetErrorString(); 1.261 + delete imp; 1.262 + } 1.263 + // return imported data. If the import failed the pointer is NULL anyways 1.264 + ASSIMP_END_EXCEPTION_REGION(const aiScene*); 1.265 + return scene; 1.266 +} 1.267 + 1.268 +// ------------------------------------------------------------------------------------------------ 1.269 +// Releases all resources associated with the given import process. 1.270 +void aiReleaseImport( const aiScene* pScene) 1.271 +{ 1.272 + if (!pScene) { 1.273 + return; 1.274 + } 1.275 + 1.276 + ASSIMP_BEGIN_EXCEPTION_REGION(); 1.277 + 1.278 + // find the importer associated with this data 1.279 + const ScenePrivateData* priv = ScenePriv(pScene); 1.280 + if( !priv || !priv->mOrigImporter) { 1.281 + delete pScene; 1.282 + } 1.283 + else { 1.284 + // deleting the Importer also deletes the scene 1.285 + // Note: the reason that this is not written as 'delete priv->mOrigImporter' 1.286 + // is a suspected bug in gcc 4.4+ (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52339) 1.287 + Importer* importer = priv->mOrigImporter; 1.288 + delete importer; 1.289 + } 1.290 + 1.291 + ASSIMP_END_EXCEPTION_REGION(void); 1.292 +} 1.293 + 1.294 +// ------------------------------------------------------------------------------------------------ 1.295 +ASSIMP_API const aiScene* aiApplyPostProcessing(const aiScene* pScene, 1.296 + unsigned int pFlags) 1.297 +{ 1.298 + const aiScene* sc = NULL; 1.299 + 1.300 + 1.301 + ASSIMP_BEGIN_EXCEPTION_REGION(); 1.302 + 1.303 + // find the importer associated with this data 1.304 + const ScenePrivateData* priv = ScenePriv(pScene); 1.305 + if( !priv || !priv->mOrigImporter) { 1.306 + ReportSceneNotFoundError(); 1.307 + return NULL; 1.308 + } 1.309 + 1.310 + sc = priv->mOrigImporter->ApplyPostProcessing(pFlags); 1.311 + 1.312 + if (!sc) { 1.313 + aiReleaseImport(pScene); 1.314 + return NULL; 1.315 + } 1.316 + 1.317 + ASSIMP_END_EXCEPTION_REGION(const aiScene*); 1.318 + return sc; 1.319 +} 1.320 + 1.321 +// ------------------------------------------------------------------------------------------------ 1.322 +ASSIMP_API const aiScene *aiApplyCustomizedPostProcessing( const aiScene *scene, 1.323 + BaseProcess* process, 1.324 + bool requestValidation ) { 1.325 + const aiScene* sc( NULL ); 1.326 + 1.327 + ASSIMP_BEGIN_EXCEPTION_REGION(); 1.328 + 1.329 + // find the importer associated with this data 1.330 + const ScenePrivateData* priv = ScenePriv( scene ); 1.331 + if ( NULL == priv || NULL == priv->mOrigImporter ) { 1.332 + ReportSceneNotFoundError(); 1.333 + return NULL; 1.334 + } 1.335 + 1.336 + sc = priv->mOrigImporter->ApplyCustomizedPostProcessing( process, requestValidation ); 1.337 + 1.338 + if ( !sc ) { 1.339 + aiReleaseImport( scene ); 1.340 + return NULL; 1.341 + } 1.342 + 1.343 + ASSIMP_END_EXCEPTION_REGION( const aiScene* ); 1.344 + 1.345 + return sc; 1.346 +} 1.347 + 1.348 +// ------------------------------------------------------------------------------------------------ 1.349 +void CallbackToLogRedirector (const char* msg, char* dt) 1.350 +{ 1.351 + ai_assert( NULL != msg ); 1.352 + ai_assert( NULL != dt ); 1.353 + LogStream* s = (LogStream*)dt; 1.354 + 1.355 + s->write(msg); 1.356 +} 1.357 + 1.358 +// ------------------------------------------------------------------------------------------------ 1.359 +ASSIMP_API aiLogStream aiGetPredefinedLogStream(aiDefaultLogStream pStream,const char* file) 1.360 +{ 1.361 + aiLogStream sout; 1.362 + 1.363 + ASSIMP_BEGIN_EXCEPTION_REGION(); 1.364 + LogStream* stream = LogStream::createDefaultStream(pStream,file); 1.365 + if (!stream) { 1.366 + sout.callback = NULL; 1.367 + sout.user = NULL; 1.368 + } 1.369 + else { 1.370 + sout.callback = &CallbackToLogRedirector; 1.371 + sout.user = (char*)stream; 1.372 + } 1.373 + gPredefinedStreams.push_back(stream); 1.374 + ASSIMP_END_EXCEPTION_REGION(aiLogStream); 1.375 + return sout; 1.376 +} 1.377 + 1.378 +// ------------------------------------------------------------------------------------------------ 1.379 +ASSIMP_API void aiAttachLogStream( const aiLogStream* stream ) 1.380 +{ 1.381 + ASSIMP_BEGIN_EXCEPTION_REGION(); 1.382 + 1.383 +#ifndef ASSIMP_BUILD_SINGLETHREADED 1.384 + std::lock_guard<std::mutex> lock(gLogStreamMutex); 1.385 +#endif 1.386 + 1.387 + LogStream* lg = new LogToCallbackRedirector(*stream); 1.388 + gActiveLogStreams[*stream] = lg; 1.389 + 1.390 + if (DefaultLogger::isNullLogger()) { 1.391 + DefaultLogger::create(NULL,(gVerboseLogging == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL)); 1.392 + } 1.393 + DefaultLogger::get()->attachStream(lg); 1.394 + ASSIMP_END_EXCEPTION_REGION(void); 1.395 +} 1.396 + 1.397 +// ------------------------------------------------------------------------------------------------ 1.398 +ASSIMP_API aiReturn aiDetachLogStream( const aiLogStream* stream) 1.399 +{ 1.400 + ASSIMP_BEGIN_EXCEPTION_REGION(); 1.401 + 1.402 +#ifndef ASSIMP_BUILD_SINGLETHREADED 1.403 + std::lock_guard<std::mutex> lock(gLogStreamMutex); 1.404 +#endif 1.405 + // find the log-stream associated with this data 1.406 + LogStreamMap::iterator it = gActiveLogStreams.find( *stream); 1.407 + // it should be there... else the user is playing fools with us 1.408 + if( it == gActiveLogStreams.end()) { 1.409 + return AI_FAILURE; 1.410 + } 1.411 + DefaultLogger::get()->detatchStream( it->second ); 1.412 + delete it->second; 1.413 + 1.414 + gActiveLogStreams.erase( it); 1.415 + 1.416 + if (gActiveLogStreams.empty()) { 1.417 + DefaultLogger::kill(); 1.418 + } 1.419 + ASSIMP_END_EXCEPTION_REGION(aiReturn); 1.420 + return AI_SUCCESS; 1.421 +} 1.422 + 1.423 +// ------------------------------------------------------------------------------------------------ 1.424 +ASSIMP_API void aiDetachAllLogStreams(void) 1.425 +{ 1.426 + ASSIMP_BEGIN_EXCEPTION_REGION(); 1.427 +#ifndef ASSIMP_BUILD_SINGLETHREADED 1.428 + std::lock_guard<std::mutex> lock(gLogStreamMutex); 1.429 +#endif 1.430 + Logger *logger( DefaultLogger::get() ); 1.431 + if ( NULL == logger ) { 1.432 + return; 1.433 + } 1.434 + 1.435 + for (LogStreamMap::iterator it = gActiveLogStreams.begin(); it != gActiveLogStreams.end(); ++it) { 1.436 + logger->detatchStream( it->second ); 1.437 + delete it->second; 1.438 + } 1.439 + gActiveLogStreams.clear(); 1.440 + DefaultLogger::kill(); 1.441 + 1.442 + ASSIMP_END_EXCEPTION_REGION(void); 1.443 +} 1.444 + 1.445 +// ------------------------------------------------------------------------------------------------ 1.446 +ASSIMP_API void aiEnableVerboseLogging(aiBool d) 1.447 +{ 1.448 + if (!DefaultLogger::isNullLogger()) { 1.449 + DefaultLogger::get()->setLogSeverity((d == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL)); 1.450 + } 1.451 + gVerboseLogging = d; 1.452 +} 1.453 + 1.454 +// ------------------------------------------------------------------------------------------------ 1.455 +// Returns the error text of the last failed import process. 1.456 +const char* aiGetErrorString() 1.457 +{ 1.458 + return gLastErrorString.c_str(); 1.459 +} 1.460 + 1.461 +// ----------------------------------------------------------------------------------------------- 1.462 +// Return the description of a importer given its index 1.463 +const aiImporterDesc* aiGetImportFormatDescription( size_t pIndex) 1.464 +{ 1.465 + return Importer().GetImporterInfo(pIndex); 1.466 +} 1.467 + 1.468 +// ----------------------------------------------------------------------------------------------- 1.469 +// Return the number of importers 1.470 +size_t aiGetImportFormatCount(void) 1.471 +{ 1.472 + return Importer().GetImporterCount(); 1.473 +} 1.474 + 1.475 +// ------------------------------------------------------------------------------------------------ 1.476 +// Returns the error text of the last failed import process. 1.477 +aiBool aiIsExtensionSupported(const char* szExtension) 1.478 +{ 1.479 + ai_assert(NULL != szExtension); 1.480 + aiBool candoit=AI_FALSE; 1.481 + ASSIMP_BEGIN_EXCEPTION_REGION(); 1.482 + 1.483 + // FIXME: no need to create a temporary Importer instance just for that .. 1.484 + Assimp::Importer tmp; 1.485 + candoit = tmp.IsExtensionSupported(std::string(szExtension)) ? AI_TRUE : AI_FALSE; 1.486 + 1.487 + ASSIMP_END_EXCEPTION_REGION(aiBool); 1.488 + return candoit; 1.489 +} 1.490 + 1.491 +// ------------------------------------------------------------------------------------------------ 1.492 +// Get a list of all file extensions supported by ASSIMP 1.493 +void aiGetExtensionList(aiString* szOut) 1.494 +{ 1.495 + ai_assert(NULL != szOut); 1.496 + ASSIMP_BEGIN_EXCEPTION_REGION(); 1.497 + 1.498 + // FIXME: no need to create a temporary Importer instance just for that .. 1.499 + Assimp::Importer tmp; 1.500 + tmp.GetExtensionList(*szOut); 1.501 + 1.502 + ASSIMP_END_EXCEPTION_REGION(void); 1.503 +} 1.504 + 1.505 +// ------------------------------------------------------------------------------------------------ 1.506 +// Get the memory requirements for a particular import. 1.507 +void aiGetMemoryRequirements(const C_STRUCT aiScene* pIn, 1.508 + C_STRUCT aiMemoryInfo* in) 1.509 +{ 1.510 + ASSIMP_BEGIN_EXCEPTION_REGION(); 1.511 + 1.512 + // find the importer associated with this data 1.513 + const ScenePrivateData* priv = ScenePriv(pIn); 1.514 + if( !priv || !priv->mOrigImporter) { 1.515 + ReportSceneNotFoundError(); 1.516 + return; 1.517 + } 1.518 + 1.519 + return priv->mOrigImporter->GetMemoryRequirements(*in); 1.520 + ASSIMP_END_EXCEPTION_REGION(void); 1.521 +} 1.522 + 1.523 +// ------------------------------------------------------------------------------------------------ 1.524 +ASSIMP_API aiPropertyStore* aiCreatePropertyStore(void) 1.525 +{ 1.526 + return reinterpret_cast<aiPropertyStore*>( new PropertyMap() ); 1.527 +} 1.528 + 1.529 +// ------------------------------------------------------------------------------------------------ 1.530 +ASSIMP_API void aiReleasePropertyStore(aiPropertyStore* p) 1.531 +{ 1.532 + delete reinterpret_cast<PropertyMap*>(p); 1.533 +} 1.534 + 1.535 +// ------------------------------------------------------------------------------------------------ 1.536 +// Importer::SetPropertyInteger 1.537 +ASSIMP_API void aiSetImportPropertyInteger(aiPropertyStore* p, const char* szName, int value) 1.538 +{ 1.539 + ASSIMP_BEGIN_EXCEPTION_REGION(); 1.540 + PropertyMap* pp = reinterpret_cast<PropertyMap*>(p); 1.541 + SetGenericProperty<int>(pp->ints,szName,value); 1.542 + ASSIMP_END_EXCEPTION_REGION(void); 1.543 +} 1.544 + 1.545 +// ------------------------------------------------------------------------------------------------ 1.546 +// Importer::SetPropertyFloat 1.547 +ASSIMP_API void aiSetImportPropertyFloat(aiPropertyStore* p, const char* szName, ai_real value) 1.548 +{ 1.549 + ASSIMP_BEGIN_EXCEPTION_REGION(); 1.550 + PropertyMap* pp = reinterpret_cast<PropertyMap*>(p); 1.551 + SetGenericProperty<ai_real>(pp->floats,szName,value); 1.552 + ASSIMP_END_EXCEPTION_REGION(void); 1.553 +} 1.554 + 1.555 +// ------------------------------------------------------------------------------------------------ 1.556 +// Importer::SetPropertyString 1.557 +ASSIMP_API void aiSetImportPropertyString(aiPropertyStore* p, const char* szName, 1.558 + const C_STRUCT aiString* st) 1.559 +{ 1.560 + if (!st) { 1.561 + return; 1.562 + } 1.563 + ASSIMP_BEGIN_EXCEPTION_REGION(); 1.564 + PropertyMap* pp = reinterpret_cast<PropertyMap*>(p); 1.565 + SetGenericProperty<std::string>(pp->strings,szName,std::string(st->C_Str())); 1.566 + ASSIMP_END_EXCEPTION_REGION(void); 1.567 +} 1.568 + 1.569 +// ------------------------------------------------------------------------------------------------ 1.570 +// Importer::SetPropertyMatrix 1.571 +ASSIMP_API void aiSetImportPropertyMatrix(aiPropertyStore* p, const char* szName, 1.572 + const C_STRUCT aiMatrix4x4* mat) 1.573 +{ 1.574 + if (!mat) { 1.575 + return; 1.576 + } 1.577 + ASSIMP_BEGIN_EXCEPTION_REGION(); 1.578 + PropertyMap* pp = reinterpret_cast<PropertyMap*>(p); 1.579 + SetGenericProperty<aiMatrix4x4>(pp->matrices,szName,*mat); 1.580 + ASSIMP_END_EXCEPTION_REGION(void); 1.581 +} 1.582 + 1.583 +// ------------------------------------------------------------------------------------------------ 1.584 +// Rotation matrix to quaternion 1.585 +ASSIMP_API void aiCreateQuaternionFromMatrix(aiQuaternion* quat,const aiMatrix3x3* mat) 1.586 +{ 1.587 + ai_assert( NULL != quat ); 1.588 + ai_assert( NULL != mat ); 1.589 + *quat = aiQuaternion(*mat); 1.590 +} 1.591 + 1.592 +// ------------------------------------------------------------------------------------------------ 1.593 +// Matrix decomposition 1.594 +ASSIMP_API void aiDecomposeMatrix(const aiMatrix4x4* mat,aiVector3D* scaling, 1.595 + aiQuaternion* rotation, 1.596 + aiVector3D* position) 1.597 +{ 1.598 + ai_assert( NULL != rotation ); 1.599 + ai_assert( NULL != position ); 1.600 + ai_assert( NULL != scaling ); 1.601 + ai_assert( NULL != mat ); 1.602 + mat->Decompose(*scaling,*rotation,*position); 1.603 +} 1.604 + 1.605 +// ------------------------------------------------------------------------------------------------ 1.606 +// Matrix transpose 1.607 +ASSIMP_API void aiTransposeMatrix3(aiMatrix3x3* mat) 1.608 +{ 1.609 + ai_assert(NULL != mat); 1.610 + mat->Transpose(); 1.611 +} 1.612 + 1.613 +// ------------------------------------------------------------------------------------------------ 1.614 +ASSIMP_API void aiTransposeMatrix4(aiMatrix4x4* mat) 1.615 +{ 1.616 + ai_assert(NULL != mat); 1.617 + mat->Transpose(); 1.618 +} 1.619 + 1.620 +// ------------------------------------------------------------------------------------------------ 1.621 +// Vector transformation 1.622 +ASSIMP_API void aiTransformVecByMatrix3(aiVector3D* vec, 1.623 + const aiMatrix3x3* mat) 1.624 +{ 1.625 + ai_assert( NULL != mat ); 1.626 + ai_assert( NULL != vec); 1.627 + *vec *= (*mat); 1.628 +} 1.629 + 1.630 +// ------------------------------------------------------------------------------------------------ 1.631 +ASSIMP_API void aiTransformVecByMatrix4(aiVector3D* vec, 1.632 + const aiMatrix4x4* mat) 1.633 +{ 1.634 + ai_assert( NULL != mat ); 1.635 + ai_assert( NULL != vec ); 1.636 + 1.637 + *vec *= (*mat); 1.638 +} 1.639 + 1.640 +// ------------------------------------------------------------------------------------------------ 1.641 +// Matrix multiplication 1.642 +ASSIMP_API void aiMultiplyMatrix4( 1.643 + aiMatrix4x4* dst, 1.644 + const aiMatrix4x4* src) 1.645 +{ 1.646 + ai_assert( NULL != dst ); 1.647 + ai_assert( NULL != src ); 1.648 + *dst = (*dst) * (*src); 1.649 +} 1.650 + 1.651 +// ------------------------------------------------------------------------------------------------ 1.652 +ASSIMP_API void aiMultiplyMatrix3( 1.653 + aiMatrix3x3* dst, 1.654 + const aiMatrix3x3* src) 1.655 +{ 1.656 + ai_assert( NULL != dst ); 1.657 + ai_assert( NULL != src ); 1.658 + *dst = (*dst) * (*src); 1.659 +} 1.660 + 1.661 +// ------------------------------------------------------------------------------------------------ 1.662 +// Matrix identity 1.663 +ASSIMP_API void aiIdentityMatrix3( 1.664 + aiMatrix3x3* mat) 1.665 +{ 1.666 + ai_assert(NULL != mat); 1.667 + *mat = aiMatrix3x3(); 1.668 +} 1.669 + 1.670 +// ------------------------------------------------------------------------------------------------ 1.671 +ASSIMP_API void aiIdentityMatrix4( 1.672 + aiMatrix4x4* mat) 1.673 +{ 1.674 + ai_assert(NULL != mat); 1.675 + *mat = aiMatrix4x4(); 1.676 +} 1.677 + 1.678 +// ------------------------------------------------------------------------------------------------ 1.679 +ASSIMP_API C_STRUCT const aiImporterDesc* aiGetImporterDesc( const char *extension ) { 1.680 + if( NULL == extension ) { 1.681 + return NULL; 1.682 + } 1.683 + const aiImporterDesc *desc( NULL ); 1.684 + std::vector< BaseImporter* > out; 1.685 + GetImporterInstanceList( out ); 1.686 + for( size_t i = 0; i < out.size(); ++i ) { 1.687 + if( 0 == strncmp( out[ i ]->GetInfo()->mFileExtensions, extension, strlen( extension ) ) ) { 1.688 + desc = out[ i ]->GetInfo(); 1.689 + break; 1.690 + } 1.691 + } 1.692 + 1.693 + DeleteImporterInstanceList(out); 1.694 + 1.695 + return desc; 1.696 +} 1.697 + 1.698 +// ------------------------------------------------------------------------------------------------