Assimp.cpp 23 KB

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