Importer.cpp 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  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 "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. // 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. for( unsigned int a = 0; a < pimpl->mImporter.size(); a++) {
  499. if( pimpl->mImporter[a]->CanRead( pFile, pimpl->mIOHandler, false)) {
  500. imp = pimpl->mImporter[a];
  501. break;
  502. }
  503. }
  504. if (!imp) {
  505. // not so bad yet ... try format auto detection.
  506. const std::string::size_type s = pFile.find_last_of('.');
  507. if (s != std::string::npos) {
  508. ASSIMP_LOG_INFO("File extension not known, trying signature-based detection");
  509. for( unsigned int a = 0; a < pimpl->mImporter.size(); a++) {
  510. if( pimpl->mImporter[a]->CanRead( pFile, pimpl->mIOHandler, true)) {
  511. imp = pimpl->mImporter[a];
  512. break;
  513. }
  514. }
  515. }
  516. // Put a proper error message if no suitable importer was found
  517. if( !imp) {
  518. pimpl->mErrorString = "No suitable reader found for the file format of file \"" + pFile + "\".";
  519. ASSIMP_LOG_ERROR(pimpl->mErrorString);
  520. return NULL;
  521. }
  522. }
  523. // Get file size for progress handler
  524. IOStream * fileIO = pimpl->mIOHandler->Open( pFile );
  525. uint32_t fileSize = 0;
  526. if (fileIO)
  527. {
  528. fileSize = static_cast<uint32_t>(fileIO->FileSize());
  529. pimpl->mIOHandler->Close( fileIO );
  530. }
  531. // Dispatch the reading to the worker class for this format
  532. const aiImporterDesc *desc( imp->GetInfo() );
  533. std::string ext( "unknown" );
  534. if ( NULL != desc ) {
  535. ext = desc->mName;
  536. }
  537. ASSIMP_LOG_INFO("Found a matching importer for this file format: " + ext + "." );
  538. pimpl->mProgressHandler->UpdateFileRead( 0, fileSize );
  539. if (profiler) {
  540. profiler->BeginRegion("import");
  541. }
  542. pimpl->mScene = imp->ReadFile( this, pFile, pimpl->mIOHandler);
  543. pimpl->mProgressHandler->UpdateFileRead( fileSize, fileSize );
  544. if (profiler) {
  545. profiler->EndRegion("import");
  546. }
  547. SetPropertyString("sourceFilePath", pFile);
  548. // If successful, apply all active post processing steps to the imported data
  549. if( pimpl->mScene) {
  550. #ifndef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  551. // The ValidateDS process is an exception. It is executed first, even before ScenePreprocessor is called.
  552. if (pFlags & aiProcess_ValidateDataStructure)
  553. {
  554. ValidateDSProcess ds;
  555. ds.ExecuteOnScene (this);
  556. if (!pimpl->mScene) {
  557. return NULL;
  558. }
  559. }
  560. #endif // no validation
  561. // Preprocess the scene and prepare it for post-processing
  562. if (profiler) {
  563. profiler->BeginRegion("preprocess");
  564. }
  565. ScenePreprocessor pre(pimpl->mScene);
  566. pre.ProcessScene();
  567. if (profiler) {
  568. profiler->EndRegion("preprocess");
  569. }
  570. // Ensure that the validation process won't be called twice
  571. ApplyPostProcessing(pFlags & (~aiProcess_ValidateDataStructure));
  572. }
  573. // if failed, extract the error string
  574. else if( !pimpl->mScene) {
  575. pimpl->mErrorString = imp->GetErrorText();
  576. }
  577. // clear any data allocated by post-process steps
  578. pimpl->mPPShared->Clean();
  579. if (profiler) {
  580. profiler->EndRegion("total");
  581. }
  582. }
  583. #ifdef ASSIMP_CATCH_GLOBAL_EXCEPTIONS
  584. catch (std::exception &e)
  585. {
  586. #if (defined _MSC_VER) && (defined _CPPRTTI)
  587. // if we have RTTI get the full name of the exception that occurred
  588. pimpl->mErrorString = std::string(typeid( e ).name()) + ": " + e.what();
  589. #else
  590. pimpl->mErrorString = std::string("std::exception: ") + e.what();
  591. #endif
  592. ASSIMP_LOG_ERROR(pimpl->mErrorString);
  593. delete pimpl->mScene; pimpl->mScene = NULL;
  594. }
  595. #endif // ! ASSIMP_CATCH_GLOBAL_EXCEPTIONS
  596. // either successful or failure - the pointer expresses it anyways
  597. ASSIMP_END_EXCEPTION_REGION(const aiScene*);
  598. return pimpl->mScene;
  599. }
  600. // ------------------------------------------------------------------------------------------------
  601. // Apply post-processing to the currently bound scene
  602. const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags)
  603. {
  604. ASSIMP_BEGIN_EXCEPTION_REGION();
  605. // Return immediately if no scene is active
  606. if (!pimpl->mScene) {
  607. return NULL;
  608. }
  609. // If no flags are given, return the current scene with no further action
  610. if (!pFlags) {
  611. return pimpl->mScene;
  612. }
  613. // In debug builds: run basic flag validation
  614. ai_assert(_ValidateFlags(pFlags));
  615. ASSIMP_LOG_INFO("Entering post processing pipeline");
  616. #ifndef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  617. // The ValidateDS process plays an exceptional role. It isn't contained in the global
  618. // list of post-processing steps, so we need to call it manually.
  619. if (pFlags & aiProcess_ValidateDataStructure)
  620. {
  621. ValidateDSProcess ds;
  622. ds.ExecuteOnScene (this);
  623. if (!pimpl->mScene) {
  624. return NULL;
  625. }
  626. }
  627. #endif // no validation
  628. #ifdef ASSIMP_BUILD_DEBUG
  629. if (pimpl->bExtraVerbose)
  630. {
  631. #ifdef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  632. ASSIMP_LOG_ERROR("Verbose Import is not available due to build settings");
  633. #endif // no validation
  634. pFlags |= aiProcess_ValidateDataStructure;
  635. }
  636. #else
  637. if (pimpl->bExtraVerbose) {
  638. ASSIMP_LOG_WARN("Not a debug build, ignoring extra verbose setting");
  639. }
  640. #endif // ! DEBUG
  641. std::unique_ptr<Profiler> profiler(GetPropertyInteger(AI_CONFIG_GLOB_MEASURE_TIME,0)?new Profiler():NULL);
  642. for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++) {
  643. BaseProcess* process = pimpl->mPostProcessingSteps[a];
  644. pimpl->mProgressHandler->UpdatePostProcess(static_cast<int>(a), static_cast<int>(pimpl->mPostProcessingSteps.size()) );
  645. if( process->IsActive( pFlags)) {
  646. if (profiler) {
  647. profiler->BeginRegion("postprocess");
  648. }
  649. process->ExecuteOnScene ( this );
  650. if (profiler) {
  651. profiler->EndRegion("postprocess");
  652. }
  653. }
  654. if( !pimpl->mScene) {
  655. break;
  656. }
  657. #ifdef ASSIMP_BUILD_DEBUG
  658. #ifdef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  659. continue;
  660. #endif // no validation
  661. // If the extra verbose mode is active, execute the ValidateDataStructureStep again - after each step
  662. if (pimpl->bExtraVerbose) {
  663. ASSIMP_LOG_DEBUG("Verbose Import: re-validating data structures");
  664. ValidateDSProcess ds;
  665. ds.ExecuteOnScene (this);
  666. if( !pimpl->mScene) {
  667. ASSIMP_LOG_ERROR("Verbose Import: failed to re-validate data structures");
  668. break;
  669. }
  670. }
  671. #endif // ! DEBUG
  672. }
  673. pimpl->mProgressHandler->UpdatePostProcess( static_cast<int>(pimpl->mPostProcessingSteps.size()),
  674. static_cast<int>(pimpl->mPostProcessingSteps.size()) );
  675. // update private scene flags
  676. if( pimpl->mScene )
  677. ScenePriv(pimpl->mScene)->mPPStepsApplied |= pFlags;
  678. // clear any data allocated by post-process steps
  679. pimpl->mPPShared->Clean();
  680. ASSIMP_LOG_INFO("Leaving post processing pipeline");
  681. ASSIMP_END_EXCEPTION_REGION(const aiScene*);
  682. return pimpl->mScene;
  683. }
  684. // ------------------------------------------------------------------------------------------------
  685. const aiScene* Importer::ApplyCustomizedPostProcessing( BaseProcess *rootProcess, bool requestValidation ) {
  686. ASSIMP_BEGIN_EXCEPTION_REGION();
  687. // Return immediately if no scene is active
  688. if ( NULL == pimpl->mScene ) {
  689. return NULL;
  690. }
  691. // If no flags are given, return the current scene with no further action
  692. if ( NULL == rootProcess ) {
  693. return pimpl->mScene;
  694. }
  695. // In debug builds: run basic flag validation
  696. ASSIMP_LOG_INFO( "Entering customized post processing pipeline" );
  697. #ifndef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  698. // The ValidateDS process plays an exceptional role. It isn't contained in the global
  699. // list of post-processing steps, so we need to call it manually.
  700. if ( requestValidation )
  701. {
  702. ValidateDSProcess ds;
  703. ds.ExecuteOnScene( this );
  704. if ( !pimpl->mScene ) {
  705. return NULL;
  706. }
  707. }
  708. #endif // no validation
  709. #ifdef ASSIMP_BUILD_DEBUG
  710. if ( pimpl->bExtraVerbose )
  711. {
  712. #ifdef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  713. ASSIMP_LOG_ERROR( "Verbose Import is not available due to build settings" );
  714. #endif // no validation
  715. }
  716. #else
  717. if ( pimpl->bExtraVerbose ) {
  718. ASSIMP_LOG_WARN( "Not a debug build, ignoring extra verbose setting" );
  719. }
  720. #endif // ! DEBUG
  721. std::unique_ptr<Profiler> profiler( GetPropertyInteger( AI_CONFIG_GLOB_MEASURE_TIME, 0 ) ? new Profiler() : NULL );
  722. if ( profiler ) {
  723. profiler->BeginRegion( "postprocess" );
  724. }
  725. rootProcess->ExecuteOnScene( this );
  726. if ( profiler ) {
  727. profiler->EndRegion( "postprocess" );
  728. }
  729. // If the extra verbose mode is active, execute the ValidateDataStructureStep again - after each step
  730. if ( pimpl->bExtraVerbose || requestValidation ) {
  731. ASSIMP_LOG_DEBUG( "Verbose Import: revalidating data structures" );
  732. ValidateDSProcess ds;
  733. ds.ExecuteOnScene( this );
  734. if ( !pimpl->mScene ) {
  735. ASSIMP_LOG_ERROR( "Verbose Import: failed to revalidate data structures" );
  736. }
  737. }
  738. // clear any data allocated by post-process steps
  739. pimpl->mPPShared->Clean();
  740. ASSIMP_LOG_INFO( "Leaving customized post processing pipeline" );
  741. ASSIMP_END_EXCEPTION_REGION( const aiScene* );
  742. return pimpl->mScene;
  743. }
  744. // ------------------------------------------------------------------------------------------------
  745. // Helper function to check whether an extension is supported by ASSIMP
  746. bool Importer::IsExtensionSupported(const char* szExtension) const
  747. {
  748. return nullptr != GetImporter(szExtension);
  749. }
  750. // ------------------------------------------------------------------------------------------------
  751. size_t Importer::GetImporterCount() const
  752. {
  753. return pimpl->mImporter.size();
  754. }
  755. // ------------------------------------------------------------------------------------------------
  756. const aiImporterDesc* Importer::GetImporterInfo(size_t index) const
  757. {
  758. if (index >= pimpl->mImporter.size()) {
  759. return NULL;
  760. }
  761. return pimpl->mImporter[index]->GetInfo();
  762. }
  763. // ------------------------------------------------------------------------------------------------
  764. BaseImporter* Importer::GetImporter (size_t index) const
  765. {
  766. if (index >= pimpl->mImporter.size()) {
  767. return NULL;
  768. }
  769. return pimpl->mImporter[index];
  770. }
  771. // ------------------------------------------------------------------------------------------------
  772. // Find a loader plugin for a given file extension
  773. BaseImporter* Importer::GetImporter (const char* szExtension) const
  774. {
  775. return GetImporter(GetImporterIndex(szExtension));
  776. }
  777. // ------------------------------------------------------------------------------------------------
  778. // Find a loader plugin for a given file extension
  779. size_t Importer::GetImporterIndex (const char* szExtension) const {
  780. ai_assert(nullptr != szExtension);
  781. ASSIMP_BEGIN_EXCEPTION_REGION();
  782. // skip over wildcard and dot characters at string head --
  783. for ( ; *szExtension == '*' || *szExtension == '.'; ++szExtension );
  784. std::string ext(szExtension);
  785. if (ext.empty()) {
  786. return static_cast<size_t>(-1);
  787. }
  788. std::transform( ext.begin(), ext.end(), ext.begin(), ToLower<char> );
  789. std::set<std::string> str;
  790. for (std::vector<BaseImporter*>::const_iterator i = pimpl->mImporter.begin();i != pimpl->mImporter.end();++i) {
  791. str.clear();
  792. (*i)->GetExtensionList(str);
  793. for (std::set<std::string>::const_iterator it = str.begin(); it != str.end(); ++it) {
  794. if (ext == *it) {
  795. return std::distance(static_cast< std::vector<BaseImporter*>::const_iterator >(pimpl->mImporter.begin()), i);
  796. }
  797. }
  798. }
  799. ASSIMP_END_EXCEPTION_REGION(size_t);
  800. return static_cast<size_t>(-1);
  801. }
  802. // ------------------------------------------------------------------------------------------------
  803. // Helper function to build a list of all file extensions supported by ASSIMP
  804. void Importer::GetExtensionList(aiString& szOut) const
  805. {
  806. ASSIMP_BEGIN_EXCEPTION_REGION();
  807. std::set<std::string> str;
  808. for (std::vector<BaseImporter*>::const_iterator i = pimpl->mImporter.begin();i != pimpl->mImporter.end();++i) {
  809. (*i)->GetExtensionList(str);
  810. }
  811. // List can be empty
  812. if( !str.empty() ) {
  813. for (std::set<std::string>::const_iterator it = str.begin();; ) {
  814. szOut.Append("*.");
  815. szOut.Append((*it).c_str());
  816. if (++it == str.end()) {
  817. break;
  818. }
  819. szOut.Append(";");
  820. }
  821. }
  822. ASSIMP_END_EXCEPTION_REGION(void);
  823. }
  824. // ------------------------------------------------------------------------------------------------
  825. // Set a configuration property
  826. bool Importer::SetPropertyInteger(const char* szName, int iValue)
  827. {
  828. bool existing;
  829. ASSIMP_BEGIN_EXCEPTION_REGION();
  830. existing = SetGenericProperty<int>(pimpl->mIntProperties, szName,iValue);
  831. ASSIMP_END_EXCEPTION_REGION(bool);
  832. return existing;
  833. }
  834. // ------------------------------------------------------------------------------------------------
  835. // Set a configuration property
  836. bool Importer::SetPropertyFloat(const char* szName, ai_real iValue)
  837. {
  838. bool existing;
  839. ASSIMP_BEGIN_EXCEPTION_REGION();
  840. existing = SetGenericProperty<ai_real>(pimpl->mFloatProperties, szName,iValue);
  841. ASSIMP_END_EXCEPTION_REGION(bool);
  842. return existing;
  843. }
  844. // ------------------------------------------------------------------------------------------------
  845. // Set a configuration property
  846. bool Importer::SetPropertyString(const char* szName, const std::string& value)
  847. {
  848. bool existing;
  849. ASSIMP_BEGIN_EXCEPTION_REGION();
  850. existing = SetGenericProperty<std::string>(pimpl->mStringProperties, szName,value);
  851. ASSIMP_END_EXCEPTION_REGION(bool);
  852. return existing;
  853. }
  854. // ------------------------------------------------------------------------------------------------
  855. // Set a configuration property
  856. bool Importer::SetPropertyMatrix(const char* szName, const aiMatrix4x4& value)
  857. {
  858. bool existing;
  859. ASSIMP_BEGIN_EXCEPTION_REGION();
  860. existing = SetGenericProperty<aiMatrix4x4>(pimpl->mMatrixProperties, szName,value);
  861. ASSIMP_END_EXCEPTION_REGION(bool);
  862. return existing;
  863. }
  864. // ------------------------------------------------------------------------------------------------
  865. // Get a configuration property
  866. int Importer::GetPropertyInteger(const char* szName,
  867. int iErrorReturn /*= 0xffffffff*/) const
  868. {
  869. return GetGenericProperty<int>(pimpl->mIntProperties,szName,iErrorReturn);
  870. }
  871. // ------------------------------------------------------------------------------------------------
  872. // Get a configuration property
  873. ai_real Importer::GetPropertyFloat(const char* szName,
  874. ai_real iErrorReturn /*= 10e10*/) const
  875. {
  876. return GetGenericProperty<ai_real>(pimpl->mFloatProperties,szName,iErrorReturn);
  877. }
  878. // ------------------------------------------------------------------------------------------------
  879. // Get a configuration property
  880. const std::string Importer::GetPropertyString(const char* szName,
  881. const std::string& iErrorReturn /*= ""*/) const
  882. {
  883. return GetGenericProperty<std::string>(pimpl->mStringProperties,szName,iErrorReturn);
  884. }
  885. // ------------------------------------------------------------------------------------------------
  886. // Get a configuration property
  887. const aiMatrix4x4 Importer::GetPropertyMatrix(const char* szName,
  888. const aiMatrix4x4& iErrorReturn /*= aiMatrix4x4()*/) const
  889. {
  890. return GetGenericProperty<aiMatrix4x4>(pimpl->mMatrixProperties,szName,iErrorReturn);
  891. }
  892. // ------------------------------------------------------------------------------------------------
  893. // Get the memory requirements of a single node
  894. inline void AddNodeWeight(unsigned int& iScene,const aiNode* pcNode)
  895. {
  896. iScene += sizeof(aiNode);
  897. iScene += sizeof(unsigned int) * pcNode->mNumMeshes;
  898. iScene += sizeof(void*) * pcNode->mNumChildren;
  899. for (unsigned int i = 0; i < pcNode->mNumChildren;++i) {
  900. AddNodeWeight(iScene,pcNode->mChildren[i]);
  901. }
  902. }
  903. // ------------------------------------------------------------------------------------------------
  904. // Get the memory requirements of the scene
  905. void Importer::GetMemoryRequirements(aiMemoryInfo& in) const
  906. {
  907. in = aiMemoryInfo();
  908. aiScene* mScene = pimpl->mScene;
  909. // return if we have no scene loaded
  910. if (!pimpl->mScene)
  911. return;
  912. in.total = sizeof(aiScene);
  913. // add all meshes
  914. for (unsigned int i = 0; i < mScene->mNumMeshes;++i)
  915. {
  916. in.meshes += sizeof(aiMesh);
  917. if (mScene->mMeshes[i]->HasPositions()) {
  918. in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices;
  919. }
  920. if (mScene->mMeshes[i]->HasNormals()) {
  921. in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices;
  922. }
  923. if (mScene->mMeshes[i]->HasTangentsAndBitangents()) {
  924. in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices * 2;
  925. }
  926. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS;++a) {
  927. if (mScene->mMeshes[i]->HasVertexColors(a)) {
  928. in.meshes += sizeof(aiColor4D) * mScene->mMeshes[i]->mNumVertices;
  929. }
  930. else break;
  931. }
  932. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS;++a) {
  933. if (mScene->mMeshes[i]->HasTextureCoords(a)) {
  934. in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices;
  935. }
  936. else break;
  937. }
  938. if (mScene->mMeshes[i]->HasBones()) {
  939. in.meshes += sizeof(void*) * mScene->mMeshes[i]->mNumBones;
  940. for (unsigned int p = 0; p < mScene->mMeshes[i]->mNumBones;++p) {
  941. in.meshes += sizeof(aiBone);
  942. in.meshes += mScene->mMeshes[i]->mBones[p]->mNumWeights * sizeof(aiVertexWeight);
  943. }
  944. }
  945. in.meshes += (sizeof(aiFace) + 3 * sizeof(unsigned int))*mScene->mMeshes[i]->mNumFaces;
  946. }
  947. in.total += in.meshes;
  948. // add all embedded textures
  949. for (unsigned int i = 0; i < mScene->mNumTextures;++i) {
  950. const aiTexture* pc = mScene->mTextures[i];
  951. in.textures += sizeof(aiTexture);
  952. if (pc->mHeight) {
  953. in.textures += 4 * pc->mHeight * pc->mWidth;
  954. }
  955. else in.textures += pc->mWidth;
  956. }
  957. in.total += in.textures;
  958. // add all animations
  959. for (unsigned int i = 0; i < mScene->mNumAnimations;++i) {
  960. const aiAnimation* pc = mScene->mAnimations[i];
  961. in.animations += sizeof(aiAnimation);
  962. // add all bone anims
  963. for (unsigned int a = 0; a < pc->mNumChannels; ++a) {
  964. const aiNodeAnim* pc2 = pc->mChannels[i];
  965. in.animations += sizeof(aiNodeAnim);
  966. in.animations += pc2->mNumPositionKeys * sizeof(aiVectorKey);
  967. in.animations += pc2->mNumScalingKeys * sizeof(aiVectorKey);
  968. in.animations += pc2->mNumRotationKeys * sizeof(aiQuatKey);
  969. }
  970. }
  971. in.total += in.animations;
  972. // add all cameras and all lights
  973. in.total += in.cameras = sizeof(aiCamera) * mScene->mNumCameras;
  974. in.total += in.lights = sizeof(aiLight) * mScene->mNumLights;
  975. // add all nodes
  976. AddNodeWeight(in.nodes,mScene->mRootNode);
  977. in.total += in.nodes;
  978. // add all materials
  979. for (unsigned int i = 0; i < mScene->mNumMaterials;++i) {
  980. const aiMaterial* pc = mScene->mMaterials[i];
  981. in.materials += sizeof(aiMaterial);
  982. in.materials += pc->mNumAllocated * sizeof(void*);
  983. for (unsigned int a = 0; a < pc->mNumProperties;++a) {
  984. in.materials += pc->mProperties[a]->mDataLength;
  985. }
  986. }
  987. in.total += in.materials;
  988. }