Assimp.cpp 21 KB

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