MD5Loader.cpp 20 KB

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