Importer.cpp 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2019, 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 Importer.cpp
  35. * @brief Implementation of the CPP-API class #Importer
  36. */
  37. #include <assimp/version.h>
  38. #include <assimp/config.h>
  39. #include <assimp/importerdesc.h>
  40. // ------------------------------------------------------------------------------------------------
  41. /* Uncomment this line to prevent Assimp from catching unknown exceptions.
  42. *
  43. * Note that any Exception except DeadlyImportError may lead to
  44. * undefined behaviour -> loaders could remain in an unusable state and
  45. * further imports with the same Importer instance could fail/crash/burn ...
  46. */
  47. // ------------------------------------------------------------------------------------------------
  48. #ifndef ASSIMP_BUILD_DEBUG
  49. # define ASSIMP_CATCH_GLOBAL_EXCEPTIONS
  50. #endif
  51. // ------------------------------------------------------------------------------------------------
  52. // Internal headers
  53. // ------------------------------------------------------------------------------------------------
  54. #include "Common/Importer.h"
  55. #include "Common/BaseProcess.h"
  56. #include "Common/DefaultProgressHandler.h"
  57. #include "PostProcessing/ProcessHelper.h"
  58. #include "Common/ScenePreprocessor.h"
  59. #include "Common/ScenePrivate.h"
  60. #include <assimp/BaseImporter.h>
  61. #include <assimp/GenericProperty.h>
  62. #include <assimp/MemoryIOWrapper.h>
  63. #include <assimp/Profiler.h>
  64. #include <assimp/TinyFormatter.h>
  65. #include <assimp/Exceptional.h>
  66. #include <assimp/Profiler.h>
  67. #include <set>
  68. #include <memory>
  69. #include <cctype>
  70. #include <assimp/DefaultIOStream.h>
  71. #include <assimp/DefaultIOSystem.h>
  72. #ifndef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  73. # include "PostProcessing/ValidateDataStructure.h"
  74. #endif
  75. using namespace Assimp::Profiling;
  76. using namespace Assimp::Formatter;
  77. namespace Assimp {
  78. // ImporterRegistry.cpp
  79. void GetImporterInstanceList(std::vector< BaseImporter* >& out);
  80. void DeleteImporterInstanceList(std::vector< BaseImporter* >& out);
  81. // PostStepRegistry.cpp
  82. void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out);
  83. }
  84. using namespace Assimp;
  85. using namespace Assimp::Intern;
  86. // ------------------------------------------------------------------------------------------------
  87. // Intern::AllocateFromAssimpHeap serves as abstract base class. It overrides
  88. // new and delete (and their array counterparts) of public API classes (e.g. Logger) to
  89. // utilize our DLL heap.
  90. // See http://www.gotw.ca/publications/mill15.htm
  91. // ------------------------------------------------------------------------------------------------
  92. void* AllocateFromAssimpHeap::operator new ( size_t num_bytes) {
  93. return ::operator new(num_bytes);
  94. }
  95. void* AllocateFromAssimpHeap::operator new ( size_t num_bytes, const std::nothrow_t& ) throw() {
  96. try {
  97. return AllocateFromAssimpHeap::operator new( num_bytes );
  98. }
  99. catch( ... ) {
  100. return NULL;
  101. }
  102. }
  103. void AllocateFromAssimpHeap::operator delete ( void* data) {
  104. return ::operator delete(data);
  105. }
  106. void* AllocateFromAssimpHeap::operator new[] ( size_t num_bytes) {
  107. return ::operator new[](num_bytes);
  108. }
  109. void* AllocateFromAssimpHeap::operator new[] ( size_t num_bytes, const std::nothrow_t& ) throw() {
  110. try {
  111. return AllocateFromAssimpHeap::operator new[]( num_bytes );
  112. }
  113. catch( ... ) {
  114. return NULL;
  115. }
  116. }
  117. void AllocateFromAssimpHeap::operator delete[] ( void* data) {
  118. return ::operator delete[](data);
  119. }
  120. // ------------------------------------------------------------------------------------------------
  121. // Importer constructor.
  122. Importer::Importer()
  123. : pimpl( new ImporterPimpl ) {
  124. pimpl->mScene = NULL;
  125. pimpl->mErrorString = "";
  126. // Allocate a default IO handler
  127. pimpl->mIOHandler = new DefaultIOSystem;
  128. pimpl->mIsDefaultHandler = true;
  129. pimpl->bExtraVerbose = false; // disable extra verbose mode by default
  130. pimpl->mProgressHandler = new DefaultProgressHandler();
  131. pimpl->mIsDefaultProgressHandler = true;
  132. GetImporterInstanceList(pimpl->mImporter);
  133. GetPostProcessingStepInstanceList(pimpl->mPostProcessingSteps);
  134. // Allocate a SharedPostProcessInfo object and store pointers to it in all post-process steps in the list.
  135. pimpl->mPPShared = new SharedPostProcessInfo();
  136. for (std::vector<BaseProcess*>::iterator it = pimpl->mPostProcessingSteps.begin();
  137. it != pimpl->mPostProcessingSteps.end();
  138. ++it) {
  139. (*it)->SetSharedData(pimpl->mPPShared);
  140. }
  141. }
  142. // ------------------------------------------------------------------------------------------------
  143. // Destructor of Importer
  144. Importer::~Importer()
  145. {
  146. // Delete all import plugins
  147. DeleteImporterInstanceList(pimpl->mImporter);
  148. // Delete all post-processing plug-ins
  149. for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++)
  150. delete pimpl->mPostProcessingSteps[a];
  151. // Delete the assigned IO and progress handler
  152. delete pimpl->mIOHandler;
  153. delete pimpl->mProgressHandler;
  154. // Kill imported scene. Destructor's should do that recursively
  155. delete pimpl->mScene;
  156. // Delete shared post-processing data
  157. delete pimpl->mPPShared;
  158. // and finally the pimpl itself
  159. delete pimpl;
  160. }
  161. // ------------------------------------------------------------------------------------------------
  162. // Register a custom post-processing step
  163. aiReturn Importer::RegisterPPStep(BaseProcess* pImp)
  164. {
  165. ai_assert(NULL != pImp);
  166. ASSIMP_BEGIN_EXCEPTION_REGION();
  167. pimpl->mPostProcessingSteps.push_back(pImp);
  168. ASSIMP_LOG_INFO("Registering custom post-processing step");
  169. ASSIMP_END_EXCEPTION_REGION(aiReturn);
  170. return AI_SUCCESS;
  171. }
  172. // ------------------------------------------------------------------------------------------------
  173. // Register a custom loader plugin
  174. aiReturn Importer::RegisterLoader(BaseImporter* pImp)
  175. {
  176. ai_assert(NULL != pImp);
  177. ASSIMP_BEGIN_EXCEPTION_REGION();
  178. // --------------------------------------------------------------------
  179. // Check whether we would have two loaders for the same file extension
  180. // This is absolutely OK, but we should warn the developer of the new
  181. // loader that his code will probably never be called if the first
  182. // loader is a bit too lazy in his file checking.
  183. // --------------------------------------------------------------------
  184. std::set<std::string> st;
  185. std::string baked;
  186. pImp->GetExtensionList(st);
  187. for(std::set<std::string>::const_iterator it = st.begin(); it != st.end(); ++it) {
  188. #ifdef ASSIMP_BUILD_DEBUG
  189. if (IsExtensionSupported(*it)) {
  190. ASSIMP_LOG_WARN_F("The file extension ", *it, " is already in use");
  191. }
  192. #endif
  193. baked += *it;
  194. }
  195. // add the loader
  196. pimpl->mImporter.push_back(pImp);
  197. ASSIMP_LOG_INFO_F("Registering custom importer for these file extensions: ", baked);
  198. ASSIMP_END_EXCEPTION_REGION(aiReturn);
  199. return AI_SUCCESS;
  200. }
  201. // ------------------------------------------------------------------------------------------------
  202. // Unregister a custom loader plugin
  203. aiReturn Importer::UnregisterLoader(BaseImporter* pImp)
  204. {
  205. if(!pImp) {
  206. // unregistering a NULL importer is no problem for us ... really!
  207. return AI_SUCCESS;
  208. }
  209. ASSIMP_BEGIN_EXCEPTION_REGION();
  210. std::vector<BaseImporter*>::iterator it = std::find(pimpl->mImporter.begin(),
  211. pimpl->mImporter.end(),pImp);
  212. if (it != pimpl->mImporter.end()) {
  213. pimpl->mImporter.erase(it);
  214. ASSIMP_LOG_INFO("Unregistering custom importer: ");
  215. return AI_SUCCESS;
  216. }
  217. ASSIMP_LOG_WARN("Unable to remove custom importer: I can't find you ...");
  218. ASSIMP_END_EXCEPTION_REGION(aiReturn);
  219. return AI_FAILURE;
  220. }
  221. // ------------------------------------------------------------------------------------------------
  222. // Unregister a custom loader plugin
  223. aiReturn Importer::UnregisterPPStep(BaseProcess* pImp)
  224. {
  225. if(!pImp) {
  226. // unregistering a NULL ppstep is no problem for us ... really!
  227. return AI_SUCCESS;
  228. }
  229. ASSIMP_BEGIN_EXCEPTION_REGION();
  230. std::vector<BaseProcess*>::iterator it = std::find(pimpl->mPostProcessingSteps.begin(),
  231. pimpl->mPostProcessingSteps.end(),pImp);
  232. if (it != pimpl->mPostProcessingSteps.end()) {
  233. pimpl->mPostProcessingSteps.erase(it);
  234. ASSIMP_LOG_INFO("Unregistering custom post-processing step");
  235. return AI_SUCCESS;
  236. }
  237. ASSIMP_LOG_WARN("Unable to remove custom post-processing step: I can't find you ..");
  238. ASSIMP_END_EXCEPTION_REGION(aiReturn);
  239. return AI_FAILURE;
  240. }
  241. // ------------------------------------------------------------------------------------------------
  242. // Supplies a custom IO handler to the importer to open and access files.
  243. void Importer::SetIOHandler( IOSystem* pIOHandler)
  244. {
  245. ASSIMP_BEGIN_EXCEPTION_REGION();
  246. // If the new handler is zero, allocate a default IO implementation.
  247. if (!pIOHandler)
  248. {
  249. // Release pointer in the possession of the caller
  250. pimpl->mIOHandler = new DefaultIOSystem();
  251. pimpl->mIsDefaultHandler = true;
  252. }
  253. // Otherwise register the custom handler
  254. else if (pimpl->mIOHandler != pIOHandler)
  255. {
  256. delete pimpl->mIOHandler;
  257. pimpl->mIOHandler = pIOHandler;
  258. pimpl->mIsDefaultHandler = false;
  259. }
  260. ASSIMP_END_EXCEPTION_REGION(void);
  261. }
  262. // ------------------------------------------------------------------------------------------------
  263. // Get the currently set IO handler
  264. IOSystem* Importer::GetIOHandler() const {
  265. return pimpl->mIOHandler;
  266. }
  267. // ------------------------------------------------------------------------------------------------
  268. // Check whether a custom IO handler is currently set
  269. bool Importer::IsDefaultIOHandler() const {
  270. return pimpl->mIsDefaultHandler;
  271. }
  272. // ------------------------------------------------------------------------------------------------
  273. // Supplies a custom progress handler to get regular callbacks during importing
  274. void Importer::SetProgressHandler ( ProgressHandler* pHandler ) {
  275. ASSIMP_BEGIN_EXCEPTION_REGION();
  276. // If the new handler is zero, allocate a default implementation.
  277. if (!pHandler)
  278. {
  279. // Release pointer in the possession of the caller
  280. pimpl->mProgressHandler = new DefaultProgressHandler();
  281. pimpl->mIsDefaultProgressHandler = true;
  282. }
  283. // Otherwise register the custom handler
  284. else if (pimpl->mProgressHandler != pHandler)
  285. {
  286. delete pimpl->mProgressHandler;
  287. pimpl->mProgressHandler = pHandler;
  288. pimpl->mIsDefaultProgressHandler = false;
  289. }
  290. ASSIMP_END_EXCEPTION_REGION(void);
  291. }
  292. // ------------------------------------------------------------------------------------------------
  293. // Get the currently set progress handler
  294. ProgressHandler* Importer::GetProgressHandler() const {
  295. return pimpl->mProgressHandler;
  296. }
  297. // ------------------------------------------------------------------------------------------------
  298. // Check whether a custom progress handler is currently set
  299. bool Importer::IsDefaultProgressHandler() const {
  300. return pimpl->mIsDefaultProgressHandler;
  301. }
  302. // ------------------------------------------------------------------------------------------------
  303. // Validate post process step flags
  304. bool _ValidateFlags(unsigned int pFlags)
  305. {
  306. if (pFlags & aiProcess_GenSmoothNormals && pFlags & aiProcess_GenNormals) {
  307. ASSIMP_LOG_ERROR("#aiProcess_GenSmoothNormals and #aiProcess_GenNormals are incompatible");
  308. return false;
  309. }
  310. if (pFlags & aiProcess_OptimizeGraph && pFlags & aiProcess_PreTransformVertices) {
  311. ASSIMP_LOG_ERROR("#aiProcess_OptimizeGraph and #aiProcess_PreTransformVertices are incompatible");
  312. return false;
  313. }
  314. return true;
  315. }
  316. // ------------------------------------------------------------------------------------------------
  317. // Free the current scene
  318. void Importer::FreeScene( )
  319. {
  320. ASSIMP_BEGIN_EXCEPTION_REGION();
  321. delete pimpl->mScene;
  322. pimpl->mScene = NULL;
  323. pimpl->mErrorString = "";
  324. ASSIMP_END_EXCEPTION_REGION(void);
  325. }
  326. // ------------------------------------------------------------------------------------------------
  327. // Get the current error string, if any
  328. const char* Importer::GetErrorString() const
  329. {
  330. /* Must remain valid as long as ReadFile() or FreeFile() are not called */
  331. return pimpl->mErrorString.c_str();
  332. }
  333. // ------------------------------------------------------------------------------------------------
  334. // Enable extra-verbose mode
  335. void Importer::SetExtraVerbose(bool bDo)
  336. {
  337. pimpl->bExtraVerbose = bDo;
  338. }
  339. // ------------------------------------------------------------------------------------------------
  340. // Get the current scene
  341. const aiScene* Importer::GetScene() const
  342. {
  343. return pimpl->mScene;
  344. }
  345. // ------------------------------------------------------------------------------------------------
  346. // Orphan the current scene and return it.
  347. aiScene* Importer::GetOrphanedScene()
  348. {
  349. aiScene* s = pimpl->mScene;
  350. ASSIMP_BEGIN_EXCEPTION_REGION();
  351. pimpl->mScene = NULL;
  352. pimpl->mErrorString = ""; /* reset error string */
  353. ASSIMP_END_EXCEPTION_REGION(aiScene*);
  354. return s;
  355. }
  356. // ------------------------------------------------------------------------------------------------
  357. // Validate post-processing flags
  358. bool Importer::ValidateFlags(unsigned int pFlags) const
  359. {
  360. ASSIMP_BEGIN_EXCEPTION_REGION();
  361. // run basic checks for mutually exclusive flags
  362. if(!_ValidateFlags(pFlags)) {
  363. return false;
  364. }
  365. // ValidateDS does not anymore occur in the pp list, it plays an awesome extra role ...
  366. #ifdef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  367. if (pFlags & aiProcess_ValidateDataStructure) {
  368. return false;
  369. }
  370. #endif
  371. pFlags &= ~aiProcess_ValidateDataStructure;
  372. // Now iterate through all bits which are set in the flags and check whether we find at least
  373. // one pp plugin which handles it.
  374. for (unsigned int mask = 1; mask < (1u << (sizeof(unsigned int)*8-1));mask <<= 1) {
  375. if (pFlags & mask) {
  376. bool have = false;
  377. for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++) {
  378. if (pimpl->mPostProcessingSteps[a]-> IsActive(mask) ) {
  379. have = true;
  380. break;
  381. }
  382. }
  383. if (!have) {
  384. return false;
  385. }
  386. }
  387. }
  388. ASSIMP_END_EXCEPTION_REGION(bool);
  389. return true;
  390. }
  391. // ------------------------------------------------------------------------------------------------
  392. const aiScene* Importer::ReadFileFromMemory( const void* pBuffer,
  393. size_t pLength,
  394. unsigned int pFlags,
  395. const char* pHint /*= ""*/)
  396. {
  397. ASSIMP_BEGIN_EXCEPTION_REGION();
  398. if (!pHint) {
  399. pHint = "";
  400. }
  401. if (!pBuffer || !pLength || strlen(pHint) > MaxLenHint ) {
  402. pimpl->mErrorString = "Invalid parameters passed to ReadFileFromMemory()";
  403. return NULL;
  404. }
  405. // prevent deletion of the previous IOHandler
  406. IOSystem* io = pimpl->mIOHandler;
  407. pimpl->mIOHandler = NULL;
  408. SetIOHandler(new MemoryIOSystem((const uint8_t*)pBuffer,pLength,io));
  409. // read the file and recover the previous IOSystem
  410. static const size_t BufSize(Importer::MaxLenHint + 28);
  411. char fbuff[BufSize];
  412. ai_snprintf(fbuff, BufSize, "%s.%s",AI_MEMORYIO_MAGIC_FILENAME,pHint);
  413. ReadFile(fbuff,pFlags);
  414. SetIOHandler(io);
  415. ASSIMP_END_EXCEPTION_REGION(const aiScene*);
  416. return pimpl->mScene;
  417. }
  418. // ------------------------------------------------------------------------------------------------
  419. void WriteLogOpening(const std::string& file)
  420. {
  421. ASSIMP_LOG_INFO_F("Load ", file);
  422. // print a full version dump. This is nice because we don't
  423. // need to ask the authors of incoming bug reports for
  424. // the library version they're using - a log dump is
  425. // sufficient.
  426. const unsigned int flags( aiGetCompileFlags() );
  427. std::stringstream stream;
  428. stream << "Assimp " << aiGetVersionMajor() << "." << aiGetVersionMinor() << "." << aiGetVersionRevision() << " "
  429. #if defined(ASSIMP_BUILD_ARCHITECTURE)
  430. << ASSIMP_BUILD_ARCHITECTURE
  431. #elif defined(_M_IX86) || defined(__x86_32__) || defined(__i386__)
  432. << "x86"
  433. #elif defined(_M_X64) || defined(__x86_64__)
  434. << "amd64"
  435. #elif defined(_M_IA64) || defined(__ia64__)
  436. << "itanium"
  437. #elif defined(__ppc__) || defined(__powerpc__)
  438. << "ppc32"
  439. #elif defined(__powerpc64__)
  440. << "ppc64"
  441. #elif defined(__arm__)
  442. << "arm"
  443. #else
  444. << "<unknown architecture>"
  445. #endif
  446. << " "
  447. #if defined(ASSIMP_BUILD_COMPILER)
  448. << ( ASSIMP_BUILD_COMPILER )
  449. #elif defined(_MSC_VER)
  450. << "msvc"
  451. #elif defined(__GNUC__)
  452. << "gcc"
  453. #else
  454. << "<unknown compiler>"
  455. #endif
  456. #ifdef ASSIMP_BUILD_DEBUG
  457. << " debug"
  458. #endif
  459. << (flags & ASSIMP_CFLAGS_NOBOOST ? " noboost" : "")
  460. << (flags & ASSIMP_CFLAGS_SHARED ? " shared" : "")
  461. << (flags & ASSIMP_CFLAGS_SINGLETHREADED ? " singlethreaded" : "");
  462. ASSIMP_LOG_DEBUG(stream.str());
  463. }
  464. // ------------------------------------------------------------------------------------------------
  465. // Reads the given file and returns its contents if successful.
  466. const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
  467. {
  468. ASSIMP_BEGIN_EXCEPTION_REGION();
  469. const std::string pFile(_pFile);
  470. // ----------------------------------------------------------------------
  471. // Put a large try block around everything to catch all std::exception's
  472. // that might be thrown by STL containers or by new().
  473. // ImportErrorException's are throw by ourselves and caught elsewhere.
  474. //-----------------------------------------------------------------------
  475. WriteLogOpening(pFile);
  476. #ifdef ASSIMP_CATCH_GLOBAL_EXCEPTIONS
  477. try
  478. #endif // ! ASSIMP_CATCH_GLOBAL_EXCEPTIONS
  479. {
  480. // Check whether this Importer instance has already loaded
  481. // a scene. In this case we need to delete the old one
  482. if (pimpl->mScene) {
  483. ASSIMP_LOG_DEBUG("(Deleting previous scene)");
  484. FreeScene();
  485. }
  486. // First check if the file is accessible at all
  487. if( !pimpl->mIOHandler->Exists( pFile)) {
  488. pimpl->mErrorString = "Unable to open file \"" + pFile + "\".";
  489. ASSIMP_LOG_ERROR(pimpl->mErrorString);
  490. return NULL;
  491. }
  492. std::unique_ptr<Profiler> profiler(GetPropertyInteger(AI_CONFIG_GLOB_MEASURE_TIME,0)?new Profiler():NULL);
  493. if (profiler) {
  494. profiler->BeginRegion("total");
  495. }
  496. // Find an worker class which can handle the file
  497. BaseImporter* imp = NULL;
  498. SetPropertyInteger("importerIndex", -1);
  499. for( unsigned int a = 0; a < pimpl->mImporter.size(); a++) {
  500. if( pimpl->mImporter[a]->CanRead( pFile, pimpl->mIOHandler, false)) {
  501. imp = pimpl->mImporter[a];
  502. SetPropertyInteger("importerIndex", a);
  503. break;
  504. }
  505. }
  506. if (!imp) {
  507. // not so bad yet ... try format auto detection.
  508. const std::string::size_type s = pFile.find_last_of('.');
  509. if (s != std::string::npos) {
  510. ASSIMP_LOG_INFO("File extension not known, trying signature-based detection");
  511. for( unsigned int a = 0; a < pimpl->mImporter.size(); a++) {
  512. if( pimpl->mImporter[a]->CanRead( pFile, pimpl->mIOHandler, true)) {
  513. imp = pimpl->mImporter[a];
  514. SetPropertyInteger("importerIndex", a);
  515. break;
  516. }
  517. }
  518. }
  519. // Put a proper error message if no suitable importer was found
  520. if( !imp) {
  521. pimpl->mErrorString = "No suitable reader found for the file format of file \"" + pFile + "\".";
  522. ASSIMP_LOG_ERROR(pimpl->mErrorString);
  523. return NULL;
  524. }
  525. }
  526. // Get file size for progress handler
  527. IOStream * fileIO = pimpl->mIOHandler->Open( pFile );
  528. uint32_t fileSize = 0;
  529. if (fileIO)
  530. {
  531. fileSize = static_cast<uint32_t>(fileIO->FileSize());
  532. pimpl->mIOHandler->Close( fileIO );
  533. }
  534. // Dispatch the reading to the worker class for this format
  535. const aiImporterDesc *desc( imp->GetInfo() );
  536. std::string ext( "unknown" );
  537. if ( NULL != desc ) {
  538. ext = desc->mName;
  539. }
  540. ASSIMP_LOG_INFO("Found a matching importer for this file format: " + ext + "." );
  541. pimpl->mProgressHandler->UpdateFileRead( 0, fileSize );
  542. if (profiler) {
  543. profiler->BeginRegion("import");
  544. }
  545. pimpl->mScene = imp->ReadFile( this, pFile, pimpl->mIOHandler);
  546. pimpl->mProgressHandler->UpdateFileRead( fileSize, fileSize );
  547. if (profiler) {
  548. profiler->EndRegion("import");
  549. }
  550. SetPropertyString("sourceFilePath", pFile);
  551. // If successful, apply all active post processing steps to the imported data
  552. if( pimpl->mScene) {
  553. #ifndef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  554. // The ValidateDS process is an exception. It is executed first, even before ScenePreprocessor is called.
  555. if (pFlags & aiProcess_ValidateDataStructure)
  556. {
  557. ValidateDSProcess ds;
  558. ds.ExecuteOnScene (this);
  559. if (!pimpl->mScene) {
  560. return NULL;
  561. }
  562. }
  563. #endif // no validation
  564. // Preprocess the scene and prepare it for post-processing
  565. if (profiler) {
  566. profiler->BeginRegion("preprocess");
  567. }
  568. ScenePreprocessor pre(pimpl->mScene);
  569. pre.ProcessScene();
  570. if (profiler) {
  571. profiler->EndRegion("preprocess");
  572. }
  573. // Ensure that the validation process won't be called twice
  574. ApplyPostProcessing(pFlags & (~aiProcess_ValidateDataStructure));
  575. }
  576. // if failed, extract the error string
  577. else if( !pimpl->mScene) {
  578. pimpl->mErrorString = imp->GetErrorText();
  579. }
  580. // clear any data allocated by post-process steps
  581. pimpl->mPPShared->Clean();
  582. if (profiler) {
  583. profiler->EndRegion("total");
  584. }
  585. }
  586. #ifdef ASSIMP_CATCH_GLOBAL_EXCEPTIONS
  587. catch (std::exception &e)
  588. {
  589. #if (defined _MSC_VER) && (defined _CPPRTTI)
  590. // if we have RTTI get the full name of the exception that occurred
  591. pimpl->mErrorString = std::string(typeid( e ).name()) + ": " + e.what();
  592. #else
  593. pimpl->mErrorString = std::string("std::exception: ") + e.what();
  594. #endif
  595. ASSIMP_LOG_ERROR(pimpl->mErrorString);
  596. delete pimpl->mScene; pimpl->mScene = NULL;
  597. }
  598. #endif // ! ASSIMP_CATCH_GLOBAL_EXCEPTIONS
  599. // either successful or failure - the pointer expresses it anyways
  600. ASSIMP_END_EXCEPTION_REGION(const aiScene*);
  601. return pimpl->mScene;
  602. }
  603. // ------------------------------------------------------------------------------------------------
  604. // Apply post-processing to the currently bound scene
  605. const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags)
  606. {
  607. ASSIMP_BEGIN_EXCEPTION_REGION();
  608. // Return immediately if no scene is active
  609. if (!pimpl->mScene) {
  610. return NULL;
  611. }
  612. // If no flags are given, return the current scene with no further action
  613. if (!pFlags) {
  614. return pimpl->mScene;
  615. }
  616. // In debug builds: run basic flag validation
  617. ai_assert(_ValidateFlags(pFlags));
  618. ASSIMP_LOG_INFO("Entering post processing pipeline");
  619. #ifndef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  620. // The ValidateDS process plays an exceptional role. It isn't contained in the global
  621. // list of post-processing steps, so we need to call it manually.
  622. if (pFlags & aiProcess_ValidateDataStructure)
  623. {
  624. ValidateDSProcess ds;
  625. ds.ExecuteOnScene (this);
  626. if (!pimpl->mScene) {
  627. return NULL;
  628. }
  629. }
  630. #endif // no validation
  631. #ifdef ASSIMP_BUILD_DEBUG
  632. if (pimpl->bExtraVerbose)
  633. {
  634. #ifdef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  635. ASSIMP_LOG_ERROR("Verbose Import is not available due to build settings");
  636. #endif // no validation
  637. pFlags |= aiProcess_ValidateDataStructure;
  638. }
  639. #else
  640. if (pimpl->bExtraVerbose) {
  641. ASSIMP_LOG_WARN("Not a debug build, ignoring extra verbose setting");
  642. }
  643. #endif // ! DEBUG
  644. std::unique_ptr<Profiler> profiler(GetPropertyInteger(AI_CONFIG_GLOB_MEASURE_TIME,0)?new Profiler():NULL);
  645. for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++) {
  646. BaseProcess* process = pimpl->mPostProcessingSteps[a];
  647. pimpl->mProgressHandler->UpdatePostProcess(static_cast<int>(a), static_cast<int>(pimpl->mPostProcessingSteps.size()) );
  648. if( process->IsActive( pFlags)) {
  649. if (profiler) {
  650. profiler->BeginRegion("postprocess");
  651. }
  652. process->ExecuteOnScene ( this );
  653. if (profiler) {
  654. profiler->EndRegion("postprocess");
  655. }
  656. }
  657. if( !pimpl->mScene) {
  658. break;
  659. }
  660. #ifdef ASSIMP_BUILD_DEBUG
  661. #ifdef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  662. continue;
  663. #endif // no validation
  664. // If the extra verbose mode is active, execute the ValidateDataStructureStep again - after each step
  665. if (pimpl->bExtraVerbose) {
  666. ASSIMP_LOG_DEBUG("Verbose Import: re-validating data structures");
  667. ValidateDSProcess ds;
  668. ds.ExecuteOnScene (this);
  669. if( !pimpl->mScene) {
  670. ASSIMP_LOG_ERROR("Verbose Import: failed to re-validate data structures");
  671. break;
  672. }
  673. }
  674. #endif // ! DEBUG
  675. }
  676. pimpl->mProgressHandler->UpdatePostProcess( static_cast<int>(pimpl->mPostProcessingSteps.size()),
  677. static_cast<int>(pimpl->mPostProcessingSteps.size()) );
  678. // update private scene flags
  679. if( pimpl->mScene )
  680. ScenePriv(pimpl->mScene)->mPPStepsApplied |= pFlags;
  681. // clear any data allocated by post-process steps
  682. pimpl->mPPShared->Clean();
  683. ASSIMP_LOG_INFO("Leaving post processing pipeline");
  684. ASSIMP_END_EXCEPTION_REGION(const aiScene*);
  685. return pimpl->mScene;
  686. }
  687. // ------------------------------------------------------------------------------------------------
  688. const aiScene* Importer::ApplyCustomizedPostProcessing( BaseProcess *rootProcess, bool requestValidation ) {
  689. ASSIMP_BEGIN_EXCEPTION_REGION();
  690. // Return immediately if no scene is active
  691. if ( NULL == pimpl->mScene ) {
  692. return NULL;
  693. }
  694. // If no flags are given, return the current scene with no further action
  695. if ( NULL == rootProcess ) {
  696. return pimpl->mScene;
  697. }
  698. // In debug builds: run basic flag validation
  699. ASSIMP_LOG_INFO( "Entering customized post processing pipeline" );
  700. #ifndef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  701. // The ValidateDS process plays an exceptional role. It isn't contained in the global
  702. // list of post-processing steps, so we need to call it manually.
  703. if ( requestValidation )
  704. {
  705. ValidateDSProcess ds;
  706. ds.ExecuteOnScene( this );
  707. if ( !pimpl->mScene ) {
  708. return NULL;
  709. }
  710. }
  711. #endif // no validation
  712. #ifdef ASSIMP_BUILD_DEBUG
  713. if ( pimpl->bExtraVerbose )
  714. {
  715. #ifdef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  716. ASSIMP_LOG_ERROR( "Verbose Import is not available due to build settings" );
  717. #endif // no validation
  718. }
  719. #else
  720. if ( pimpl->bExtraVerbose ) {
  721. ASSIMP_LOG_WARN( "Not a debug build, ignoring extra verbose setting" );
  722. }
  723. #endif // ! DEBUG
  724. std::unique_ptr<Profiler> profiler( GetPropertyInteger( AI_CONFIG_GLOB_MEASURE_TIME, 0 ) ? new Profiler() : NULL );
  725. if ( profiler ) {
  726. profiler->BeginRegion( "postprocess" );
  727. }
  728. rootProcess->ExecuteOnScene( this );
  729. if ( profiler ) {
  730. profiler->EndRegion( "postprocess" );
  731. }
  732. // If the extra verbose mode is active, execute the ValidateDataStructureStep again - after each step
  733. if ( pimpl->bExtraVerbose || requestValidation ) {
  734. ASSIMP_LOG_DEBUG( "Verbose Import: revalidating data structures" );
  735. ValidateDSProcess ds;
  736. ds.ExecuteOnScene( this );
  737. if ( !pimpl->mScene ) {
  738. ASSIMP_LOG_ERROR( "Verbose Import: failed to revalidate data structures" );
  739. }
  740. }
  741. // clear any data allocated by post-process steps
  742. pimpl->mPPShared->Clean();
  743. ASSIMP_LOG_INFO( "Leaving customized post processing pipeline" );
  744. ASSIMP_END_EXCEPTION_REGION( const aiScene* );
  745. return pimpl->mScene;
  746. }
  747. // ------------------------------------------------------------------------------------------------
  748. // Helper function to check whether an extension is supported by ASSIMP
  749. bool Importer::IsExtensionSupported(const char* szExtension) const
  750. {
  751. return nullptr != GetImporter(szExtension);
  752. }
  753. // ------------------------------------------------------------------------------------------------
  754. size_t Importer::GetImporterCount() const
  755. {
  756. return pimpl->mImporter.size();
  757. }
  758. // ------------------------------------------------------------------------------------------------
  759. const aiImporterDesc* Importer::GetImporterInfo(size_t index) const
  760. {
  761. if (index >= pimpl->mImporter.size()) {
  762. return NULL;
  763. }
  764. return pimpl->mImporter[index]->GetInfo();
  765. }
  766. // ------------------------------------------------------------------------------------------------
  767. BaseImporter* Importer::GetImporter (size_t index) const
  768. {
  769. if (index >= pimpl->mImporter.size()) {
  770. return NULL;
  771. }
  772. return pimpl->mImporter[index];
  773. }
  774. // ------------------------------------------------------------------------------------------------
  775. // Find a loader plugin for a given file extension
  776. BaseImporter* Importer::GetImporter (const char* szExtension) const
  777. {
  778. return GetImporter(GetImporterIndex(szExtension));
  779. }
  780. // ------------------------------------------------------------------------------------------------
  781. // Find a loader plugin for a given file extension
  782. size_t Importer::GetImporterIndex (const char* szExtension) const {
  783. ai_assert(nullptr != szExtension);
  784. ASSIMP_BEGIN_EXCEPTION_REGION();
  785. // skip over wildcard and dot characters at string head --
  786. for ( ; *szExtension == '*' || *szExtension == '.'; ++szExtension );
  787. std::string ext(szExtension);
  788. if (ext.empty()) {
  789. return static_cast<size_t>(-1);
  790. }
  791. std::transform( ext.begin(), ext.end(), ext.begin(), ToLower<char> );
  792. std::set<std::string> str;
  793. for (std::vector<BaseImporter*>::const_iterator i = pimpl->mImporter.begin();i != pimpl->mImporter.end();++i) {
  794. str.clear();
  795. (*i)->GetExtensionList(str);
  796. for (std::set<std::string>::const_iterator it = str.begin(); it != str.end(); ++it) {
  797. if (ext == *it) {
  798. return std::distance(static_cast< std::vector<BaseImporter*>::const_iterator >(pimpl->mImporter.begin()), i);
  799. }
  800. }
  801. }
  802. ASSIMP_END_EXCEPTION_REGION(size_t);
  803. return static_cast<size_t>(-1);
  804. }
  805. // ------------------------------------------------------------------------------------------------
  806. // Helper function to build a list of all file extensions supported by ASSIMP
  807. void Importer::GetExtensionList(aiString& szOut) const
  808. {
  809. ASSIMP_BEGIN_EXCEPTION_REGION();
  810. std::set<std::string> str;
  811. for (std::vector<BaseImporter*>::const_iterator i = pimpl->mImporter.begin();i != pimpl->mImporter.end();++i) {
  812. (*i)->GetExtensionList(str);
  813. }
  814. // List can be empty
  815. if( !str.empty() ) {
  816. for (std::set<std::string>::const_iterator it = str.begin();; ) {
  817. szOut.Append("*.");
  818. szOut.Append((*it).c_str());
  819. if (++it == str.end()) {
  820. break;
  821. }
  822. szOut.Append(";");
  823. }
  824. }
  825. ASSIMP_END_EXCEPTION_REGION(void);
  826. }
  827. // ------------------------------------------------------------------------------------------------
  828. // Set a configuration property
  829. bool Importer::SetPropertyInteger(const char* szName, int iValue)
  830. {
  831. bool existing;
  832. ASSIMP_BEGIN_EXCEPTION_REGION();
  833. existing = SetGenericProperty<int>(pimpl->mIntProperties, szName,iValue);
  834. ASSIMP_END_EXCEPTION_REGION(bool);
  835. return existing;
  836. }
  837. // ------------------------------------------------------------------------------------------------
  838. // Set a configuration property
  839. bool Importer::SetPropertyFloat(const char* szName, ai_real iValue)
  840. {
  841. bool existing;
  842. ASSIMP_BEGIN_EXCEPTION_REGION();
  843. existing = SetGenericProperty<ai_real>(pimpl->mFloatProperties, szName,iValue);
  844. ASSIMP_END_EXCEPTION_REGION(bool);
  845. return existing;
  846. }
  847. // ------------------------------------------------------------------------------------------------
  848. // Set a configuration property
  849. bool Importer::SetPropertyString(const char* szName, const std::string& value)
  850. {
  851. bool existing;
  852. ASSIMP_BEGIN_EXCEPTION_REGION();
  853. existing = SetGenericProperty<std::string>(pimpl->mStringProperties, szName,value);
  854. ASSIMP_END_EXCEPTION_REGION(bool);
  855. return existing;
  856. }
  857. // ------------------------------------------------------------------------------------------------
  858. // Set a configuration property
  859. bool Importer::SetPropertyMatrix(const char* szName, const aiMatrix4x4& value)
  860. {
  861. bool existing;
  862. ASSIMP_BEGIN_EXCEPTION_REGION();
  863. existing = SetGenericProperty<aiMatrix4x4>(pimpl->mMatrixProperties, szName,value);
  864. ASSIMP_END_EXCEPTION_REGION(bool);
  865. return existing;
  866. }
  867. // ------------------------------------------------------------------------------------------------
  868. // Get a configuration property
  869. int Importer::GetPropertyInteger(const char* szName,
  870. int iErrorReturn /*= 0xffffffff*/) const
  871. {
  872. return GetGenericProperty<int>(pimpl->mIntProperties,szName,iErrorReturn);
  873. }
  874. // ------------------------------------------------------------------------------------------------
  875. // Get a configuration property
  876. ai_real Importer::GetPropertyFloat(const char* szName,
  877. ai_real iErrorReturn /*= 10e10*/) const
  878. {
  879. return GetGenericProperty<ai_real>(pimpl->mFloatProperties,szName,iErrorReturn);
  880. }
  881. // ------------------------------------------------------------------------------------------------
  882. // Get a configuration property
  883. const std::string Importer::GetPropertyString(const char* szName,
  884. const std::string& iErrorReturn /*= ""*/) const
  885. {
  886. return GetGenericProperty<std::string>(pimpl->mStringProperties,szName,iErrorReturn);
  887. }
  888. // ------------------------------------------------------------------------------------------------
  889. // Get a configuration property
  890. const aiMatrix4x4 Importer::GetPropertyMatrix(const char* szName,
  891. const aiMatrix4x4& iErrorReturn /*= aiMatrix4x4()*/) const
  892. {
  893. return GetGenericProperty<aiMatrix4x4>(pimpl->mMatrixProperties,szName,iErrorReturn);
  894. }
  895. // ------------------------------------------------------------------------------------------------
  896. // Get the memory requirements of a single node
  897. inline void AddNodeWeight(unsigned int& iScene,const aiNode* pcNode)
  898. {
  899. iScene += sizeof(aiNode);
  900. iScene += sizeof(unsigned int) * pcNode->mNumMeshes;
  901. iScene += sizeof(void*) * pcNode->mNumChildren;
  902. for (unsigned int i = 0; i < pcNode->mNumChildren;++i) {
  903. AddNodeWeight(iScene,pcNode->mChildren[i]);
  904. }
  905. }
  906. // ------------------------------------------------------------------------------------------------
  907. // Get the memory requirements of the scene
  908. void Importer::GetMemoryRequirements(aiMemoryInfo& in) const
  909. {
  910. in = aiMemoryInfo();
  911. aiScene* mScene = pimpl->mScene;
  912. // return if we have no scene loaded
  913. if (!pimpl->mScene)
  914. return;
  915. in.total = sizeof(aiScene);
  916. // add all meshes
  917. for (unsigned int i = 0; i < mScene->mNumMeshes;++i)
  918. {
  919. in.meshes += sizeof(aiMesh);
  920. if (mScene->mMeshes[i]->HasPositions()) {
  921. in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices;
  922. }
  923. if (mScene->mMeshes[i]->HasNormals()) {
  924. in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices;
  925. }
  926. if (mScene->mMeshes[i]->HasTangentsAndBitangents()) {
  927. in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices * 2;
  928. }
  929. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS;++a) {
  930. if (mScene->mMeshes[i]->HasVertexColors(a)) {
  931. in.meshes += sizeof(aiColor4D) * mScene->mMeshes[i]->mNumVertices;
  932. }
  933. else break;
  934. }
  935. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS;++a) {
  936. if (mScene->mMeshes[i]->HasTextureCoords(a)) {
  937. in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices;
  938. }
  939. else break;
  940. }
  941. if (mScene->mMeshes[i]->HasBones()) {
  942. in.meshes += sizeof(void*) * mScene->mMeshes[i]->mNumBones;
  943. for (unsigned int p = 0; p < mScene->mMeshes[i]->mNumBones;++p) {
  944. in.meshes += sizeof(aiBone);
  945. in.meshes += mScene->mMeshes[i]->mBones[p]->mNumWeights * sizeof(aiVertexWeight);
  946. }
  947. }
  948. in.meshes += (sizeof(aiFace) + 3 * sizeof(unsigned int))*mScene->mMeshes[i]->mNumFaces;
  949. }
  950. in.total += in.meshes;
  951. // add all embedded textures
  952. for (unsigned int i = 0; i < mScene->mNumTextures;++i) {
  953. const aiTexture* pc = mScene->mTextures[i];
  954. in.textures += sizeof(aiTexture);
  955. if (pc->mHeight) {
  956. in.textures += 4 * pc->mHeight * pc->mWidth;
  957. }
  958. else in.textures += pc->mWidth;
  959. }
  960. in.total += in.textures;
  961. // add all animations
  962. for (unsigned int i = 0; i < mScene->mNumAnimations;++i) {
  963. const aiAnimation* pc = mScene->mAnimations[i];
  964. in.animations += sizeof(aiAnimation);
  965. // add all bone anims
  966. for (unsigned int a = 0; a < pc->mNumChannels; ++a) {
  967. const aiNodeAnim* pc2 = pc->mChannels[i];
  968. in.animations += sizeof(aiNodeAnim);
  969. in.animations += pc2->mNumPositionKeys * sizeof(aiVectorKey);
  970. in.animations += pc2->mNumScalingKeys * sizeof(aiVectorKey);
  971. in.animations += pc2->mNumRotationKeys * sizeof(aiQuatKey);
  972. }
  973. }
  974. in.total += in.animations;
  975. // add all cameras and all lights
  976. in.total += in.cameras = sizeof(aiCamera) * mScene->mNumCameras;
  977. in.total += in.lights = sizeof(aiLight) * mScene->mNumLights;
  978. // add all nodes
  979. AddNodeWeight(in.nodes,mScene->mRootNode);
  980. in.total += in.nodes;
  981. // add all materials
  982. for (unsigned int i = 0; i < mScene->mNumMaterials;++i) {
  983. const aiMaterial* pc = mScene->mMaterials[i];
  984. in.materials += sizeof(aiMaterial);
  985. in.materials += pc->mNumAllocated * sizeof(void*);
  986. for (unsigned int a = 0; a < pc->mNumProperties;++a) {
  987. in.materials += pc->mProperties[a]->mDataLength;
  988. }
  989. }
  990. in.total += in.materials;
  991. }