Assimp.cpp 21 KB

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