Importer.cpp 41 KB

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