MD5Loader.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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 MD5 importer class */
  35. // internal headers
  36. #include "MaterialSystem.h"
  37. #include "RemoveComments.h"
  38. #include "MD5Loader.h"
  39. #include "StringComparison.h"
  40. #include "fast_atof.h"
  41. // public headers
  42. #include "../include/DefaultLogger.h"
  43. #include "../include/IOStream.h"
  44. #include "../include/IOSystem.h"
  45. #include "../include/aiMesh.h"
  46. #include "../include/aiScene.h"
  47. #include "../include/aiAssert.h"
  48. // boost headers
  49. #include <boost/scoped_ptr.hpp>
  50. using namespace Assimp;
  51. // we're just doing this with static buffers whose size is known at
  52. // compile time, so the compiler should automatically expand to
  53. // sprintf<array_length>(...)
  54. #if _MSC_VER >= 1400
  55. # define sprintf sprintf_s
  56. #endif
  57. // ------------------------------------------------------------------------------------------------
  58. // Constructor to be privately used by Importer
  59. MD5Importer::MD5Importer()
  60. {
  61. // nothing to do here
  62. }
  63. // ------------------------------------------------------------------------------------------------
  64. // Destructor, private as well
  65. MD5Importer::~MD5Importer()
  66. {
  67. // nothing to do here
  68. }
  69. // ------------------------------------------------------------------------------------------------
  70. // Returns whether the class can handle the format of the given file.
  71. bool MD5Importer::CanRead( const std::string& pFile, IOSystem* pIOHandler) const
  72. {
  73. // simple check of file extension is enough for the moment
  74. std::string::size_type pos = pFile.find_last_of('.');
  75. // no file extension - can't read
  76. if( pos == std::string::npos)
  77. return false;
  78. std::string extension = pFile.substr( pos);
  79. if (extension.length() < 4)return false;
  80. if (extension[0] != '.')return false;
  81. if (extension[1] != 'm' && extension[1] != 'M')return false;
  82. if (extension[2] != 'd' && extension[2] != 'D')return false;
  83. if (extension[3] != '5')return false;
  84. return true;
  85. }
  86. // ------------------------------------------------------------------------------------------------
  87. // Imports the given file into the given scene structure.
  88. void MD5Importer::InternReadFile(
  89. const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler)
  90. {
  91. // remove the file extension
  92. std::string::size_type pos = pFile.find_last_of('.');
  93. this->mFile = pFile.substr(0,pos+1);
  94. this->pIOHandler = pIOHandler;
  95. this->pScene = pScene;
  96. bHadMD5Mesh = bHadMD5Anim = false;
  97. // load the animation keyframes
  98. this->LoadMD5AnimFile();
  99. // load the mesh vertices and bones
  100. this->LoadMD5MeshFile();
  101. // make sure we return no incomplete data
  102. if (!bHadMD5Mesh && !bHadMD5Anim)
  103. {
  104. throw new ImportErrorException("Failed to read valid data from this MD5");
  105. }
  106. if (!bHadMD5Mesh)pScene->mFlags |= AI_SCENE_FLAGS_ANIM_SKELETON_ONLY;
  107. }
  108. // ------------------------------------------------------------------------------------------------
  109. void MD5Importer::LoadFileIntoMemory (IOStream* file)
  110. {
  111. ai_assert(NULL != file);
  112. this->fileSize = (unsigned int)file->FileSize();
  113. // allocate storage and copy the contents of the file to a memory buffer
  114. this->pScene = pScene;
  115. this->mBuffer = new char[this->fileSize+1];
  116. file->Read( (void*)mBuffer, 1, this->fileSize);
  117. this->iLineNumber = 1;
  118. // append a terminal 0
  119. this->mBuffer[this->fileSize] = '\0';
  120. // now remove all line comments from the file
  121. CommentRemover::RemoveLineComments("//",this->mBuffer,' ');
  122. }
  123. // ------------------------------------------------------------------------------------------------
  124. void MD5Importer::UnloadFileFromMemory ()
  125. {
  126. // delete the file buffer
  127. delete[] this->mBuffer;
  128. this->mBuffer = NULL;
  129. this->fileSize = 0;
  130. }
  131. // ------------------------------------------------------------------------------------------------
  132. void MakeDataUnique (MD5::MeshDesc& meshSrc)
  133. {
  134. std::vector<bool> abHad(meshSrc.mVertices.size(),false);
  135. // allocate enough storage to keep the output structures
  136. const unsigned int iNewNum = (unsigned int)meshSrc.mFaces.size()*3;
  137. unsigned int iNewIndex = (unsigned int)meshSrc.mVertices.size();
  138. meshSrc.mVertices.resize(iNewNum);
  139. // try to guess how much storage we'll need for new weights
  140. const float fWeightsPerVert = meshSrc.mWeights.size() / (float)iNewIndex;
  141. const unsigned int guess = (unsigned int)(fWeightsPerVert*iNewNum);
  142. meshSrc.mWeights.reserve(guess + (guess >> 3)); // + 12.5% as buffer
  143. for (FaceList::const_iterator iter = meshSrc.mFaces.begin(),iterEnd = meshSrc.mFaces.end();
  144. iter != iterEnd;++iter)
  145. {
  146. const aiFace& face = *iter;
  147. for (unsigned int i = 0; i < 3;++i)
  148. {
  149. if (abHad[face.mIndices[i]])
  150. {
  151. // generate a new vertex
  152. meshSrc.mVertices[iNewIndex] = meshSrc.mVertices[face.mIndices[i]];
  153. face.mIndices[i] = iNewIndex++;
  154. // FIX: removed this ...
  155. #if 0
  156. // the algorithm in MD5Importer::LoadMD5MeshFile() doesn't work if
  157. // a weight is referenced by more than one vertex. This shouldn't
  158. // occur in MD5 files, but we must take care that we generate new
  159. // weights now, too.
  160. vertNew.mFirstWeight = (unsigned int)meshSrc.mWeights.size();
  161. meshSrc.mWeights.resize(vertNew.mFirstWeight+vertNew.mNumWeights);
  162. for (unsigned int q = 0; q < vertNew.mNumWeights;++q)
  163. {
  164. meshSrc.mWeights[vertNew.mFirstWeight+q] = meshSrc.mWeights[vertOld.mFirstWeight+q];
  165. }
  166. #endif
  167. }
  168. else abHad[face.mIndices[i]] = true;
  169. }
  170. }
  171. }
  172. // ------------------------------------------------------------------------------------------------
  173. void AttachChilds(int iParentID,aiNode* piParent,BoneList& bones)
  174. {
  175. ai_assert(NULL != piParent && !piParent->mNumChildren);
  176. for (unsigned int i = 0; i < bones.size();++i)
  177. {
  178. // (avoid infinite recursion)
  179. if (iParentID != i && bones[i].mParentIndex == iParentID)
  180. {
  181. // have it ...
  182. ++piParent->mNumChildren;
  183. }
  184. }
  185. if (piParent->mNumChildren)
  186. {
  187. piParent->mChildren = new aiNode*[piParent->mNumChildren];
  188. for (unsigned int i = 0; i < bones.size();++i)
  189. {
  190. // (avoid infinite recursion)
  191. if (iParentID != i && bones[i].mParentIndex == iParentID)
  192. {
  193. aiNode* pc;
  194. *piParent->mChildren++ = pc = new aiNode();
  195. pc->mName = aiString(bones[i].mName);
  196. pc->mParent = piParent;
  197. // get the transformation matrix from rotation and translational components
  198. aiQuaternion quat = aiQuaternion ( bones[i].mRotationQuat );
  199. //quat.w *= -1.0f; // DX to OGL
  200. pc->mTransformation = aiMatrix4x4 ( quat.GetMatrix());
  201. aiMatrix4x4 mTranslate;
  202. mTranslate.a4 = bones[i].mPositionXYZ.x;
  203. mTranslate.b4 = bones[i].mPositionXYZ.y;
  204. mTranslate.c4 = bones[i].mPositionXYZ.z;
  205. pc->mTransformation = pc->mTransformation*mTranslate;
  206. // store it for later use
  207. bones[i].mTransform = bones[i].mInvTransform = pc->mTransformation;
  208. bones[i].mInvTransform.Inverse();
  209. // the transformations for each bone are absolute,
  210. // so we need to multiply them with the inverse
  211. // of the absolut matrix of the parent
  212. if (-1 != iParentID)
  213. {
  214. pc->mTransformation = bones[iParentID].mInvTransform*pc->mTransformation;
  215. }
  216. // add children to this node, too
  217. AttachChilds( i, pc, bones);
  218. }
  219. }
  220. // undo our nice shift
  221. piParent->mChildren -= piParent->mNumChildren;
  222. }
  223. }
  224. // ------------------------------------------------------------------------------------------------
  225. void MD5Importer::LoadMD5MeshFile ()
  226. {
  227. std::string pFile = this->mFile + "MD5MESH";
  228. boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile, "rb"));
  229. // Check whether we can read from the file
  230. if( file.get() == NULL)
  231. {
  232. DefaultLogger::get()->warn("Failed to read MD5 mesh file: " + pFile);
  233. return;
  234. }
  235. bHadMD5Mesh = true;
  236. // now load the file into memory
  237. this->LoadFileIntoMemory(file.get());
  238. // now construct a parser and parse the file
  239. MD5::MD5Parser parser(mBuffer,fileSize);
  240. // load the mesh information from it
  241. MD5::MD5MeshParser meshParser(parser.mSections);
  242. // create the bone hierarchy - first the root node
  243. // and dummy nodes for all meshes
  244. pScene->mRootNode = new aiNode();
  245. pScene->mRootNode->mNumChildren = 2;
  246. pScene->mRootNode->mChildren = new aiNode*[2];
  247. aiNode* pcNode = pScene->mRootNode->mChildren[0] = new aiNode();
  248. pcNode->mNumMeshes = (unsigned int)meshParser.mMeshes.size();
  249. pcNode->mMeshes = new unsigned int[pcNode->mNumMeshes];
  250. pcNode->mName.Set("MD5Mesh");
  251. pcNode->mParent = pScene->mRootNode;
  252. for (unsigned int i = 0; i < pcNode->mNumMeshes;++i)
  253. {
  254. pcNode->mMeshes[i] = i;
  255. }
  256. // now create the hierarchy of animated bones
  257. pcNode = pScene->mRootNode->mChildren[1] = new aiNode();
  258. pcNode->mName.Set("MD5Anim");
  259. pcNode->mParent = pScene->mRootNode;
  260. AttachChilds(-1,pcNode,meshParser.mJoints);
  261. // generate all meshes
  262. pScene->mNumMeshes = pScene->mNumMaterials = (unsigned int)meshParser.mMeshes.size();
  263. pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
  264. pScene->mMaterials = new aiMaterial*[pScene->mNumMeshes];
  265. for (unsigned int i = 0; i < pScene->mNumMeshes;++i)
  266. {
  267. aiMesh* mesh = pScene->mMeshes[i] = new aiMesh();
  268. MD5::MeshDesc& meshSrc = meshParser.mMeshes[i];
  269. // generate unique vertices in our internal verbose format
  270. MakeDataUnique(meshSrc);
  271. mesh->mNumVertices = (unsigned int) meshSrc.mVertices.size();
  272. mesh->mVertices = new aiVector3D[mesh->mNumVertices];
  273. mesh->mTextureCoords[0] = new aiVector3D[mesh->mNumVertices];
  274. mesh->mNumUVComponents[0] = 2;
  275. // copy texture coordinates
  276. aiVector3D* pv = mesh->mTextureCoords[0];
  277. for (MD5::VertexList::const_iterator
  278. iter = meshSrc.mVertices.begin();
  279. iter != meshSrc.mVertices.end();++iter,++pv)
  280. {
  281. pv->x = (*iter).mUV.x;
  282. pv->y = 1.0f-(*iter).mUV.y; // D3D to OpenGL
  283. pv->z = 0.0f;
  284. }
  285. // sort all bone weights - per bone
  286. unsigned int* piCount = new unsigned int[meshParser.mJoints.size()];
  287. ::memset(piCount,0,sizeof(unsigned int)*meshParser.mJoints.size());
  288. for (MD5::VertexList::const_iterator
  289. iter = meshSrc.mVertices.begin();
  290. iter != meshSrc.mVertices.end();++iter,++pv)
  291. {
  292. for (unsigned int jub = (*iter).mFirstWeight, w = jub; w < jub + (*iter).mNumWeights;++w)
  293. {
  294. MD5::WeightDesc& desc = meshSrc.mWeights[w];
  295. ++piCount[desc.mBone];
  296. }
  297. }
  298. // check how many we will need
  299. for (unsigned int p = 0; p < meshParser.mJoints.size();++p)
  300. if (piCount[p])mesh->mNumBones++;
  301. if (mesh->mNumBones) // just for safety
  302. {
  303. mesh->mBones = new aiBone*[mesh->mNumBones];
  304. for (unsigned int q = 0,h = 0; q < meshParser.mJoints.size();++q)
  305. {
  306. if (!piCount[q])continue;
  307. aiBone* p = mesh->mBones[h] = new aiBone();
  308. p->mNumWeights = piCount[q];
  309. p->mWeights = new aiVertexWeight[p->mNumWeights];
  310. p->mName = aiString(meshParser.mJoints[q].mName);
  311. // store the index for later use
  312. meshParser.mJoints[q].mMap = h++;
  313. }
  314. unsigned int g = 0;
  315. pv = mesh->mVertices;
  316. for (MD5::VertexList::const_iterator
  317. iter = meshSrc.mVertices.begin();
  318. iter != meshSrc.mVertices.end();++iter,++pv)
  319. {
  320. // compute the final vertex position from all single weights
  321. *pv = aiVector3D();
  322. // there are models which have weights which don't sum to 1 ...
  323. // granite.md5mesh for example
  324. float fSum = 0.0f;
  325. for (unsigned int jub = (*iter).mFirstWeight, w = jub; w < jub + (*iter).mNumWeights;++w)
  326. fSum += meshSrc.mWeights[w].mWeight;
  327. if (!fSum)throw new ImportErrorException("The sum of all vertex bone weights is 0");
  328. // process bone weights
  329. for (unsigned int jub = (*iter).mFirstWeight, w = jub; w < jub + (*iter).mNumWeights;++w)
  330. {
  331. MD5::WeightDesc& desc = meshSrc.mWeights[w];
  332. float fNewWeight = desc.mWeight / fSum;
  333. // transform the local position into worldspace
  334. MD5::BoneDesc& boneSrc = meshParser.mJoints[desc.mBone];
  335. aiVector3D v = desc.vOffsetPosition;
  336. aiQuaternion quat = aiQuaternion( boneSrc.mRotationQuat );
  337. //quat.w *= -1.0f;
  338. v = quat.GetMatrix() * v;
  339. v += boneSrc.mPositionXYZ;
  340. // use the original weight to compute the vertex position
  341. // (some MD5s seem to depend on the invalid weight values ...)
  342. pv->operator +=(v * desc.mWeight);
  343. aiBone* bone = mesh->mBones[boneSrc.mMap];
  344. *bone->mWeights++ = aiVertexWeight((unsigned int)(pv-mesh->mVertices),fNewWeight);
  345. }
  346. // convert from DOOM coordinate system to OGL
  347. std::swap(pv->z,pv->y);
  348. }
  349. // undo our nice offset tricks ...
  350. for (unsigned int p = 0; p < mesh->mNumBones;++p)
  351. mesh->mBones[p]->mWeights -= mesh->mBones[p]->mNumWeights;
  352. }
  353. delete[] piCount;
  354. // now setup all faces - we can directly copy the list
  355. // (however, take care that the aiFace destructor doesn't delete the mIndices array)
  356. mesh->mNumFaces = (unsigned int)meshSrc.mFaces.size();
  357. mesh->mFaces = new aiFace[mesh->mNumFaces];
  358. for (unsigned int c = 0; c < mesh->mNumFaces;++c)
  359. {
  360. mesh->mFaces[c].mNumIndices = 3;
  361. mesh->mFaces[c].mIndices = meshSrc.mFaces[c].mIndices;
  362. meshSrc.mFaces[c].mIndices = NULL;
  363. }
  364. // generate a material for the mesh
  365. MaterialHelper* mat = new MaterialHelper();
  366. pScene->mMaterials[i] = mat;
  367. mat->AddProperty(&meshSrc.mShader,AI_MATKEY_TEXTURE_DIFFUSE(0));
  368. mesh->mMaterialIndex = i;
  369. }
  370. // delete the file again
  371. this->UnloadFileFromMemory();
  372. }
  373. // ------------------------------------------------------------------------------------------------
  374. void MD5Importer::LoadMD5AnimFile ()
  375. {
  376. std::string pFile = this->mFile + "MD5ANIM";
  377. boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile, "rb"));
  378. // Check whether we can read from the file
  379. if( file.get() == NULL)
  380. {
  381. DefaultLogger::get()->warn("Failed to read MD5 anim file: " + pFile);
  382. return;
  383. }
  384. bHadMD5Anim = true;
  385. // now load the file into memory
  386. this->LoadFileIntoMemory(file.get());
  387. // now construct a parser and parse the file
  388. MD5::MD5Parser parser(mBuffer,fileSize);
  389. // load the animation information from it
  390. MD5::MD5AnimParser animParser(parser.mSections);
  391. // generate and fill the output animation
  392. if (!animParser.mAnimatedBones.empty())
  393. {
  394. pScene->mNumAnimations = 1;
  395. pScene->mAnimations = new aiAnimation*[1];
  396. aiAnimation* anim = pScene->mAnimations[0] = new aiAnimation();
  397. anim->mNumBones = (unsigned int)animParser.mAnimatedBones.size();
  398. anim->mBones = new aiBoneAnim*[anim->mNumBones];
  399. for (unsigned int i = 0; i < anim->mNumBones;++i)
  400. {
  401. aiBoneAnim* bone = anim->mBones[i] = new aiBoneAnim();
  402. bone->mBoneName = aiString( animParser.mAnimatedBones[i].mName );
  403. // allocate storage for the keyframes
  404. bone->mNumPositionKeys = bone->mNumRotationKeys = (unsigned int)animParser.mFrames.size();
  405. bone->mPositionKeys = new aiVectorKey[bone->mNumPositionKeys];
  406. bone->mRotationKeys = new aiQuatKey[bone->mNumPositionKeys];
  407. }
  408. // 1 tick == 1 frame
  409. anim->mTicksPerSecond = animParser.fFrameRate;
  410. for (FrameList::const_iterator iter = animParser.mFrames.begin(),
  411. iterEnd = animParser.mFrames.end();iter != iterEnd;++iter)
  412. {
  413. double dTime = (double)(*iter).iIndex;
  414. if (!(*iter).mValues.empty())
  415. {
  416. // now process all values in there ... read all joints
  417. aiBoneAnim** pcAnimBone = anim->mBones;
  418. MD5::BaseFrameDesc* pcBaseFrame = &animParser.mBaseFrames[0];
  419. for (AnimBoneList::const_iterator
  420. iter2 = animParser.mAnimatedBones.begin(),
  421. iterEnd2 = animParser.mAnimatedBones.end();
  422. iter2 != iterEnd2;++iter2,++pcAnimBone,++pcBaseFrame)
  423. {
  424. if((*iter2).iFirstKeyIndex >= (*iter).mValues.size())
  425. {
  426. // TODO: add proper array checks for all cases here ...
  427. DefaultLogger::get()->error("Keyframe index is out of range. ");
  428. continue;
  429. }
  430. const float* fpCur = &(*iter).mValues[(*iter2).iFirstKeyIndex];
  431. aiBoneAnim* pcCurAnimBone = *pcAnimBone;
  432. aiVectorKey* vKey = pcCurAnimBone->mPositionKeys++;
  433. // translation on the x axis
  434. if ((*iter2).iFlags & AI_MD5_ANIMATION_FLAG_TRANSLATE_X)
  435. vKey->mValue.x = *fpCur++;
  436. else vKey->mValue.x = pcBaseFrame->vPositionXYZ.x;
  437. // translation on the y axis
  438. if ((*iter2).iFlags & AI_MD5_ANIMATION_FLAG_TRANSLATE_Y)
  439. vKey->mValue.y = *fpCur++;
  440. else vKey->mValue.y = pcBaseFrame->vPositionXYZ.y;
  441. // translation on the z axis
  442. if ((*iter2).iFlags & AI_MD5_ANIMATION_FLAG_TRANSLATE_Z)
  443. vKey->mValue.z = *fpCur++;
  444. else vKey->mValue.z = pcBaseFrame->vPositionXYZ.z;
  445. // rotation quaternion, x component
  446. aiQuatKey* qKey = pcCurAnimBone->mRotationKeys++;
  447. aiVector3D vTemp;
  448. if ((*iter2).iFlags & AI_MD5_ANIMATION_FLAG_ROTQUAT_X)
  449. vTemp.x = *fpCur++;
  450. else vTemp.x = pcBaseFrame->vRotationQuat.x;
  451. // rotation quaternion, y component
  452. if ((*iter2).iFlags & AI_MD5_ANIMATION_FLAG_ROTQUAT_Y)
  453. vTemp.y = *fpCur++;
  454. else vTemp.y = pcBaseFrame->vRotationQuat.y;
  455. // rotation quaternion, z component
  456. if ((*iter2).iFlags & AI_MD5_ANIMATION_FLAG_ROTQUAT_Z)
  457. vTemp.z = *fpCur++;
  458. else vTemp.z = pcBaseFrame->vRotationQuat.z;
  459. // compute the w component of the quaternion - invert it (DX to OGL)
  460. qKey->mValue = aiQuaternion(vTemp);
  461. //qKey->mValue.w *= -1.0f;
  462. qKey->mTime = dTime;
  463. vKey->mTime = dTime;
  464. }
  465. }
  466. // compute the duration of the animation
  467. anim->mDuration = std::max(dTime,anim->mDuration);
  468. }
  469. // undo our offset computations
  470. for (unsigned int i = 0; i < anim->mNumBones;++i)
  471. {
  472. aiBoneAnim* bone = anim->mBones[i];
  473. bone->mPositionKeys -= bone->mNumPositionKeys;
  474. bone->mRotationKeys -= bone->mNumPositionKeys;
  475. }
  476. }
  477. // delete the file again
  478. this->UnloadFileFromMemory();
  479. }