Importer.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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 Implementation of the CPP-API class #Importer */
  35. // STL/CSL heades
  36. #include <fstream>
  37. #include <string>
  38. // public Assimp API
  39. #include "../include/assimp.hpp"
  40. #include "../include/aiAssert.h"
  41. #include "../include/aiScene.h"
  42. #include "../include/aiPostProcess.h"
  43. #include "../include/DefaultLogger.h"
  44. // internal headers
  45. #include "BaseImporter.h"
  46. #include "BaseProcess.h"
  47. #include "DefaultIOStream.h"
  48. #include "DefaultIOSystem.h"
  49. // Importers
  50. #if (!defined AI_BUILD_NO_X_IMPORTER)
  51. # include "XFileImporter.h"
  52. #endif
  53. #if (!defined AI_BUILD_NO_3DS_IMPORTER)
  54. # include "3DSLoader.h"
  55. #endif
  56. #if (!defined AI_BUILD_NO_MD3_IMPORTER)
  57. # include "MD3Loader.h"
  58. #endif
  59. #if (!defined AI_BUILD_NO_MDL_IMPORTER)
  60. # include "MDLLoader.h"
  61. #endif
  62. #if (!defined AI_BUILD_NO_MD2_IMPORTER)
  63. # include "MD2Loader.h"
  64. #endif
  65. #if (!defined AI_BUILD_NO_PLY_IMPORTER)
  66. # include "PlyLoader.h"
  67. #endif
  68. #if (!defined AI_BUILD_NO_ASE_IMPORTER)
  69. # include "ASELoader.h"
  70. #endif
  71. #if (!defined AI_BUILD_NO_OBJ_IMPORTER)
  72. # include "ObjFileImporter.h"
  73. #endif
  74. #if (!defined AI_BUILD_NO_HMP_IMPORTER)
  75. # include "HMPLoader.h"
  76. #endif
  77. #if (!defined AI_BUILD_NO_SMD_IMPORTER)
  78. # include "SMDLoader.h"
  79. #endif
  80. #if 0
  81. #if (!defined AI_BUILD_NO_MDR_IMPORTER)
  82. # include "MDRLoader.h"
  83. #endif
  84. #if (!defined AI_BUILD_NO_MDC_IMPORTER)
  85. # include "MDCLoader.h"
  86. #endif
  87. #endif
  88. #if (!defined AI_BUILD_NO_MD5_IMPORTER)
  89. # include "MD5Loader.h"
  90. #endif
  91. #if (!defined AI_BUILD_NO_MD5_IMPORTER)
  92. # include "MD5Loader.h"
  93. #endif
  94. #if (!defined AI_BUILD_NO_STL_IMPORTER)
  95. # include "STLLoader.h"
  96. #endif
  97. #if (!defined AI_BUILD_NO_LWO_IMPORTER)
  98. # include "LWOLoader.h"
  99. #endif
  100. // PostProcess-Steps
  101. #if (!defined AI_BUILD_NO_CALCTANGENTS_PROCESS)
  102. # include "CalcTangentsProcess.h"
  103. #endif
  104. #if (!defined AI_BUILD_NO_JOINVERTICES_PROCESS)
  105. # include "JoinVerticesProcess.h"
  106. #endif
  107. #if (!defined AI_BUILD_NO_CONVERTTOLH_PROCESS)
  108. # include "ConvertToLHProcess.h"
  109. #endif
  110. #if (!defined AI_BUILD_NO_TRIANGULATE_PROCESS)
  111. # include "TriangulateProcess.h"
  112. #endif
  113. #if (!defined AI_BUILD_NO_GENFACENORMALS_PROCESS)
  114. # include "GenFaceNormalsProcess.h"
  115. #endif
  116. #if (!defined AI_BUILD_NO_GENVERTEXNORMALS_PROCESS)
  117. # include "GenVertexNormalsProcess.h"
  118. #endif
  119. #if (!defined AI_BUILD_NO_KILLNORMALS_PROCESS)
  120. # include "KillNormalsProcess.h"
  121. #endif
  122. #if (!defined AI_BUILD_NO_SPLITLARGEMESHES_PROCESS)
  123. # include "SplitLargeMeshes.h"
  124. #endif
  125. #if (!defined AI_BUILD_NO_PRETRANSFORMVERTICES_PROCESS)
  126. # include "PretransformVertices.h"
  127. #endif
  128. #if (!defined AI_BUILD_NO_LIMITBONEWEIGHTS_PROCESS)
  129. # include "LimitBoneWeightsProcess.h"
  130. #endif
  131. #if (!defined AI_BUILD_NO_VALIDATEDS_PROCESS)
  132. # include "ValidateDataStructure.h"
  133. #endif
  134. #if (!defined AI_BUILD_NO_IMPROVECACHELOCALITY_PROCESS)
  135. # include "ImproveCacheLocality.h"
  136. #endif
  137. #if (!defined AI_BUILD_NO_FIXINFACINGNORMALS_PROCESS)
  138. # include "FixNormalsStep.h"
  139. #endif
  140. #if (!defined AI_BUILD_NO_REMOVE_REDUNDANTMATERIALS_PROCESS)
  141. # include "RemoveRedundantMaterials.h"
  142. #endif
  143. using namespace Assimp;
  144. // ------------------------------------------------------------------------------------------------
  145. // Constructor.
  146. Importer::Importer() :
  147. mIOHandler(NULL),
  148. mScene(NULL),
  149. mErrorString("")
  150. {
  151. // allocate a default IO handler
  152. mIOHandler = new DefaultIOSystem;
  153. mIsDefaultHandler = true;
  154. bExtraVerbose = false; // disable extra verbose mode by default
  155. // add an instance of each worker class here
  156. #if (!defined AI_BUILD_NO_X_IMPORTER)
  157. mImporter.push_back( new XFileImporter());
  158. #endif
  159. #if (!defined AI_BUILD_NO_OBJ_IMPORTER)
  160. mImporter.push_back( new ObjFileImporter());
  161. #endif
  162. #if (!defined AI_BUILD_NO_3DS_IMPORTER)
  163. mImporter.push_back( new Dot3DSImporter());
  164. #endif
  165. #if (!defined AI_BUILD_NO_MD3_IMPORTER)
  166. mImporter.push_back( new MD3Importer());
  167. #endif
  168. #if (!defined AI_BUILD_NO_MD2_IMPORTER)
  169. mImporter.push_back( new MD2Importer());
  170. #endif
  171. #if (!defined AI_BUILD_NO_PLY_IMPORTER)
  172. mImporter.push_back( new PLYImporter());
  173. #endif
  174. #if (!defined AI_BUILD_NO_MDL_IMPORTER)
  175. mImporter.push_back( new MDLImporter());
  176. #endif
  177. #if (!defined AI_BUILD_NO_ASE_IMPORTER)
  178. mImporter.push_back( new ASEImporter());
  179. #endif
  180. #if (!defined AI_BUILD_NO_HMP_IMPORTER)
  181. mImporter.push_back( new HMPImporter());
  182. #endif
  183. #if (!defined AI_BUILD_NO_SMD_IMPORTER)
  184. mImporter.push_back( new SMDImporter());
  185. #endif
  186. #if 0
  187. #if (!defined AI_BUILD_NO_MDR_IMPORTER)
  188. mImporter.push_back( new MDRImporter());
  189. #endif
  190. #if (!defined AI_BUILD_NO_MDC_IMPORTER)
  191. mImporter.push_back( new MDCImporter());
  192. #endif
  193. #endif
  194. #if (!defined AI_BUILD_NO_MD5_IMPORTER)
  195. mImporter.push_back( new MD5Importer());
  196. #endif
  197. #if (!defined AI_BUILD_NO_STL_IMPORTER)
  198. mImporter.push_back( new STLImporter());
  199. #endif
  200. #if (!defined AI_BUILD_NO_LWO_IMPORTER)
  201. mImporter.push_back( new LWOImporter());
  202. #endif
  203. // add an instance of each post processing step here in the order
  204. // of sequence it is executed
  205. #if (!defined AI_BUILD_NO_VALIDATEDS_PROCESS)
  206. mPostProcessingSteps.push_back( new ValidateDSProcess()); // must be first
  207. #endif
  208. #if (!defined AI_BUILD_NO_REMOVE_REDUNDANTMATERIALS_PROCESS)
  209. mPostProcessingSteps.push_back( new RemoveRedundantMatsProcess());
  210. #endif
  211. #if (!defined AI_BUILD_NO_TRIANGULATE_PROCESS)
  212. mPostProcessingSteps.push_back( new TriangulateProcess());
  213. #endif
  214. #if (!defined AI_BUILD_NO_PRETRANSFORMVERTICES_PROCESS)
  215. mPostProcessingSteps.push_back( new PretransformVertices());
  216. #endif
  217. #if (!defined AI_BUILD_NO_FIXINFACINGNORMALS_PROCESS)
  218. mPostProcessingSteps.push_back( new FixInfacingNormalsProcess());
  219. #endif
  220. #if (!defined AI_BUILD_NO_SPLITLARGEMESHES_PROCESS)
  221. mPostProcessingSteps.push_back( new SplitLargeMeshesProcess_Triangle());
  222. #endif
  223. #if (!defined AI_BUILD_NO_KILLNORMALS_PROCESS)
  224. mPostProcessingSteps.push_back( new KillNormalsProcess());
  225. #endif
  226. #if (!defined AI_BUILD_NO_GENFACENORMALS_PROCESS)
  227. mPostProcessingSteps.push_back( new GenFaceNormalsProcess());
  228. #endif
  229. #if (!defined AI_BUILD_NO_GENVERTEXNORMALS_PROCESS)
  230. mPostProcessingSteps.push_back( new GenVertexNormalsProcess());
  231. #endif
  232. #if (!defined AI_BUILD_NO_CALCTANGENTS_PROCESS)
  233. mPostProcessingSteps.push_back( new CalcTangentsProcess());
  234. #endif
  235. #if (!defined AI_BUILD_NO_JOINVERTICES_PROCESS)
  236. mPostProcessingSteps.push_back( new JoinVerticesProcess());
  237. #endif
  238. #if (!defined AI_BUILD_NO_SPLITLARGEMESHES_PROCESS)
  239. mPostProcessingSteps.push_back( new SplitLargeMeshesProcess_Vertex());
  240. #endif
  241. #if (!defined AI_BUILD_NO_CONVERTTOLH_PROCESS)
  242. mPostProcessingSteps.push_back( new ConvertToLHProcess());
  243. #endif
  244. #if (!defined AI_BUILD_NO_LIMITBONEWEIGHTS_PROCESS)
  245. mPostProcessingSteps.push_back( new LimitBoneWeightsProcess());
  246. #endif
  247. #if (!defined AI_BUILD_NO_IMPROVECACHELOCALITY_PROCESS)
  248. mPostProcessingSteps.push_back( new ImproveCacheLocalityProcess());
  249. #endif
  250. //// store the *this* pointer in all BaseImporter instances
  251. //for (std::vector<BaseImporter*>::iterator
  252. // i = mImporter.begin();
  253. // i != mImporter.end();++i)
  254. //{
  255. // (**i).mImporter = this;
  256. //}
  257. //// store the *this* pointer in all BaseProcess instances
  258. //for (std::vector<BaseProcess*>::iterator
  259. // i = mPostProcessingSteps.begin();
  260. // i != mPostProcessingSteps.end();++i)
  261. //{
  262. // (**i).mImporter = this;
  263. //}
  264. }
  265. // ------------------------------------------------------------------------------------------------
  266. // Destructor.
  267. Importer::~Importer()
  268. {
  269. for( unsigned int a = 0; a < mImporter.size(); a++)
  270. delete mImporter[a];
  271. for( unsigned int a = 0; a < mPostProcessingSteps.size(); a++)
  272. delete mPostProcessingSteps[a];
  273. // delete the assigned IO handler
  274. delete mIOHandler;
  275. // kill imported scene. Destructors should do that recursivly
  276. delete mScene;
  277. }
  278. // ------------------------------------------------------------------------------------------------
  279. // Supplies a custom IO handler to the importer to open and access files.
  280. void Importer::SetIOHandler( IOSystem* pIOHandler)
  281. {
  282. if (!pIOHandler)
  283. {
  284. delete mIOHandler;
  285. mIOHandler = new DefaultIOSystem();
  286. mIsDefaultHandler = true;
  287. }
  288. else if (mIOHandler != pIOHandler)
  289. {
  290. delete mIOHandler;
  291. mIOHandler = pIOHandler;
  292. mIsDefaultHandler = false;
  293. }
  294. return;
  295. }
  296. // ------------------------------------------------------------------------------------------------
  297. IOSystem* Importer::GetIOHandler()
  298. {
  299. return mIOHandler;
  300. }
  301. // ------------------------------------------------------------------------------------------------
  302. bool Importer::IsDefaultIOHandler()
  303. {
  304. return mIsDefaultHandler;
  305. }
  306. // ------------------------------------------------------------------------------------------------
  307. // Validate post process step flags
  308. bool ValidateFlags(unsigned int pFlags)
  309. {
  310. if (pFlags & aiProcess_GenSmoothNormals &&
  311. pFlags & aiProcess_GenNormals)
  312. {
  313. DefaultLogger::get()->error("aiProcess_GenSmoothNormals and aiProcess_GenNormals "
  314. "may not be specified together");
  315. return false;
  316. }
  317. return true;
  318. }
  319. // ------------------------------------------------------------------------------------------------
  320. // Reads the given file and returns its contents if successful.
  321. const aiScene* Importer::ReadFile( const std::string& pFile, unsigned int pFlags)
  322. {
  323. // validate the flags
  324. ai_assert(ValidateFlags(pFlags));
  325. // check whether this Importer instance has already loaded
  326. // a scene. In this case we need to delete the old one
  327. if (this->mScene)
  328. {
  329. delete mScene;
  330. this->mScene = NULL;
  331. }
  332. // first check if the file is accessable at all
  333. if( !mIOHandler->Exists( pFile))
  334. {
  335. mErrorString = "Unable to open file \"" + pFile + "\".";
  336. DefaultLogger::get()->error(mErrorString);
  337. return NULL;
  338. }
  339. // find an worker class which can handle the file
  340. BaseImporter* imp = NULL;
  341. for( unsigned int a = 0; a < mImporter.size(); a++)
  342. {
  343. if( mImporter[a]->CanRead( pFile, mIOHandler))
  344. {
  345. imp = mImporter[a];
  346. break;
  347. }
  348. }
  349. // put a proper error message if no suitable importer was found
  350. if( !imp)
  351. {
  352. mErrorString = "No suitable reader found for the file format of file \"" + pFile + "\".";
  353. DefaultLogger::get()->error(mErrorString);
  354. return NULL;
  355. }
  356. // dispatch the reading to the worker class for this format
  357. mScene = imp->ReadFile( pFile, mIOHandler);
  358. // if successful, apply all active post processing steps to the imported data
  359. if( mScene)
  360. {
  361. if (bExtraVerbose)
  362. {
  363. pFlags |= aiProcess_ValidateDataStructure;
  364. // use the MSB to tell the ValidateDS-Step that e're in extra verbose mode
  365. // TODO: temporary solution, clean up later
  366. mScene->mFlags |= 0x80000000;
  367. }
  368. for( unsigned int a = 0; a < mPostProcessingSteps.size(); a++)
  369. {
  370. BaseProcess* process = mPostProcessingSteps[a];
  371. if( process->IsActive( pFlags))
  372. {
  373. process->ExecuteOnScene( this );
  374. }
  375. if( !mScene)break; // error string has already been set ...
  376. // if the extra verbose mode is active execute the
  377. // VaidateDataStructureStep again after each step
  378. if (bExtraVerbose && a)
  379. {
  380. DefaultLogger::get()->debug("Extra verbose: revalidating data structures");
  381. ((ValidateDSProcess*)mPostProcessingSteps[0])->ExecuteOnScene (this);
  382. if( !mScene)
  383. {
  384. DefaultLogger::get()->error("Extra verbose: failed to revalidate data structures");
  385. break; // error string has already been set ...
  386. }
  387. }
  388. }
  389. if (bExtraVerbose)mScene->mFlags &= ~0x80000000;
  390. }
  391. // if failed, extract the error string
  392. else if( !mScene)
  393. {
  394. mErrorString = imp->GetErrorText();
  395. }
  396. // either successful or failure - the pointer expresses it anyways
  397. return mScene;
  398. }
  399. // ------------------------------------------------------------------------------------------------
  400. // Empty and private copy constructor
  401. Importer::Importer(const Importer &other)
  402. {
  403. // empty
  404. }
  405. // ------------------------------------------------------------------------------------------------
  406. // Helper function to check whether an extension is supported by ASSIMP
  407. bool Importer::IsExtensionSupported(const std::string& szExtension)
  408. {
  409. for (std::vector<BaseImporter*>::const_iterator
  410. i = this->mImporter.begin();
  411. i != this->mImporter.end();++i)
  412. {
  413. // pass the file extension to the CanRead(..,NULL)-method
  414. if ((*i)->CanRead(szExtension,NULL))return true;
  415. }
  416. return false;
  417. }
  418. // ------------------------------------------------------------------------------------------------
  419. // Helper function to build a list of all file extensions supported by ASSIMP
  420. void Importer::GetExtensionList(std::string& szOut)
  421. {
  422. unsigned int iNum = 0;
  423. for (std::vector<BaseImporter*>::const_iterator
  424. i = this->mImporter.begin();
  425. i != this->mImporter.end();++i,++iNum)
  426. {
  427. // insert a comma as delimiter character
  428. if (0 != iNum)
  429. szOut.append(";");
  430. (*i)->GetExtensionList(szOut);
  431. }
  432. return;
  433. }
  434. // ------------------------------------------------------------------------------------------------
  435. // Set a configuration property
  436. int Importer::SetProperty(const char* szName, int iValue)
  437. {
  438. ai_assert(NULL != szName);
  439. // search in the list ...
  440. for (std::vector<IntPropertyInfo>::iterator
  441. i = this->mIntProperties.begin();
  442. i != this->mIntProperties.end();++i)
  443. {
  444. if (0 == ::strcmp( (*i).name.c_str(), szName ))
  445. {
  446. int iOld = (*i).value;
  447. (*i).value = iValue;
  448. return iOld;
  449. }
  450. }
  451. // the property is not yet in the list ...
  452. this->mIntProperties.push_back( IntPropertyInfo() );
  453. IntPropertyInfo& me = this->mIntProperties.back();
  454. me.name = std::string(szName);
  455. me.value = iValue;
  456. return AI_PROPERTY_WAS_NOT_EXISTING;
  457. }
  458. // ------------------------------------------------------------------------------------------------
  459. // Get a configuration property
  460. int Importer::GetProperty(const char* szName,
  461. int iErrorReturn /*= 0xffffffff*/)
  462. {
  463. ai_assert(NULL != szName);
  464. // search in the list ...
  465. for (std::vector<IntPropertyInfo>::const_iterator
  466. i = this->mIntProperties.begin();
  467. i != this->mIntProperties.end();++i)
  468. {
  469. if (0 == ::strcmp( (*i).name.c_str(), szName ))
  470. {
  471. return (*i).value;
  472. }
  473. }
  474. return iErrorReturn;
  475. }
  476. // ------------------------------------------------------------------------------------------------
  477. void AddNodeWeight(unsigned int& iScene,const aiNode* pcNode)
  478. {
  479. iScene += sizeof(aiNode);
  480. iScene += sizeof(unsigned int) * pcNode->mNumMeshes;
  481. iScene += sizeof(void*) * pcNode->mNumChildren;
  482. for (unsigned int i = 0; i < pcNode->mNumChildren;++i)
  483. AddNodeWeight(iScene,pcNode->mChildren[i]);
  484. }
  485. // ------------------------------------------------------------------------------------------------
  486. // Get the memory requirements of the scene
  487. void Importer::GetMemoryRequirements(aiMemoryInfo& in) const
  488. {
  489. in.aiMemoryInfo::aiMemoryInfo();
  490. if (!this->mScene)return;
  491. in.total = sizeof(aiScene);
  492. // add all meshes
  493. for (unsigned int i = 0; i < mScene->mNumMeshes;++i)
  494. {
  495. in.meshes += sizeof(aiMesh);
  496. if (mScene->mMeshes[i]->HasPositions())
  497. in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices;
  498. if (mScene->mMeshes[i]->HasNormals())
  499. in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices;
  500. if (mScene->mMeshes[i]->HasTangentsAndBitangents())
  501. in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices * 2;
  502. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS;++a)
  503. {
  504. if (mScene->mMeshes[i]->HasVertexColors(a))
  505. in.meshes += sizeof(aiColor4D) * mScene->mMeshes[i]->mNumVertices;
  506. else break;
  507. }
  508. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS;++a)
  509. {
  510. if (mScene->mMeshes[i]->HasTextureCoords(a))
  511. in.meshes += sizeof(aiVector3D) * mScene->mMeshes[i]->mNumVertices;
  512. else break;
  513. }
  514. if (mScene->mMeshes[i]->HasBones())
  515. {
  516. in.meshes += sizeof(void*) * mScene->mMeshes[i]->mNumBones;
  517. for (unsigned int p = 0; p < mScene->mMeshes[i]->mNumBones;++p)
  518. {
  519. in.meshes += sizeof(aiBone);
  520. in.meshes += mScene->mMeshes[i]->mBones[p]->mNumWeights * sizeof(aiVertexWeight);
  521. }
  522. }
  523. in.meshes += (sizeof(aiFace) + 3 * sizeof(unsigned int))*mScene->mMeshes[i]->mNumFaces;
  524. }
  525. in.total += in.meshes;
  526. // add all embedded textures
  527. for (unsigned int i = 0; i < mScene->mNumTextures;++i)
  528. {
  529. const aiTexture* pc = mScene->mTextures[i];
  530. in.textures += sizeof(aiTexture);
  531. if (pc->mHeight)
  532. {
  533. in.textures += 4 * pc->mHeight * pc->mWidth;
  534. }
  535. else in.textures += pc->mWidth;
  536. }
  537. in.total += in.textures;
  538. // add all animations
  539. for (unsigned int i = 0; i < mScene->mNumAnimations;++i)
  540. {
  541. const aiAnimation* pc = mScene->mAnimations[i];
  542. in.animations += sizeof(aiAnimation);
  543. // add all bone anims
  544. for (unsigned int a = 0; a < pc->mNumBones;++a)
  545. {
  546. const aiBoneAnim* pc2 = pc->mBones[i];
  547. in.animations += sizeof(aiBoneAnim);
  548. in.animations += pc2->mNumPositionKeys * sizeof(aiVectorKey);
  549. in.animations += pc2->mNumScalingKeys * sizeof(aiVectorKey);
  550. in.animations += pc2->mNumRotationKeys * sizeof(aiQuatKey);
  551. }
  552. }
  553. in.total += in.animations;
  554. // add all nodes
  555. AddNodeWeight(in.nodes,mScene->mRootNode);
  556. in.total += in.nodes;
  557. // add all materials
  558. for (unsigned int i = 0; i < mScene->mNumMaterials;++i)
  559. {
  560. const aiMaterial* pc = mScene->mMaterials[i];
  561. in.materials += sizeof(aiMaterial);
  562. in.materials += pc->mNumAllocated * sizeof(void*);
  563. for (unsigned int a = 0; a < pc->mNumProperties;++a)
  564. {
  565. in.materials += pc->mProperties[a]->mDataLength;
  566. }
  567. }
  568. in.total += in.materials;
  569. return;
  570. }