Importer.cpp 40 KB

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