Importer.cpp 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  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. // 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. DefaultLogger::get()->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. DefaultLogger::get()->warn("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. DefaultLogger::get()->info("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. DefaultLogger::get()->info("Unregistering custom importer: ");
  215. return AI_SUCCESS;
  216. }
  217. DefaultLogger::get()->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. DefaultLogger::get()->info("Unregistering custom post-processing step");
  235. return AI_SUCCESS;
  236. }
  237. DefaultLogger::get()->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. {
  266. return pimpl->mIOHandler;
  267. }
  268. // ------------------------------------------------------------------------------------------------
  269. // Check whether a custom IO handler is currently set
  270. bool Importer::IsDefaultIOHandler() const
  271. {
  272. return pimpl->mIsDefaultHandler;
  273. }
  274. // ------------------------------------------------------------------------------------------------
  275. // Supplies a custom progress handler to get regular callbacks during importing
  276. void Importer::SetProgressHandler ( ProgressHandler* pHandler )
  277. {
  278. ASSIMP_BEGIN_EXCEPTION_REGION();
  279. // If the new handler is zero, allocate a default implementation.
  280. if (!pHandler)
  281. {
  282. // Release pointer in the possession of the caller
  283. pimpl->mProgressHandler = new DefaultProgressHandler();
  284. pimpl->mIsDefaultProgressHandler = true;
  285. }
  286. // Otherwise register the custom handler
  287. else if (pimpl->mProgressHandler != pHandler)
  288. {
  289. delete pimpl->mProgressHandler;
  290. pimpl->mProgressHandler = pHandler;
  291. pimpl->mIsDefaultProgressHandler = false;
  292. }
  293. ASSIMP_END_EXCEPTION_REGION(void);
  294. }
  295. // ------------------------------------------------------------------------------------------------
  296. // Get the currently set progress handler
  297. ProgressHandler* Importer::GetProgressHandler() const
  298. {
  299. return pimpl->mProgressHandler;
  300. }
  301. // ------------------------------------------------------------------------------------------------
  302. // Check whether a custom progress handler is currently set
  303. bool Importer::IsDefaultProgressHandler() const
  304. {
  305. return pimpl->mIsDefaultProgressHandler;
  306. }
  307. // ------------------------------------------------------------------------------------------------
  308. // Validate post process step flags
  309. bool _ValidateFlags(unsigned int pFlags)
  310. {
  311. if (pFlags & aiProcess_GenSmoothNormals && pFlags & aiProcess_GenNormals) {
  312. DefaultLogger::get()->error("#aiProcess_GenSmoothNormals and #aiProcess_GenNormals are incompatible");
  313. return false;
  314. }
  315. if (pFlags & aiProcess_OptimizeGraph && pFlags & aiProcess_PreTransformVertices) {
  316. DefaultLogger::get()->error("#aiProcess_OptimizeGraph and #aiProcess_PreTransformVertices are incompatible");
  317. return false;
  318. }
  319. return true;
  320. }
  321. // ------------------------------------------------------------------------------------------------
  322. // Free the current scene
  323. void Importer::FreeScene( )
  324. {
  325. ASSIMP_BEGIN_EXCEPTION_REGION();
  326. delete pimpl->mScene;
  327. pimpl->mScene = NULL;
  328. pimpl->mErrorString = "";
  329. ASSIMP_END_EXCEPTION_REGION(void);
  330. }
  331. // ------------------------------------------------------------------------------------------------
  332. // Get the current error string, if any
  333. const char* Importer::GetErrorString() const
  334. {
  335. /* Must remain valid as long as ReadFile() or FreeFile() are not called */
  336. return pimpl->mErrorString.c_str();
  337. }
  338. // ------------------------------------------------------------------------------------------------
  339. // Enable extra-verbose mode
  340. void Importer::SetExtraVerbose(bool bDo)
  341. {
  342. pimpl->bExtraVerbose = bDo;
  343. }
  344. // ------------------------------------------------------------------------------------------------
  345. // Get the current scene
  346. const aiScene* Importer::GetScene() const
  347. {
  348. return pimpl->mScene;
  349. }
  350. // ------------------------------------------------------------------------------------------------
  351. // Orphan the current scene and return it.
  352. aiScene* Importer::GetOrphanedScene()
  353. {
  354. aiScene* s = pimpl->mScene;
  355. ASSIMP_BEGIN_EXCEPTION_REGION();
  356. pimpl->mScene = NULL;
  357. pimpl->mErrorString = ""; /* reset error string */
  358. ASSIMP_END_EXCEPTION_REGION(aiScene*);
  359. return s;
  360. }
  361. // ------------------------------------------------------------------------------------------------
  362. // Validate post-processing flags
  363. bool Importer::ValidateFlags(unsigned int pFlags) const
  364. {
  365. ASSIMP_BEGIN_EXCEPTION_REGION();
  366. // run basic checks for mutually exclusive flags
  367. if(!_ValidateFlags(pFlags)) {
  368. return false;
  369. }
  370. // ValidateDS does not anymore occur in the pp list, it plays an awesome extra role ...
  371. #ifdef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  372. if (pFlags & aiProcess_ValidateDataStructure) {
  373. return false;
  374. }
  375. #endif
  376. pFlags &= ~aiProcess_ValidateDataStructure;
  377. // Now iterate through all bits which are set in the flags and check whether we find at least
  378. // one pp plugin which handles it.
  379. for (unsigned int mask = 1; mask < (1u << (sizeof(unsigned int)*8-1));mask <<= 1) {
  380. if (pFlags & mask) {
  381. bool have = false;
  382. for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++) {
  383. if (pimpl->mPostProcessingSteps[a]-> IsActive(mask) ) {
  384. have = true;
  385. break;
  386. }
  387. }
  388. if (!have) {
  389. return false;
  390. }
  391. }
  392. }
  393. ASSIMP_END_EXCEPTION_REGION(bool);
  394. return true;
  395. }
  396. // ------------------------------------------------------------------------------------------------
  397. const aiScene* Importer::ReadFileFromMemory( const void* pBuffer,
  398. size_t pLength,
  399. unsigned int pFlags,
  400. const char* pHint /*= ""*/)
  401. {
  402. ASSIMP_BEGIN_EXCEPTION_REGION();
  403. if (!pHint) {
  404. pHint = "";
  405. }
  406. if (!pBuffer || !pLength || strlen(pHint) > MaxLenHint ) {
  407. pimpl->mErrorString = "Invalid parameters passed to ReadFileFromMemory()";
  408. return NULL;
  409. }
  410. // prevent deletion of the previous IOHandler
  411. IOSystem* io = pimpl->mIOHandler;
  412. pimpl->mIOHandler = NULL;
  413. SetIOHandler(new MemoryIOSystem((const uint8_t*)pBuffer,pLength));
  414. // read the file and recover the previous IOSystem
  415. static const size_t BufferSize(Importer::MaxLenHint + 28);
  416. char fbuff[ BufferSize ];
  417. ai_snprintf(fbuff, BufferSize, "%s.%s",AI_MEMORYIO_MAGIC_FILENAME,pHint);
  418. ReadFile(fbuff,pFlags);
  419. SetIOHandler(io);
  420. ASSIMP_END_EXCEPTION_REGION(const aiScene*);
  421. return pimpl->mScene;
  422. }
  423. // ------------------------------------------------------------------------------------------------
  424. void WriteLogOpening(const std::string& file)
  425. {
  426. Logger* l = DefaultLogger::get();
  427. if (!l) {
  428. return;
  429. }
  430. l->info("Load " + file);
  431. // print a full version dump. This is nice because we don't
  432. // need to ask the authors of incoming bug reports for
  433. // the library version they're using - a log dump is
  434. // sufficient.
  435. const unsigned int flags = aiGetCompileFlags();
  436. l->debug(format()
  437. << "Assimp "
  438. << aiGetVersionMajor()
  439. << "."
  440. << aiGetVersionMinor()
  441. << "."
  442. << aiGetVersionRevision()
  443. << " "
  444. #if defined(ASSIMP_BUILD_ARCHITECTURE)
  445. << ASSIMP_BUILD_ARCHITECTURE
  446. #elif defined(_M_IX86) || defined(__x86_32__) || defined(__i386__)
  447. << "x86"
  448. #elif defined(_M_X64) || defined(__x86_64__)
  449. << "amd64"
  450. #elif defined(_M_IA64) || defined(__ia64__)
  451. << "itanium"
  452. #elif defined(__ppc__) || defined(__powerpc__)
  453. << "ppc32"
  454. #elif defined(__powerpc64__)
  455. << "ppc64"
  456. #elif defined(__arm__)
  457. << "arm"
  458. #else
  459. << "<unknown architecture>"
  460. #endif
  461. << " "
  462. #if defined(ASSIMP_BUILD_COMPILER)
  463. << ASSIMP_BUILD_COMPILER
  464. #elif defined(_MSC_VER)
  465. << "msvc"
  466. #elif defined(__GNUC__)
  467. << "gcc"
  468. #else
  469. << "<unknown compiler>"
  470. #endif
  471. #ifdef ASSIMP_BUILD_DEBUG
  472. << " debug"
  473. #endif
  474. << (flags & ASSIMP_CFLAGS_NOBOOST ? " noboost" : "")
  475. << (flags & ASSIMP_CFLAGS_SHARED ? " shared" : "")
  476. << (flags & ASSIMP_CFLAGS_SINGLETHREADED ? " singlethreaded" : "")
  477. );
  478. }
  479. // ------------------------------------------------------------------------------------------------
  480. // Reads the given file and returns its contents if successful.
  481. const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags)
  482. {
  483. ASSIMP_BEGIN_EXCEPTION_REGION();
  484. const std::string pFile(_pFile);
  485. // ----------------------------------------------------------------------
  486. // Put a large try block around everything to catch all std::exception's
  487. // that might be thrown by STL containers or by new().
  488. // ImportErrorException's are throw by ourselves and caught elsewhere.
  489. //-----------------------------------------------------------------------
  490. WriteLogOpening(pFile);
  491. #ifdef ASSIMP_CATCH_GLOBAL_EXCEPTIONS
  492. try
  493. #endif // ! ASSIMP_CATCH_GLOBAL_EXCEPTIONS
  494. {
  495. // Check whether this Importer instance has already loaded
  496. // a scene. In this case we need to delete the old one
  497. if (pimpl->mScene) {
  498. DefaultLogger::get()->debug("(Deleting previous scene)");
  499. FreeScene();
  500. }
  501. // First check if the file is accessible at all
  502. if( !pimpl->mIOHandler->Exists( pFile)) {
  503. pimpl->mErrorString = "Unable to open file \"" + pFile + "\".";
  504. DefaultLogger::get()->error(pimpl->mErrorString);
  505. return NULL;
  506. }
  507. std::unique_ptr<Profiler> profiler(GetPropertyInteger(AI_CONFIG_GLOB_MEASURE_TIME,0)?new Profiler():NULL);
  508. if (profiler) {
  509. profiler->BeginRegion("total");
  510. }
  511. // Find an worker class which can handle the file
  512. BaseImporter* imp = NULL;
  513. for( unsigned int a = 0; a < pimpl->mImporter.size(); a++) {
  514. if( pimpl->mImporter[a]->CanRead( pFile, pimpl->mIOHandler, false)) {
  515. imp = pimpl->mImporter[a];
  516. break;
  517. }
  518. }
  519. if (!imp) {
  520. // not so bad yet ... try format auto detection.
  521. const std::string::size_type s = pFile.find_last_of('.');
  522. if (s != std::string::npos) {
  523. DefaultLogger::get()->info("File extension not known, trying signature-based detection");
  524. for( unsigned int a = 0; a < pimpl->mImporter.size(); a++) {
  525. if( pimpl->mImporter[a]->CanRead( pFile, pimpl->mIOHandler, true)) {
  526. imp = pimpl->mImporter[a];
  527. break;
  528. }
  529. }
  530. }
  531. // Put a proper error message if no suitable importer was found
  532. if( !imp) {
  533. pimpl->mErrorString = "No suitable reader found for the file format of file \"" + pFile + "\".";
  534. DefaultLogger::get()->error(pimpl->mErrorString);
  535. return NULL;
  536. }
  537. }
  538. // Get file size for progress handler
  539. IOStream * fileIO = pimpl->mIOHandler->Open( pFile );
  540. uint32_t fileSize = 0;
  541. if (fileIO)
  542. {
  543. fileSize = static_cast<uint32_t>(fileIO->FileSize());
  544. pimpl->mIOHandler->Close( fileIO );
  545. }
  546. // Dispatch the reading to the worker class for this format
  547. const aiImporterDesc *desc( imp->GetInfo() );
  548. std::string ext( "unknown" );
  549. if ( NULL != desc ) {
  550. ext = desc->mName;
  551. }
  552. DefaultLogger::get()->info("Found a matching importer for this file format: " + ext + "." );
  553. pimpl->mProgressHandler->UpdateFileRead( 0, fileSize );
  554. if (profiler) {
  555. profiler->BeginRegion("import");
  556. }
  557. pimpl->mScene = imp->ReadFile( this, pFile, pimpl->mIOHandler);
  558. pimpl->mProgressHandler->UpdateFileRead( fileSize, fileSize );
  559. if (profiler) {
  560. profiler->EndRegion("import");
  561. }
  562. SetPropertyString("sourceFilePath", pFile);
  563. // If successful, apply all active post processing steps to the imported data
  564. if( pimpl->mScene) {
  565. #ifndef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  566. // The ValidateDS process is an exception. It is executed first, even before ScenePreprocessor is called.
  567. if (pFlags & aiProcess_ValidateDataStructure)
  568. {
  569. ValidateDSProcess ds;
  570. ds.ExecuteOnScene (this);
  571. if (!pimpl->mScene) {
  572. return NULL;
  573. }
  574. }
  575. #endif // no validation
  576. // Preprocess the scene and prepare it for post-processing
  577. if (profiler) {
  578. profiler->BeginRegion("preprocess");
  579. }
  580. ScenePreprocessor pre(pimpl->mScene);
  581. pre.ProcessScene();
  582. if (profiler) {
  583. profiler->EndRegion("preprocess");
  584. }
  585. // Ensure that the validation process won't be called twice
  586. ApplyPostProcessing(pFlags & (~aiProcess_ValidateDataStructure));
  587. }
  588. // if failed, extract the error string
  589. else if( !pimpl->mScene) {
  590. pimpl->mErrorString = imp->GetErrorText();
  591. }
  592. // clear any data allocated by post-process steps
  593. pimpl->mPPShared->Clean();
  594. if (profiler) {
  595. profiler->EndRegion("total");
  596. }
  597. }
  598. #ifdef ASSIMP_CATCH_GLOBAL_EXCEPTIONS
  599. catch (std::exception &e)
  600. {
  601. #if (defined _MSC_VER) && (defined _CPPRTTI)
  602. // if we have RTTI get the full name of the exception that occurred
  603. pimpl->mErrorString = std::string(typeid( e ).name()) + ": " + e.what();
  604. #else
  605. pimpl->mErrorString = std::string("std::exception: ") + e.what();
  606. #endif
  607. DefaultLogger::get()->error(pimpl->mErrorString);
  608. delete pimpl->mScene; pimpl->mScene = NULL;
  609. }
  610. #endif // ! ASSIMP_CATCH_GLOBAL_EXCEPTIONS
  611. // either successful or failure - the pointer expresses it anyways
  612. ASSIMP_END_EXCEPTION_REGION(const aiScene*);
  613. return pimpl->mScene;
  614. }
  615. // ------------------------------------------------------------------------------------------------
  616. // Apply post-processing to the currently bound scene
  617. const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags)
  618. {
  619. ASSIMP_BEGIN_EXCEPTION_REGION();
  620. // Return immediately if no scene is active
  621. if (!pimpl->mScene) {
  622. return NULL;
  623. }
  624. // If no flags are given, return the current scene with no further action
  625. if (!pFlags) {
  626. return pimpl->mScene;
  627. }
  628. // In debug builds: run basic flag validation
  629. ai_assert(_ValidateFlags(pFlags));
  630. DefaultLogger::get()->info("Entering post processing pipeline");
  631. #ifndef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  632. // The ValidateDS process plays an exceptional role. It isn't contained in the global
  633. // list of post-processing steps, so we need to call it manually.
  634. if (pFlags & aiProcess_ValidateDataStructure)
  635. {
  636. ValidateDSProcess ds;
  637. ds.ExecuteOnScene (this);
  638. if (!pimpl->mScene) {
  639. return NULL;
  640. }
  641. }
  642. #endif // no validation
  643. #ifdef ASSIMP_BUILD_DEBUG
  644. if (pimpl->bExtraVerbose)
  645. {
  646. #ifdef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  647. DefaultLogger::get()->error("Verbose Import is not available due to build settings");
  648. #endif // no validation
  649. pFlags |= aiProcess_ValidateDataStructure;
  650. }
  651. #else
  652. if (pimpl->bExtraVerbose) {
  653. DefaultLogger::get()->warn("Not a debug build, ignoring extra verbose setting");
  654. }
  655. #endif // ! DEBUG
  656. std::unique_ptr<Profiler> profiler(GetPropertyInteger(AI_CONFIG_GLOB_MEASURE_TIME,0)?new Profiler():NULL);
  657. for( unsigned int a = 0; a < pimpl->mPostProcessingSteps.size(); a++) {
  658. BaseProcess* process = pimpl->mPostProcessingSteps[a];
  659. pimpl->mProgressHandler->UpdatePostProcess(static_cast<int>(a), static_cast<int>(pimpl->mPostProcessingSteps.size()) );
  660. if( process->IsActive( pFlags)) {
  661. if (profiler) {
  662. profiler->BeginRegion("postprocess");
  663. }
  664. process->ExecuteOnScene ( this );
  665. if (profiler) {
  666. profiler->EndRegion("postprocess");
  667. }
  668. }
  669. if( !pimpl->mScene) {
  670. break;
  671. }
  672. #ifdef ASSIMP_BUILD_DEBUG
  673. #ifdef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  674. continue;
  675. #endif // no validation
  676. // If the extra verbose mode is active, execute the ValidateDataStructureStep again - after each step
  677. if (pimpl->bExtraVerbose) {
  678. DefaultLogger::get()->debug("Verbose Import: revalidating data structures");
  679. ValidateDSProcess ds;
  680. ds.ExecuteOnScene (this);
  681. if( !pimpl->mScene) {
  682. DefaultLogger::get()->error("Verbose Import: failed to revalidate data structures");
  683. break;
  684. }
  685. }
  686. #endif // ! DEBUG
  687. }
  688. pimpl->mProgressHandler->UpdatePostProcess( static_cast<int>(pimpl->mPostProcessingSteps.size()), static_cast<int>(pimpl->mPostProcessingSteps.size()) );
  689. // update private scene flags
  690. if( pimpl->mScene )
  691. ScenePriv(pimpl->mScene)->mPPStepsApplied |= pFlags;
  692. // clear any data allocated by post-process steps
  693. pimpl->mPPShared->Clean();
  694. DefaultLogger::get()->info("Leaving post processing pipeline");
  695. ASSIMP_END_EXCEPTION_REGION(const aiScene*);
  696. return pimpl->mScene;
  697. }
  698. // ------------------------------------------------------------------------------------------------
  699. const aiScene* Importer::ApplyCustomizedPostProcessing( BaseProcess *rootProcess, bool requestValidation ) {
  700. ASSIMP_BEGIN_EXCEPTION_REGION();
  701. // Return immediately if no scene is active
  702. if ( NULL == pimpl->mScene ) {
  703. return NULL;
  704. }
  705. // If no flags are given, return the current scene with no further action
  706. if ( NULL == rootProcess ) {
  707. return pimpl->mScene;
  708. }
  709. // In debug builds: run basic flag validation
  710. DefaultLogger::get()->info( "Entering customized post processing pipeline" );
  711. #ifndef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  712. // The ValidateDS process plays an exceptional role. It isn't contained in the global
  713. // list of post-processing steps, so we need to call it manually.
  714. if ( requestValidation )
  715. {
  716. ValidateDSProcess ds;
  717. ds.ExecuteOnScene( this );
  718. if ( !pimpl->mScene ) {
  719. return NULL;
  720. }
  721. }
  722. #endif // no validation
  723. #ifdef ASSIMP_BUILD_DEBUG
  724. if ( pimpl->bExtraVerbose )
  725. {
  726. #ifdef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
  727. DefaultLogger::get()->error( "Verbose Import is not available due to build settings" );
  728. #endif // no validation
  729. }
  730. #else
  731. if ( pimpl->bExtraVerbose ) {
  732. DefaultLogger::get()->warn( "Not a debug build, ignoring extra verbose setting" );
  733. }
  734. #endif // ! DEBUG
  735. std::unique_ptr<Profiler> profiler( GetPropertyInteger( AI_CONFIG_GLOB_MEASURE_TIME, 0 ) ? new Profiler() : NULL );
  736. if ( profiler ) {
  737. profiler->BeginRegion( "postprocess" );
  738. }
  739. rootProcess->ExecuteOnScene( this );
  740. if ( profiler ) {
  741. profiler->EndRegion( "postprocess" );
  742. }
  743. // If the extra verbose mode is active, execute the ValidateDataStructureStep again - after each step
  744. if ( pimpl->bExtraVerbose || requestValidation ) {
  745. DefaultLogger::get()->debug( "Verbose Import: revalidating data structures" );
  746. ValidateDSProcess ds;
  747. ds.ExecuteOnScene( this );
  748. if ( !pimpl->mScene ) {
  749. DefaultLogger::get()->error( "Verbose Import: failed to revalidate data structures" );
  750. }
  751. }
  752. // clear any data allocated by post-process steps
  753. pimpl->mPPShared->Clean();
  754. DefaultLogger::get()->info( "Leaving customized post processing pipeline" );
  755. ASSIMP_END_EXCEPTION_REGION( const aiScene* );
  756. return pimpl->mScene;
  757. }
  758. // ------------------------------------------------------------------------------------------------
  759. // Helper function to check whether an extension is supported by ASSIMP
  760. bool Importer::IsExtensionSupported(const char* szExtension) const
  761. {
  762. return NULL != GetImporter(szExtension);
  763. }
  764. // ------------------------------------------------------------------------------------------------
  765. size_t Importer::GetImporterCount() const
  766. {
  767. return pimpl->mImporter.size();
  768. }
  769. // ------------------------------------------------------------------------------------------------
  770. const aiImporterDesc* Importer::GetImporterInfo(size_t index) const
  771. {
  772. if (index >= pimpl->mImporter.size()) {
  773. return NULL;
  774. }
  775. return pimpl->mImporter[index]->GetInfo();
  776. }
  777. // ------------------------------------------------------------------------------------------------
  778. BaseImporter* Importer::GetImporter (size_t index) const
  779. {
  780. if (index >= pimpl->mImporter.size()) {
  781. return NULL;
  782. }
  783. return pimpl->mImporter[index];
  784. }
  785. // ------------------------------------------------------------------------------------------------
  786. // Find a loader plugin for a given file extension
  787. BaseImporter* Importer::GetImporter (const char* szExtension) const
  788. {
  789. return GetImporter(GetImporterIndex(szExtension));
  790. }
  791. // ------------------------------------------------------------------------------------------------
  792. // Find a loader plugin for a given file extension
  793. size_t Importer::GetImporterIndex (const char* szExtension) const
  794. {
  795. ai_assert(szExtension);
  796. ASSIMP_BEGIN_EXCEPTION_REGION();
  797. // skip over wildcard and dot characters at string head --
  798. for(;*szExtension == '*' || *szExtension == '.'; ++szExtension);
  799. std::string ext(szExtension);
  800. if (ext.empty()) {
  801. return static_cast<size_t>(-1);
  802. }
  803. std::transform(ext.begin(),ext.end(), ext.begin(), tolower);
  804. std::set<std::string> str;
  805. for (std::vector<BaseImporter*>::const_iterator i = pimpl->mImporter.begin();i != pimpl->mImporter.end();++i) {
  806. str.clear();
  807. (*i)->GetExtensionList(str);
  808. for (std::set<std::string>::const_iterator it = str.begin(); it != str.end(); ++it) {
  809. if (ext == *it) {
  810. return std::distance(static_cast< std::vector<BaseImporter*>::const_iterator >(pimpl->mImporter.begin()), i);
  811. }
  812. }
  813. }
  814. ASSIMP_END_EXCEPTION_REGION(size_t);
  815. return static_cast<size_t>(-1);
  816. }
  817. // ------------------------------------------------------------------------------------------------
  818. // Helper function to build a list of all file extensions supported by ASSIMP
  819. void Importer::GetExtensionList(aiString& szOut) const
  820. {
  821. ASSIMP_BEGIN_EXCEPTION_REGION();
  822. std::set<std::string> str;
  823. for (std::vector<BaseImporter*>::const_iterator i = pimpl->mImporter.begin();i != pimpl->mImporter.end();++i) {
  824. (*i)->GetExtensionList(str);
  825. }
  826. for (std::set<std::string>::const_iterator it = str.begin();; ) {
  827. szOut.Append("*.");
  828. szOut.Append((*it).c_str());
  829. if (++it == str.end()) {
  830. break;
  831. }
  832. szOut.Append(";");
  833. }
  834. ASSIMP_END_EXCEPTION_REGION(void);
  835. }
  836. // ------------------------------------------------------------------------------------------------
  837. // Set a configuration property
  838. bool Importer::SetPropertyInteger(const char* szName, int iValue)
  839. {
  840. bool existing;
  841. ASSIMP_BEGIN_EXCEPTION_REGION();
  842. existing = SetGenericProperty<int>(pimpl->mIntProperties, szName,iValue);
  843. ASSIMP_END_EXCEPTION_REGION(bool);
  844. return existing;
  845. }
  846. // ------------------------------------------------------------------------------------------------
  847. // Set a configuration property
  848. bool Importer::SetPropertyFloat(const char* szName, ai_real iValue)
  849. {
  850. bool exising;
  851. ASSIMP_BEGIN_EXCEPTION_REGION();
  852. exising = SetGenericProperty<ai_real>(pimpl->mFloatProperties, szName,iValue);
  853. ASSIMP_END_EXCEPTION_REGION(bool);
  854. return exising;
  855. }
  856. // ------------------------------------------------------------------------------------------------
  857. // Set a configuration property
  858. bool Importer::SetPropertyString(const char* szName, const std::string& value)
  859. {
  860. bool exising;
  861. ASSIMP_BEGIN_EXCEPTION_REGION();
  862. exising = SetGenericProperty<std::string>(pimpl->mStringProperties, szName,value);
  863. ASSIMP_END_EXCEPTION_REGION(bool);
  864. return exising;
  865. }
  866. // ------------------------------------------------------------------------------------------------
  867. // Set a configuration property
  868. bool Importer::SetPropertyMatrix(const char* szName, const aiMatrix4x4& value)
  869. {
  870. bool exising;
  871. ASSIMP_BEGIN_EXCEPTION_REGION();
  872. exising = SetGenericProperty<aiMatrix4x4>(pimpl->mMatrixProperties, szName,value);
  873. ASSIMP_END_EXCEPTION_REGION(bool);
  874. return exising;
  875. }
  876. // ------------------------------------------------------------------------------------------------
  877. // Get a configuration property
  878. int Importer::GetPropertyInteger(const char* szName,
  879. int iErrorReturn /*= 0xffffffff*/) const
  880. {
  881. return GetGenericProperty<int>(pimpl->mIntProperties,szName,iErrorReturn);
  882. }
  883. // ------------------------------------------------------------------------------------------------
  884. // Get a configuration property
  885. ai_real Importer::GetPropertyFloat(const char* szName,
  886. ai_real iErrorReturn /*= 10e10*/) const
  887. {
  888. return GetGenericProperty<ai_real>(pimpl->mFloatProperties,szName,iErrorReturn);
  889. }
  890. // ------------------------------------------------------------------------------------------------
  891. // Get a configuration property
  892. const std::string Importer::GetPropertyString(const char* szName,
  893. const std::string& iErrorReturn /*= ""*/) const
  894. {
  895. return GetGenericProperty<std::string>(pimpl->mStringProperties,szName,iErrorReturn);
  896. }
  897. // ------------------------------------------------------------------------------------------------
  898. // Get a configuration property
  899. const aiMatrix4x4 Importer::GetPropertyMatrix(const char* szName,
  900. const aiMatrix4x4& iErrorReturn /*= aiMatrix4x4()*/) const
  901. {
  902. return GetGenericProperty<aiMatrix4x4>(pimpl->mMatrixProperties,szName,iErrorReturn);
  903. }
  904. // ------------------------------------------------------------------------------------------------
  905. // Get the memory requirements of a single node
  906. inline void AddNodeWeight(unsigned int& iScene,const aiNode* pcNode)
  907. {
  908. iScene += sizeof(aiNode);
  909. iScene += sizeof(unsigned int) * pcNode->mNumMeshes;
  910. iScene += sizeof(void*) * pcNode->mNumChildren;
  911. for (unsigned int i = 0; i < pcNode->mNumChildren;++i) {
  912. AddNodeWeight(iScene,pcNode->mChildren[i]);
  913. }
  914. }
  915. // ------------------------------------------------------------------------------------------------
  916. // Get the memory requirements of the scene
  917. void Importer::GetMemoryRequirements(aiMemoryInfo& in) const
  918. {
  919. in = aiMemoryInfo();
  920. aiScene* mScene = pimpl->mScene;
  921. // return if we have no scene loaded
  922. if (!pimpl->mScene)
  923. return;
  924. in.total = sizeof(aiScene);
  925. // add all meshes
  926. for (unsigned int i = 0; i < mScene->mNumMeshes;++i)
  927. {
  928. in.meshes += sizeof(aiMesh);
  929. if (mScene->mMeshes[i]->HasPositions()) {
  930. in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices;
  931. }
  932. if (mScene->mMeshes[i]->HasNormals()) {
  933. in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices;
  934. }
  935. if (mScene->mMeshes[i]->HasTangentsAndBitangents()) {
  936. in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices * 2;
  937. }
  938. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS;++a) {
  939. if (mScene->mMeshes[i]->HasVertexColors(a)) {
  940. in.meshes += sizeof(aiColor4D) * mScene->mMeshes[i]->mNumVertices;
  941. }
  942. else break;
  943. }
  944. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS;++a) {
  945. if (mScene->mMeshes[i]->HasTextureCoords(a)) {
  946. in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices;
  947. }
  948. else break;
  949. }
  950. if (mScene->mMeshes[i]->HasBones()) {
  951. in.meshes += sizeof(void*) * mScene->mMeshes[i]->mNumBones;
  952. for (unsigned int p = 0; p < mScene->mMeshes[i]->mNumBones;++p) {
  953. in.meshes += sizeof(aiBone);
  954. in.meshes += mScene->mMeshes[i]->mBones[p]->mNumWeights * sizeof(aiVertexWeight);
  955. }
  956. }
  957. in.meshes += (sizeof(aiFace) + 3 * sizeof(unsigned int))*mScene->mMeshes[i]->mNumFaces;
  958. }
  959. in.total += in.meshes;
  960. // add all embedded textures
  961. for (unsigned int i = 0; i < mScene->mNumTextures;++i) {
  962. const aiTexture* pc = mScene->mTextures[i];
  963. in.textures += sizeof(aiTexture);
  964. if (pc->mHeight) {
  965. in.textures += 4 * pc->mHeight * pc->mWidth;
  966. }
  967. else in.textures += pc->mWidth;
  968. }
  969. in.total += in.textures;
  970. // add all animations
  971. for (unsigned int i = 0; i < mScene->mNumAnimations;++i) {
  972. const aiAnimation* pc = mScene->mAnimations[i];
  973. in.animations += sizeof(aiAnimation);
  974. // add all bone anims
  975. for (unsigned int a = 0; a < pc->mNumChannels; ++a) {
  976. const aiNodeAnim* pc2 = pc->mChannels[i];
  977. in.animations += sizeof(aiNodeAnim);
  978. in.animations += pc2->mNumPositionKeys * sizeof(aiVectorKey);
  979. in.animations += pc2->mNumScalingKeys * sizeof(aiVectorKey);
  980. in.animations += pc2->mNumRotationKeys * sizeof(aiQuatKey);
  981. }
  982. }
  983. in.total += in.animations;
  984. // add all cameras and all lights
  985. in.total += in.cameras = sizeof(aiCamera) * mScene->mNumCameras;
  986. in.total += in.lights = sizeof(aiLight) * mScene->mNumLights;
  987. // add all nodes
  988. AddNodeWeight(in.nodes,mScene->mRootNode);
  989. in.total += in.nodes;
  990. // add all materials
  991. for (unsigned int i = 0; i < mScene->mNumMaterials;++i) {
  992. const aiMaterial* pc = mScene->mMaterials[i];
  993. in.materials += sizeof(aiMaterial);
  994. in.materials += pc->mNumAllocated * sizeof(void*);
  995. for (unsigned int a = 0; a < pc->mNumProperties;++a) {
  996. in.materials += pc->mProperties[a]->mDataLength;
  997. }
  998. }
  999. in.total += in.materials;
  1000. }