Importer.cpp 43 KB

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