Importer.cpp 41 KB

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