Importer.cpp 41 KB

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