Importer.cpp 40 KB

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