Importer.cpp 38 KB

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