Importer.cpp 19 KB

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