Importer.cpp 41 KB

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