Assimp.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2016, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file Assimp.cpp
  35. * @brief Implementation of the Plain-C API
  36. */
  37. #include <assimp/cimport.h>
  38. #include <assimp/LogStream.hpp>
  39. #include <assimp/DefaultLogger.hpp>
  40. #include <assimp/Importer.hpp>
  41. #include <assimp/importerdesc.h>
  42. #include <assimp/scene.h>
  43. #include "GenericProperty.h"
  44. #include "CInterfaceIOWrapper.h"
  45. #include "Importer.h"
  46. #include "Exceptional.h"
  47. #include "ScenePrivate.h"
  48. #include "BaseImporter.h"
  49. #include <list>
  50. // ------------------------------------------------------------------------------------------------
  51. #ifndef ASSIMP_BUILD_SINGLETHREADED
  52. # include <thread>
  53. # include <mutex>
  54. #endif
  55. // ------------------------------------------------------------------------------------------------
  56. using namespace Assimp;
  57. namespace Assimp
  58. {
  59. // underlying structure for aiPropertyStore
  60. typedef BatchLoader::PropertyMap PropertyMap;
  61. /** Stores the LogStream objects for all active C log streams */
  62. struct mpred {
  63. bool operator () (const aiLogStream& s0, const aiLogStream& s1) const {
  64. return s0.callback<s1.callback&&s0.user<s1.user;
  65. }
  66. };
  67. typedef std::map<aiLogStream, Assimp::LogStream*, mpred> LogStreamMap;
  68. /** Stores the LogStream objects allocated by #aiGetPredefinedLogStream */
  69. typedef std::list<Assimp::LogStream*> PredefLogStreamMap;
  70. /** Local storage of all active log streams */
  71. static LogStreamMap gActiveLogStreams;
  72. /** Local storage of LogStreams allocated by #aiGetPredefinedLogStream */
  73. static PredefLogStreamMap gPredefinedStreams;
  74. /** Error message of the last failed import process */
  75. static std::string gLastErrorString;
  76. /** Verbose logging active or not? */
  77. static aiBool gVerboseLogging = false;
  78. /** will return all registered importers. */
  79. void GetImporterInstanceList(std::vector< BaseImporter* >& out);
  80. /** will delete all registered importers. */
  81. void DeleteImporterInstanceList(std::vector< BaseImporter* >& out);
  82. } // namespace assimp
  83. #ifndef ASSIMP_BUILD_SINGLETHREADED
  84. /** Global mutex to manage the access to the log-stream map */
  85. static std::mutex gLogStreamMutex;
  86. #endif
  87. // ------------------------------------------------------------------------------------------------
  88. // Custom LogStream implementation for the C-API
  89. class LogToCallbackRedirector : public LogStream
  90. {
  91. public:
  92. explicit LogToCallbackRedirector(const aiLogStream& s)
  93. : stream (s) {
  94. ai_assert(NULL != s.callback);
  95. }
  96. ~LogToCallbackRedirector() {
  97. #ifndef ASSIMP_BUILD_SINGLETHREADED
  98. std::lock_guard<std::mutex> lock(gLogStreamMutex);
  99. #endif
  100. // (HACK) Check whether the 'stream.user' pointer points to a
  101. // custom LogStream allocated by #aiGetPredefinedLogStream.
  102. // In this case, we need to delete it, too. Of course, this
  103. // might cause strange problems, but the chance is quite low.
  104. PredefLogStreamMap::iterator it = std::find(gPredefinedStreams.begin(),
  105. gPredefinedStreams.end(), (Assimp::LogStream*)stream.user);
  106. if (it != gPredefinedStreams.end()) {
  107. delete *it;
  108. gPredefinedStreams.erase(it);
  109. }
  110. }
  111. /** @copydoc LogStream::write */
  112. void write(const char* message) {
  113. stream.callback(message,stream.user);
  114. }
  115. private:
  116. aiLogStream stream;
  117. };
  118. // ------------------------------------------------------------------------------------------------
  119. void ReportSceneNotFoundError()
  120. {
  121. DefaultLogger::get()->error("Unable to find the Assimp::Importer for this aiScene. "
  122. "The C-API does not accept scenes produced by the C++ API and vice versa");
  123. ai_assert(false);
  124. }
  125. // ------------------------------------------------------------------------------------------------
  126. // Reads the given file and returns its content.
  127. const aiScene* aiImportFile( const char* pFile, unsigned int pFlags)
  128. {
  129. return aiImportFileEx(pFile,pFlags,NULL);
  130. }
  131. // ------------------------------------------------------------------------------------------------
  132. const aiScene* aiImportFileEx( const char* pFile, unsigned int pFlags, aiFileIO* pFS)
  133. {
  134. return aiImportFileExWithProperties(pFile, pFlags, pFS, NULL);
  135. }
  136. // ------------------------------------------------------------------------------------------------
  137. const aiScene* aiImportFileExWithProperties( const char* pFile, unsigned int pFlags,
  138. aiFileIO* pFS,
  139. const aiPropertyStore* props)
  140. {
  141. ai_assert(NULL != pFile);
  142. const aiScene* scene = NULL;
  143. ASSIMP_BEGIN_EXCEPTION_REGION();
  144. // create an Importer for this file
  145. Assimp::Importer* imp = new Assimp::Importer();
  146. // copy properties
  147. if(props) {
  148. const PropertyMap* pp = reinterpret_cast<const PropertyMap*>(props);
  149. ImporterPimpl* pimpl = imp->Pimpl();
  150. pimpl->mIntProperties = pp->ints;
  151. pimpl->mFloatProperties = pp->floats;
  152. pimpl->mStringProperties = pp->strings;
  153. pimpl->mMatrixProperties = pp->matrices;
  154. }
  155. // setup a custom IO system if necessary
  156. if (pFS) {
  157. imp->SetIOHandler( new CIOSystemWrapper (pFS) );
  158. }
  159. // and have it read the file
  160. scene = imp->ReadFile( pFile, pFlags);
  161. // if succeeded, store the importer in the scene and keep it alive
  162. if( scene) {
  163. ScenePrivateData* priv = const_cast<ScenePrivateData*>( ScenePriv(scene) );
  164. priv->mOrigImporter = imp;
  165. }
  166. else {
  167. // if failed, extract error code and destroy the import
  168. gLastErrorString = imp->GetErrorString();
  169. delete imp;
  170. }
  171. // return imported data. If the import failed the pointer is NULL anyways
  172. ASSIMP_END_EXCEPTION_REGION(const aiScene*);
  173. return scene;
  174. }
  175. // ------------------------------------------------------------------------------------------------
  176. const aiScene* aiImportFileFromMemory(
  177. const char* pBuffer,
  178. unsigned int pLength,
  179. unsigned int pFlags,
  180. const char* pHint)
  181. {
  182. return aiImportFileFromMemoryWithProperties(pBuffer, pLength, pFlags, pHint, NULL);
  183. }
  184. // ------------------------------------------------------------------------------------------------
  185. const aiScene* aiImportFileFromMemoryWithProperties(
  186. const char* pBuffer,
  187. unsigned int pLength,
  188. unsigned int pFlags,
  189. const char* pHint,
  190. const aiPropertyStore* props)
  191. {
  192. ai_assert( NULL != pBuffer );
  193. ai_assert( 0 != pLength );
  194. const aiScene* scene = NULL;
  195. ASSIMP_BEGIN_EXCEPTION_REGION();
  196. // create an Importer for this file
  197. Assimp::Importer* imp = new Assimp::Importer();
  198. // copy properties
  199. if(props) {
  200. const PropertyMap* pp = reinterpret_cast<const PropertyMap*>(props);
  201. ImporterPimpl* pimpl = imp->Pimpl();
  202. pimpl->mIntProperties = pp->ints;
  203. pimpl->mFloatProperties = pp->floats;
  204. pimpl->mStringProperties = pp->strings;
  205. pimpl->mMatrixProperties = pp->matrices;
  206. }
  207. // and have it read the file from the memory buffer
  208. scene = imp->ReadFileFromMemory( pBuffer, pLength, pFlags,pHint);
  209. // if succeeded, store the importer in the scene and keep it alive
  210. if( scene) {
  211. ScenePrivateData* priv = const_cast<ScenePrivateData*>( ScenePriv(scene) );
  212. priv->mOrigImporter = imp;
  213. }
  214. else {
  215. // if failed, extract error code and destroy the import
  216. gLastErrorString = imp->GetErrorString();
  217. delete imp;
  218. }
  219. // return imported data. If the import failed the pointer is NULL anyways
  220. ASSIMP_END_EXCEPTION_REGION(const aiScene*);
  221. return scene;
  222. }
  223. // ------------------------------------------------------------------------------------------------
  224. // Releases all resources associated with the given import process.
  225. void aiReleaseImport( const aiScene* pScene)
  226. {
  227. if (!pScene) {
  228. return;
  229. }
  230. ASSIMP_BEGIN_EXCEPTION_REGION();
  231. // find the importer associated with this data
  232. const ScenePrivateData* priv = ScenePriv(pScene);
  233. if( !priv || !priv->mOrigImporter) {
  234. delete pScene;
  235. }
  236. else {
  237. // deleting the Importer also deletes the scene
  238. // Note: the reason that this is not written as 'delete priv->mOrigImporter'
  239. // is a suspected bug in gcc 4.4+ (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52339)
  240. Importer* importer = priv->mOrigImporter;
  241. delete importer;
  242. }
  243. ASSIMP_END_EXCEPTION_REGION(void);
  244. }
  245. // ------------------------------------------------------------------------------------------------
  246. ASSIMP_API const aiScene* aiApplyPostProcessing(const aiScene* pScene,
  247. unsigned int pFlags)
  248. {
  249. const aiScene* sc = NULL;
  250. ASSIMP_BEGIN_EXCEPTION_REGION();
  251. // find the importer associated with this data
  252. const ScenePrivateData* priv = ScenePriv(pScene);
  253. if( !priv || !priv->mOrigImporter) {
  254. ReportSceneNotFoundError();
  255. return NULL;
  256. }
  257. sc = priv->mOrigImporter->ApplyPostProcessing(pFlags);
  258. if (!sc) {
  259. aiReleaseImport(pScene);
  260. return NULL;
  261. }
  262. ASSIMP_END_EXCEPTION_REGION(const aiScene*);
  263. return sc;
  264. }
  265. // ------------------------------------------------------------------------------------------------
  266. ASSIMP_API const aiScene *aiApplyCustomizedPostProcessing( const aiScene *scene,
  267. BaseProcess* process,
  268. bool requestValidation ) {
  269. const aiScene* sc( NULL );
  270. ASSIMP_BEGIN_EXCEPTION_REGION();
  271. // find the importer associated with this data
  272. const ScenePrivateData* priv = ScenePriv( scene );
  273. if ( NULL == priv || NULL == priv->mOrigImporter ) {
  274. ReportSceneNotFoundError();
  275. return NULL;
  276. }
  277. sc = priv->mOrigImporter->ApplyCustomizedPostProcessing( process, requestValidation );
  278. if ( !sc ) {
  279. aiReleaseImport( scene );
  280. return NULL;
  281. }
  282. ASSIMP_END_EXCEPTION_REGION( const aiScene* );
  283. return sc;
  284. }
  285. // ------------------------------------------------------------------------------------------------
  286. void CallbackToLogRedirector (const char* msg, char* dt)
  287. {
  288. ai_assert( NULL != msg );
  289. ai_assert( NULL != dt );
  290. LogStream* s = (LogStream*)dt;
  291. s->write(msg);
  292. }
  293. // ------------------------------------------------------------------------------------------------
  294. ASSIMP_API aiLogStream aiGetPredefinedLogStream(aiDefaultLogStream pStream,const char* file)
  295. {
  296. aiLogStream sout;
  297. ASSIMP_BEGIN_EXCEPTION_REGION();
  298. LogStream* stream = LogStream::createDefaultStream(pStream,file);
  299. if (!stream) {
  300. sout.callback = NULL;
  301. sout.user = NULL;
  302. }
  303. else {
  304. sout.callback = &CallbackToLogRedirector;
  305. sout.user = (char*)stream;
  306. }
  307. gPredefinedStreams.push_back(stream);
  308. ASSIMP_END_EXCEPTION_REGION(aiLogStream);
  309. return sout;
  310. }
  311. // ------------------------------------------------------------------------------------------------
  312. ASSIMP_API void aiAttachLogStream( const aiLogStream* stream )
  313. {
  314. ASSIMP_BEGIN_EXCEPTION_REGION();
  315. #ifndef ASSIMP_BUILD_SINGLETHREADED
  316. std::lock_guard<std::mutex> lock(gLogStreamMutex);
  317. #endif
  318. LogStream* lg = new LogToCallbackRedirector(*stream);
  319. gActiveLogStreams[*stream] = lg;
  320. if (DefaultLogger::isNullLogger()) {
  321. DefaultLogger::create(NULL,(gVerboseLogging == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL));
  322. }
  323. DefaultLogger::get()->attachStream(lg);
  324. ASSIMP_END_EXCEPTION_REGION(void);
  325. }
  326. // ------------------------------------------------------------------------------------------------
  327. ASSIMP_API aiReturn aiDetachLogStream( const aiLogStream* stream)
  328. {
  329. ASSIMP_BEGIN_EXCEPTION_REGION();
  330. #ifndef ASSIMP_BUILD_SINGLETHREADED
  331. std::lock_guard<std::mutex> lock(gLogStreamMutex);
  332. #endif
  333. // find the log-stream associated with this data
  334. LogStreamMap::iterator it = gActiveLogStreams.find( *stream);
  335. // it should be there... else the user is playing fools with us
  336. if( it == gActiveLogStreams.end()) {
  337. return AI_FAILURE;
  338. }
  339. DefaultLogger::get()->detatchStream( it->second );
  340. delete it->second;
  341. gActiveLogStreams.erase( it);
  342. if (gActiveLogStreams.empty()) {
  343. DefaultLogger::kill();
  344. }
  345. ASSIMP_END_EXCEPTION_REGION(aiReturn);
  346. return AI_SUCCESS;
  347. }
  348. // ------------------------------------------------------------------------------------------------
  349. ASSIMP_API void aiDetachAllLogStreams(void)
  350. {
  351. ASSIMP_BEGIN_EXCEPTION_REGION();
  352. #ifndef ASSIMP_BUILD_SINGLETHREADED
  353. std::lock_guard<std::mutex> lock(gLogStreamMutex);
  354. #endif
  355. Logger *logger( DefaultLogger::get() );
  356. if ( NULL == logger ) {
  357. return;
  358. }
  359. for (LogStreamMap::iterator it = gActiveLogStreams.begin(); it != gActiveLogStreams.end(); ++it) {
  360. logger->detatchStream( it->second );
  361. delete it->second;
  362. }
  363. gActiveLogStreams.clear();
  364. DefaultLogger::kill();
  365. ASSIMP_END_EXCEPTION_REGION(void);
  366. }
  367. // ------------------------------------------------------------------------------------------------
  368. ASSIMP_API void aiEnableVerboseLogging(aiBool d)
  369. {
  370. if (!DefaultLogger::isNullLogger()) {
  371. DefaultLogger::get()->setLogSeverity((d == AI_TRUE ? Logger::VERBOSE : Logger::NORMAL));
  372. }
  373. gVerboseLogging = d;
  374. }
  375. // ------------------------------------------------------------------------------------------------
  376. // Returns the error text of the last failed import process.
  377. const char* aiGetErrorString()
  378. {
  379. return gLastErrorString.c_str();
  380. }
  381. // -----------------------------------------------------------------------------------------------
  382. // Return the description of a importer given its index
  383. const aiImporterDesc* aiGetImportFormatDescription( size_t pIndex)
  384. {
  385. return Importer().GetImporterInfo(pIndex);
  386. }
  387. // -----------------------------------------------------------------------------------------------
  388. // Return the number of importers
  389. size_t aiGetImportFormatCount(void)
  390. {
  391. return Importer().GetImporterCount();
  392. }
  393. // ------------------------------------------------------------------------------------------------
  394. // Returns the error text of the last failed import process.
  395. aiBool aiIsExtensionSupported(const char* szExtension)
  396. {
  397. ai_assert(NULL != szExtension);
  398. aiBool candoit=AI_FALSE;
  399. ASSIMP_BEGIN_EXCEPTION_REGION();
  400. // FIXME: no need to create a temporary Importer instance just for that ..
  401. Assimp::Importer tmp;
  402. candoit = tmp.IsExtensionSupported(std::string(szExtension)) ? AI_TRUE : AI_FALSE;
  403. ASSIMP_END_EXCEPTION_REGION(aiBool);
  404. return candoit;
  405. }
  406. // ------------------------------------------------------------------------------------------------
  407. // Get a list of all file extensions supported by ASSIMP
  408. void aiGetExtensionList(aiString* szOut)
  409. {
  410. ai_assert(NULL != szOut);
  411. ASSIMP_BEGIN_EXCEPTION_REGION();
  412. // FIXME: no need to create a temporary Importer instance just for that ..
  413. Assimp::Importer tmp;
  414. tmp.GetExtensionList(*szOut);
  415. ASSIMP_END_EXCEPTION_REGION(void);
  416. }
  417. // ------------------------------------------------------------------------------------------------
  418. // Get the memory requirements for a particular import.
  419. void aiGetMemoryRequirements(const C_STRUCT aiScene* pIn,
  420. C_STRUCT aiMemoryInfo* in)
  421. {
  422. ASSIMP_BEGIN_EXCEPTION_REGION();
  423. // find the importer associated with this data
  424. const ScenePrivateData* priv = ScenePriv(pIn);
  425. if( !priv || !priv->mOrigImporter) {
  426. ReportSceneNotFoundError();
  427. return;
  428. }
  429. return priv->mOrigImporter->GetMemoryRequirements(*in);
  430. ASSIMP_END_EXCEPTION_REGION(void);
  431. }
  432. // ------------------------------------------------------------------------------------------------
  433. ASSIMP_API aiPropertyStore* aiCreatePropertyStore(void)
  434. {
  435. return reinterpret_cast<aiPropertyStore*>( new PropertyMap() );
  436. }
  437. // ------------------------------------------------------------------------------------------------
  438. ASSIMP_API void aiReleasePropertyStore(aiPropertyStore* p)
  439. {
  440. delete reinterpret_cast<PropertyMap*>(p);
  441. }
  442. // ------------------------------------------------------------------------------------------------
  443. // Importer::SetPropertyInteger
  444. ASSIMP_API void aiSetImportPropertyInteger(aiPropertyStore* p, const char* szName, int value)
  445. {
  446. ASSIMP_BEGIN_EXCEPTION_REGION();
  447. PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
  448. SetGenericProperty<int>(pp->ints,szName,value);
  449. ASSIMP_END_EXCEPTION_REGION(void);
  450. }
  451. // ------------------------------------------------------------------------------------------------
  452. // Importer::SetPropertyFloat
  453. ASSIMP_API void aiSetImportPropertyFloat(aiPropertyStore* p, const char* szName, ai_real value)
  454. {
  455. ASSIMP_BEGIN_EXCEPTION_REGION();
  456. PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
  457. SetGenericProperty<ai_real>(pp->floats,szName,value);
  458. ASSIMP_END_EXCEPTION_REGION(void);
  459. }
  460. // ------------------------------------------------------------------------------------------------
  461. // Importer::SetPropertyString
  462. ASSIMP_API void aiSetImportPropertyString(aiPropertyStore* p, const char* szName,
  463. const C_STRUCT aiString* st)
  464. {
  465. if (!st) {
  466. return;
  467. }
  468. ASSIMP_BEGIN_EXCEPTION_REGION();
  469. PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
  470. SetGenericProperty<std::string>(pp->strings,szName,std::string(st->C_Str()));
  471. ASSIMP_END_EXCEPTION_REGION(void);
  472. }
  473. // ------------------------------------------------------------------------------------------------
  474. // Importer::SetPropertyMatrix
  475. ASSIMP_API void aiSetImportPropertyMatrix(aiPropertyStore* p, const char* szName,
  476. const C_STRUCT aiMatrix4x4* mat)
  477. {
  478. if (!mat) {
  479. return;
  480. }
  481. ASSIMP_BEGIN_EXCEPTION_REGION();
  482. PropertyMap* pp = reinterpret_cast<PropertyMap*>(p);
  483. SetGenericProperty<aiMatrix4x4>(pp->matrices,szName,*mat);
  484. ASSIMP_END_EXCEPTION_REGION(void);
  485. }
  486. // ------------------------------------------------------------------------------------------------
  487. // Rotation matrix to quaternion
  488. ASSIMP_API void aiCreateQuaternionFromMatrix(aiQuaternion* quat,const aiMatrix3x3* mat)
  489. {
  490. ai_assert( NULL != quat );
  491. ai_assert( NULL != mat );
  492. *quat = aiQuaternion(*mat);
  493. }
  494. // ------------------------------------------------------------------------------------------------
  495. // Matrix decomposition
  496. ASSIMP_API void aiDecomposeMatrix(const aiMatrix4x4* mat,aiVector3D* scaling,
  497. aiQuaternion* rotation,
  498. aiVector3D* position)
  499. {
  500. ai_assert( NULL != rotation );
  501. ai_assert( NULL != position );
  502. ai_assert( NULL != scaling );
  503. ai_assert( NULL != mat );
  504. mat->Decompose(*scaling,*rotation,*position);
  505. }
  506. // ------------------------------------------------------------------------------------------------
  507. // Matrix transpose
  508. ASSIMP_API void aiTransposeMatrix3(aiMatrix3x3* mat)
  509. {
  510. ai_assert(NULL != mat);
  511. mat->Transpose();
  512. }
  513. // ------------------------------------------------------------------------------------------------
  514. ASSIMP_API void aiTransposeMatrix4(aiMatrix4x4* mat)
  515. {
  516. ai_assert(NULL != mat);
  517. mat->Transpose();
  518. }
  519. // ------------------------------------------------------------------------------------------------
  520. // Vector transformation
  521. ASSIMP_API void aiTransformVecByMatrix3(aiVector3D* vec,
  522. const aiMatrix3x3* mat)
  523. {
  524. ai_assert( NULL != mat );
  525. ai_assert( NULL != vec);
  526. *vec *= (*mat);
  527. }
  528. // ------------------------------------------------------------------------------------------------
  529. ASSIMP_API void aiTransformVecByMatrix4(aiVector3D* vec,
  530. const aiMatrix4x4* mat)
  531. {
  532. ai_assert( NULL != mat );
  533. ai_assert( NULL != vec );
  534. *vec *= (*mat);
  535. }
  536. // ------------------------------------------------------------------------------------------------
  537. // Matrix multiplication
  538. ASSIMP_API void aiMultiplyMatrix4(
  539. aiMatrix4x4* dst,
  540. const aiMatrix4x4* src)
  541. {
  542. ai_assert( NULL != dst );
  543. ai_assert( NULL != src );
  544. *dst = (*dst) * (*src);
  545. }
  546. // ------------------------------------------------------------------------------------------------
  547. ASSIMP_API void aiMultiplyMatrix3(
  548. aiMatrix3x3* dst,
  549. const aiMatrix3x3* src)
  550. {
  551. ai_assert( NULL != dst );
  552. ai_assert( NULL != src );
  553. *dst = (*dst) * (*src);
  554. }
  555. // ------------------------------------------------------------------------------------------------
  556. // Matrix identity
  557. ASSIMP_API void aiIdentityMatrix3(
  558. aiMatrix3x3* mat)
  559. {
  560. ai_assert(NULL != mat);
  561. *mat = aiMatrix3x3();
  562. }
  563. // ------------------------------------------------------------------------------------------------
  564. ASSIMP_API void aiIdentityMatrix4(
  565. aiMatrix4x4* mat)
  566. {
  567. ai_assert(NULL != mat);
  568. *mat = aiMatrix4x4();
  569. }
  570. // ------------------------------------------------------------------------------------------------
  571. ASSIMP_API C_STRUCT const aiImporterDesc* aiGetImporterDesc( const char *extension ) {
  572. if( NULL == extension ) {
  573. return NULL;
  574. }
  575. const aiImporterDesc *desc( NULL );
  576. std::vector< BaseImporter* > out;
  577. GetImporterInstanceList( out );
  578. for( size_t i = 0; i < out.size(); ++i ) {
  579. if( 0 == strncmp( out[ i ]->GetInfo()->mFileExtensions, extension, strlen( extension ) ) ) {
  580. desc = out[ i ]->GetInfo();
  581. break;
  582. }
  583. }
  584. DeleteImporterInstanceList(out);
  585. return desc;
  586. }
  587. // ------------------------------------------------------------------------------------------------