Assimp.cpp 21 KB

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