Importer.cpp 37 KB

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