Importer.cpp 41 KB

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