MS3DLoader.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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 MS3DLoader.cpp
  35. * @brief Implementation of the Ms3D importer class.
  36. * Written against http://chumbalum.swissquake.ch/ms3d/ms3dspec.txt
  37. */
  38. #include "AssimpPCH.h"
  39. #ifndef ASSIMP_BUILD_NO_MS3D_IMPORTER
  40. // internal headers
  41. #include "MS3DLoader.h"
  42. #include "StreamReader.h"
  43. using namespace Assimp;
  44. // ------------------------------------------------------------------------------------------------
  45. // Constructor to be privately used by Importer
  46. MS3DImporter::MS3DImporter()
  47. {}
  48. // ------------------------------------------------------------------------------------------------
  49. // Destructor, private as well
  50. MS3DImporter::~MS3DImporter()
  51. {}
  52. // ------------------------------------------------------------------------------------------------
  53. // Returns whether the class can handle the format of the given file.
  54. bool MS3DImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
  55. {
  56. // first call - simple extension check
  57. const std::string extension = GetExtension(pFile);
  58. if (extension == "ms3d") {
  59. return true;
  60. }
  61. // second call - check for magic identifiers
  62. else if (!extension.length() || checkSig) {
  63. if (!pIOHandler) {
  64. return true;
  65. }
  66. const char* tokens[] = {"MS3D000000"};
  67. return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1);
  68. }
  69. return false;
  70. }
  71. // ------------------------------------------------------------------------------------------------
  72. void MS3DImporter::GetExtensionList(std::set<std::string>& extensions)
  73. {
  74. extensions.insert("ms3d");
  75. }
  76. // ------------------------------------------------------------------------------------------------
  77. void ReadColor(StreamReaderLE& stream, aiColor4D& ambient)
  78. {
  79. // aiColor4D is packed on gcc, implicit binding to float& fails therefore.
  80. stream >> (float&)ambient.r >> (float&)ambient.g >> (float&)ambient.b >> (float&)ambient.a;
  81. }
  82. // ------------------------------------------------------------------------------------------------
  83. void ReadVector(StreamReaderLE& stream, aiVector3D& pos)
  84. {
  85. // See note in ReadColor()
  86. stream >> (float&)pos.x >> (float&)pos.y >> (float&)pos.z;
  87. }
  88. // ------------------------------------------------------------------------------------------------
  89. template<typename T>
  90. void MS3DImporter :: ReadComments(StreamReaderLE& stream, std::vector<T>& outp)
  91. {
  92. uint16_t cnt;
  93. stream >> cnt;
  94. for(unsigned int i = 0; i < cnt; ++i) {
  95. uint32_t index, clength;
  96. stream >> index >> clength;
  97. if(index >= outp.size()) {
  98. DefaultLogger::get()->warn("MS3D: Invalid index in comment section");
  99. }
  100. else {
  101. outp[index].comment = std::string(reinterpret_cast<char*>(stream.GetPtr()),clength);
  102. }
  103. stream.IncPtr(clength);
  104. }
  105. }
  106. // ------------------------------------------------------------------------------------------------
  107. template <typename T, typename T2, typename T3> bool inrange(const T& in, const T2& lower, const T3& higher)
  108. {
  109. return in > lower && in <= higher;
  110. }
  111. // ------------------------------------------------------------------------------------------------
  112. void MS3DImporter :: CollectChildJoints(const std::vector<TempJoint>& joints,
  113. std::vector<bool>& hadit,
  114. aiNode* nd,
  115. const aiMatrix4x4& absTrafo)
  116. {
  117. unsigned int cnt = 0;
  118. for(size_t i = 0; i < joints.size(); ++i) {
  119. if (!hadit[i] && !strcmp(joints[i].parentName,nd->mName.data)) {
  120. ++cnt;
  121. }
  122. }
  123. nd->mChildren = new aiNode*[nd->mNumChildren = cnt];
  124. cnt = 0;
  125. for(size_t i = 0; i < joints.size(); ++i) {
  126. if (!hadit[i] && !strcmp(joints[i].parentName,nd->mName.data)) {
  127. aiNode* ch = nd->mChildren[cnt++] = new aiNode(joints[i].name);
  128. ch->mParent = nd;
  129. const aiVector3D& qin = joints[i].rotation;
  130. ch->mTransformation = aiMatrix4x4().FromEulerAnglesXYZ(qin.x,qin.y,qin.z)*
  131. aiMatrix4x4::Translation(joints[i].position,ch->mTransformation);
  132. const aiMatrix4x4 abs = absTrafo*ch->mTransformation;
  133. for(unsigned int a = 0; a < mScene->mNumMeshes; ++a) {
  134. aiMesh* const msh = mScene->mMeshes[a];
  135. for(unsigned int n = 0; n < msh->mNumBones; ++n) {
  136. aiBone* const bone = msh->mBones[n];
  137. if(bone->mName == ch->mName) {
  138. bone->mOffsetMatrix = aiMatrix4x4(abs).Inverse();
  139. }
  140. }
  141. }
  142. hadit[i] = true;
  143. CollectChildJoints(joints,hadit,ch,abs);
  144. }
  145. }
  146. }
  147. // ------------------------------------------------------------------------------------------------
  148. void MS3DImporter :: CollectChildJoints(const std::vector<TempJoint>& joints, aiNode* nd)
  149. {
  150. std::vector<bool> hadit(joints.size(),false);
  151. aiMatrix4x4 trafo;
  152. CollectChildJoints(joints,hadit,nd,trafo);
  153. }
  154. // ------------------------------------------------------------------------------------------------
  155. // Imports the given file into the given scene structure.
  156. void MS3DImporter::InternReadFile( const std::string& pFile,
  157. aiScene* pScene, IOSystem* pIOHandler)
  158. {
  159. StreamReaderLE stream(pIOHandler->Open(pFile,"rb"));
  160. // CanRead() should have done this already
  161. char head[10];
  162. int32_t version;
  163. mScene = pScene;
  164. // 1 ------------ read into temporary data structures mirroring the original file
  165. stream.CopyAndAdvance(head,10);
  166. stream >> version;
  167. if (strncmp(head,"MS3D000000",10)) {
  168. throw new ImportErrorException("Not a MS3D file, magic string MS3D000000 not found: "+pFile);
  169. }
  170. if (version != 4) {
  171. throw new ImportErrorException("MS3D: Unsupported file format version, 4 was expected");
  172. }
  173. uint16_t verts;
  174. stream >> verts;
  175. std::vector<TempVertex> vertices(verts);
  176. for (unsigned int i = 0; i < verts; ++i) {
  177. TempVertex& v = vertices[i];
  178. stream.IncPtr(1);
  179. ReadVector(stream,v.pos);
  180. v.bone_id[0] = stream.GetI1();
  181. v.ref_cnt = stream.GetI1();
  182. v.bone_id[1] = v.bone_id[2] = v.bone_id[3] = 0xffffffff;
  183. v.weights[1] = v.weights[2] = v.weights[3] = 0.f;
  184. v.weights[0] = 1.f;
  185. }
  186. uint16_t tris;
  187. stream >> tris;
  188. std::vector<TempTriangle> triangles(tris);
  189. for (unsigned int i = 0;i < tris; ++i) {
  190. TempTriangle& t = triangles[i];
  191. stream.IncPtr(2);
  192. for (unsigned int i = 0; i < 3; ++i) {
  193. t.indices[i] = stream.GetI2();
  194. }
  195. for (unsigned int i = 0; i < 3; ++i) {
  196. ReadVector(stream,t.normals[i]);
  197. }
  198. for (unsigned int i = 0; i < 3; ++i) {
  199. stream >> (float&)(t.uv[i].x); // see note in ReadColor()
  200. }
  201. for (unsigned int i = 0; i < 3; ++i) {
  202. stream >> (float&)(t.uv[i].y);
  203. }
  204. t.sg = stream.GetI1();
  205. t.group = stream.GetI1();
  206. }
  207. uint16_t grp;
  208. stream >> grp;
  209. bool need_default = false;
  210. std::vector<TempGroup> groups(grp);
  211. for (unsigned int i = 0;i < grp; ++i) {
  212. TempGroup& t = groups[i];
  213. stream.IncPtr(1);
  214. stream.CopyAndAdvance(t.name,32);
  215. t.name[32] = '\0';
  216. uint16_t num;
  217. stream >> num;
  218. t.triangles.resize(num);
  219. for (unsigned int i = 0; i < num; ++i) {
  220. t.triangles[i] = stream.GetI2();
  221. }
  222. t.mat = stream.GetI1();
  223. if (t.mat == 0xff) {
  224. need_default = true;
  225. }
  226. }
  227. uint16_t mat;
  228. stream >> mat;
  229. std::vector<TempMaterial> materials(mat);
  230. for (unsigned int i = 0;i < mat; ++i) {
  231. TempMaterial& t = materials[i];
  232. stream.CopyAndAdvance(t.name,32);
  233. t.name[32] = '\0';
  234. ReadColor(stream,t.ambient);
  235. ReadColor(stream,t.diffuse);
  236. ReadColor(stream,t.specular);
  237. ReadColor(stream,t.emissive);
  238. stream >> t.shininess >> t.transparency;
  239. stream.IncPtr(1);
  240. stream.CopyAndAdvance(t.texture,128);
  241. t.texture[128] = '\0';
  242. stream.CopyAndAdvance(t.alphamap,128);
  243. t.alphamap[128] = '\0';
  244. }
  245. float animfps, currenttime;
  246. uint32_t totalframes;
  247. stream >> animfps >> currenttime >> totalframes;
  248. uint16_t joint;
  249. stream >> joint;
  250. std::vector<TempJoint> joints(joint);
  251. for(unsigned int i = 0; i < joint; ++i) {
  252. TempJoint& j = joints[i];
  253. stream.IncPtr(1);
  254. stream.CopyAndAdvance(j.name,32);
  255. j.name[32] = '\0';
  256. stream.CopyAndAdvance(j.parentName,32);
  257. j.parentName[32] = '\0';
  258. // DefaultLogger::get()->debug(j.name);
  259. // DefaultLogger::get()->debug(j.parentName);
  260. ReadVector(stream,j.rotation);
  261. ReadVector(stream,j.position);
  262. j.rotFrames.resize(stream.GetI2());
  263. j.posFrames.resize(stream.GetI2());
  264. for(unsigned int a = 0; a < j.rotFrames.size(); ++a) {
  265. TempKeyFrame& kf = j.rotFrames[a];
  266. stream >> kf.time;
  267. ReadVector(stream,kf.value);
  268. }
  269. for(unsigned int a = 0; a < j.posFrames.size(); ++a) {
  270. TempKeyFrame& kf = j.posFrames[a];
  271. stream >> kf.time;
  272. ReadVector(stream,kf.value);
  273. }
  274. }
  275. if(stream.GetRemainingSize() > 4) {
  276. uint32_t subversion;
  277. stream >> subversion;
  278. if (subversion == 1) {
  279. ReadComments<TempGroup>(stream,groups);
  280. ReadComments<TempMaterial>(stream,materials);
  281. ReadComments<TempJoint>(stream,joints);
  282. ReadComments<TempModel>(stream,std::vector<TempModel>() = std::vector<TempModel>());
  283. if(stream.GetRemainingSize() > 4 && inrange((stream >> subversion,subversion),1u,3u)) {
  284. for(unsigned int i = 0; i < verts; ++i) {
  285. TempVertex& v = vertices[i];
  286. v.weights[3]=1.f;
  287. for(unsigned int n = 0; n < 3; v.weights[3]-=v.weights[n++]) {
  288. v.bone_id[n+1] = stream.GetI1();
  289. v.weights[n] = static_cast<float>(static_cast<unsigned int>(stream.GetI1()))/255.f;
  290. }
  291. stream.IncPtr((subversion-1)<<2u);
  292. }
  293. // even further extra data is not of interest for us, at least now now.
  294. }
  295. }
  296. }
  297. // 2 ------------ convert to proper aiXX data structures -----------------------------------
  298. if (need_default && materials.size()) {
  299. DefaultLogger::get()->warn("MS3D: Found group with no material assigned, spawning default material");
  300. // if one of the groups has no material assigned, but there are other
  301. // groups with materials, a default material needs to be added (
  302. // scenepreprocessor adds a default material only if nummat==0).
  303. materials.push_back(TempMaterial());
  304. TempMaterial& m = materials.back();
  305. strcpy(m.name,"<MS3D_DefaultMat>");
  306. m.diffuse = aiColor4D(0.6f,0.6f,0.6f,1.0);
  307. m.transparency = 1.f;
  308. m.shininess = 0.f;
  309. for (unsigned int i = 0; i < groups.size(); ++i) {
  310. TempGroup& g = groups[i];
  311. if (g.mat == 0xff) {
  312. g.mat = materials.size()-1;
  313. }
  314. }
  315. }
  316. // convert materials to our generic key-value dict-alike
  317. if (materials.size()) {
  318. pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials=static_cast<unsigned int>(materials.size())];
  319. for (unsigned int i = 0; i < pScene->mNumMaterials; ++i) {
  320. MaterialHelper* mo = new MaterialHelper();
  321. pScene->mMaterials[i] = mo;
  322. const TempMaterial& mi = materials[i];
  323. aiString tmp;
  324. if (0[mi.alphamap]) {
  325. tmp = aiString(mi.alphamap);
  326. mo->AddProperty(&tmp,AI_MATKEY_TEXTURE_OPACITY(0));
  327. }
  328. if (0[mi.texture]) {
  329. tmp = aiString(mi.texture);
  330. mo->AddProperty(&tmp,AI_MATKEY_TEXTURE_DIFFUSE(0));
  331. }
  332. if (0[mi.name]) {
  333. tmp = aiString(mi.name);
  334. mo->AddProperty(&tmp,AI_MATKEY_NAME);
  335. }
  336. mo->AddProperty(&mi.ambient,1,AI_MATKEY_COLOR_AMBIENT);
  337. mo->AddProperty(&mi.diffuse,1,AI_MATKEY_COLOR_DIFFUSE);
  338. mo->AddProperty(&mi.specular,1,AI_MATKEY_COLOR_SPECULAR);
  339. mo->AddProperty(&mi.emissive,1,AI_MATKEY_COLOR_EMISSIVE);
  340. mo->AddProperty(&mi.shininess,1,AI_MATKEY_SHININESS);
  341. mo->AddProperty(&mi.transparency,1,AI_MATKEY_OPACITY);
  342. const int sm = mi.shininess>0.f?aiShadingMode_Phong:aiShadingMode_Gouraud;
  343. mo->AddProperty(&sm,1,AI_MATKEY_SHADING_MODEL);
  344. }
  345. }
  346. // convert groups to meshes
  347. if (groups.empty()) {
  348. throw new ImportErrorException("MS3D: Didn't get any group records, file is malformed");
  349. }
  350. pScene->mMeshes = new aiMesh*[pScene->mNumMeshes=static_cast<unsigned int>(groups.size())];
  351. for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
  352. aiMesh* m = pScene->mMeshes[i] = new aiMesh();
  353. const TempGroup& g = groups[i];
  354. if (pScene->mNumMaterials && g.mat > pScene->mNumMaterials) {
  355. throw new ImportErrorException("MS3D: Encountered invalid material index, file is malformed");
  356. } // no error if no materials at all - scenepreprocessor adds one then
  357. m->mMaterialIndex = g.mat;
  358. m->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
  359. m->mFaces = new aiFace[m->mNumFaces = g.triangles.size()];
  360. m->mNumVertices = m->mNumFaces*3;
  361. // storage for vertices - verbose format, as requested by the postprocessing pipeline
  362. m->mVertices = new aiVector3D[m->mNumVertices];
  363. m->mNormals = new aiVector3D[m->mNumVertices];
  364. m->mTextureCoords[0] = new aiVector3D[m->mNumVertices];
  365. m->mNumUVComponents[0] = 2;
  366. typedef std::map<unsigned int,unsigned int> BoneSet;
  367. BoneSet mybones;
  368. for (unsigned int i = 0,n = 0; i < m->mNumFaces; ++i) {
  369. aiFace& f = m->mFaces[i];
  370. if (g.triangles[i]>triangles.size()) {
  371. throw new ImportErrorException("MS3D: Encountered invalid triangle index, file is malformed");
  372. }
  373. TempTriangle& t = triangles[g.triangles[i]];
  374. f.mIndices = new unsigned int[f.mNumIndices=3];
  375. for (unsigned int i = 0; i < 3; ++i,++n) {
  376. if (t.indices[i]>vertices.size()) {
  377. throw new ImportErrorException("MS3D: Encountered invalid vertex index, file is malformed");
  378. }
  379. const TempVertex& v = vertices[t.indices[i]];
  380. for(unsigned int a = 0; a < 4; ++a) {
  381. if (v.bone_id[a] != 0xffffffff) {
  382. if (v.bone_id[a] >= joints.size()) {
  383. throw new ImportErrorException("MS3D: Encountered invalid bone index, file is malformed");
  384. }
  385. if (mybones.find(v.bone_id[a]) == mybones.end()) {
  386. mybones[v.bone_id[a]] = 1;
  387. }
  388. else ++mybones[v.bone_id[a]];
  389. }
  390. }
  391. // collect vertex components
  392. m->mVertices[n] = v.pos;
  393. m->mNormals[n] = t.normals[i];
  394. m->mTextureCoords[0][n] = aiVector3D(t.uv[i].x,1.f-t.uv[i].y,0.0);
  395. f.mIndices[i] = n;
  396. }
  397. }
  398. // allocate storage for bones
  399. if(mybones.size()) {
  400. std::vector<unsigned int> bmap(joints.size());
  401. m->mBones = new aiBone*[mybones.size()];
  402. for(BoneSet::const_iterator it = mybones.begin(); it != mybones.end(); ++it) {
  403. aiBone* const bn = m->mBones[m->mNumBones] = new aiBone();
  404. const TempJoint& jnt = joints[(*it).first];
  405. bn->mName.Set(jnt.name);
  406. bn->mWeights = new aiVertexWeight[(*it).second];
  407. bmap[(*it).first] = m->mNumBones++;
  408. }
  409. // .. and collect bone weights
  410. for (unsigned int i = 0,n = 0; i < m->mNumFaces; ++i) {
  411. TempTriangle& t = triangles[g.triangles[i]];
  412. for (unsigned int i = 0; i < 3; ++i,++n) {
  413. const TempVertex& v = vertices[t.indices[i]];
  414. for(unsigned int a = 0; a < 4; ++a) {
  415. const unsigned int bone = v.bone_id[a];
  416. if(bone==0xffffffff){
  417. continue;
  418. }
  419. aiBone* const outbone = m->mBones[bmap[bone]];
  420. aiVertexWeight& outwght = outbone->mWeights[outbone->mNumWeights++];
  421. outwght.mVertexId = n;
  422. outwght.mWeight = v.weights[a];
  423. }
  424. }
  425. }
  426. }
  427. }
  428. // ... add dummy nodes under a single root, each holding a reference to one
  429. // mesh. If we didn't do this, we'd loose the group name.
  430. aiNode* rt = pScene->mRootNode = new aiNode("<MS3DRoot>");
  431. rt->mChildren = new aiNode*[rt->mNumChildren=pScene->mNumMeshes+(joints.size()?1:0)];
  432. for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
  433. aiNode* nd = rt->mChildren[i] = new aiNode();
  434. const TempGroup& g = groups[i];
  435. nd->mName = aiString(g.name);
  436. nd->mParent = rt;
  437. nd->mMeshes = new unsigned int[nd->mNumMeshes = 1];
  438. nd->mMeshes[0] = i;
  439. }
  440. // convert animations as well
  441. if(joints.size()) {
  442. aiNode* jt = rt->mChildren[pScene->mNumMeshes] = new aiNode();
  443. jt->mParent = rt;
  444. CollectChildJoints(joints,jt);
  445. jt->mName.Set("<MS3DJointRoot>");
  446. pScene->mAnimations = new aiAnimation*[ pScene->mNumAnimations = 1 ];
  447. aiAnimation* const anim = pScene->mAnimations[0] = new aiAnimation();
  448. anim->mName.Set("<MS3DMasterAnim>");
  449. // carry the fps info to the user by scaling all times with it
  450. anim->mTicksPerSecond = animfps;
  451. // leave duration at its default, so ScenePreprocessor will fill an appropriate
  452. // value (the values taken from some MS3D files seem to be too unreliable
  453. // to pass the validation)
  454. // anim->mDuration = totalframes/animfps;
  455. anim->mChannels = new aiNodeAnim*[joints.size()]();
  456. for(std::vector<TempJoint>::const_iterator it = joints.begin(); it != joints.end(); ++it) {
  457. if ((*it).rotFrames.empty() && (*it).posFrames.empty()) {
  458. continue;
  459. }
  460. aiNodeAnim* nd = anim->mChannels[anim->mNumChannels++] = new aiNodeAnim();
  461. nd->mNodeName.Set((*it).name);
  462. if ((*it).rotFrames.size()) {
  463. nd->mRotationKeys = new aiQuatKey[(*it).rotFrames.size()];
  464. for(std::vector<TempKeyFrame>::const_iterator rot = (*it).rotFrames.begin(); rot != (*it).rotFrames.end(); ++rot) {
  465. aiQuatKey& q = nd->mRotationKeys[nd->mNumRotationKeys++];
  466. q.mTime = (*rot).time*animfps;
  467. q.mValue = aiQuaternion((*rot).value.x,(*rot).value.y,(*rot).value.z)*
  468. aiQuaternion((*it).rotation.x,(*it).rotation.y,(*it).rotation.z);
  469. }
  470. }
  471. if ((*it).posFrames.size()) {
  472. nd->mPositionKeys = new aiVectorKey[(*it).posFrames.size()];
  473. for(std::vector<TempKeyFrame>::const_iterator pos = (*it).posFrames.begin(); pos != (*it).posFrames.end(); ++pos) {
  474. aiVectorKey& v = nd->mPositionKeys[nd->mNumPositionKeys++];
  475. v.mTime = (*pos).time*animfps;
  476. v.mValue = (*pos).value + (*it).position;
  477. }
  478. }
  479. }
  480. // fixup to pass the validation if not a single animation channel is non-trivial
  481. if (!anim->mNumChannels) {
  482. anim->mChannels = NULL;
  483. }
  484. }
  485. }
  486. #endif