Importer.cpp 38 KB

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