SMDLoader.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  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 SMD importer class */
  35. #include "AssimpPCH.h"
  36. // internal headers
  37. #include "SMDLoader.h"
  38. #include "fast_atof.h"
  39. using namespace Assimp;
  40. // ------------------------------------------------------------------------------------------------
  41. // Constructor to be privately used by Importer
  42. SMDImporter::SMDImporter()
  43. {
  44. // nothing to do here
  45. }
  46. // ------------------------------------------------------------------------------------------------
  47. // Destructor, private as well
  48. SMDImporter::~SMDImporter()
  49. {
  50. // nothing to do here
  51. }
  52. // ------------------------------------------------------------------------------------------------
  53. // Returns whether the class can handle the format of the given file.
  54. bool SMDImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler) const
  55. {
  56. // simple check of file extension is enough for the moment
  57. std::string::size_type pos = pFile.find_last_of('.');
  58. // no file extension - can't read
  59. if( pos == std::string::npos)
  60. return false;
  61. std::string extension = pFile.substr( pos);
  62. if (extension.length() < 4)return false;
  63. if (extension[0] != '.')return false;
  64. // VTA is not really supported as it contains vertex animations.
  65. // However, at least the first keyframe can be loaded
  66. if ((extension[1] != 's' && extension[1] != 'S') ||
  67. (extension[2] != 'm' && extension[2] != 'M') ||
  68. (extension[3] != 'd' && extension[3] != 'D'))
  69. {
  70. if ((extension[1] != 'v' && extension[1] != 'V') ||
  71. (extension[2] != 't' && extension[2] != 'T') ||
  72. (extension[3] != 'a' && extension[3] != 'A'))
  73. {
  74. return false;
  75. }
  76. }
  77. return true;
  78. }
  79. // ------------------------------------------------------------------------------------------------
  80. // Setup configuration properties
  81. void SMDImporter::SetupProperties(const Importer* pImp)
  82. {
  83. // The AI_CONFIG_IMPORT_SMD_KEYFRAME option overrides the
  84. // AI_CONFIG_IMPORT_GLOBAL_KEYFRAME option.
  85. if(0xffffffff == (configFrameID = pImp->GetPropertyInteger(
  86. AI_CONFIG_IMPORT_SMD_KEYFRAME,0xffffffff)))
  87. {
  88. configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_GLOBAL_KEYFRAME,0);
  89. }
  90. }
  91. // ------------------------------------------------------------------------------------------------
  92. // Imports the given file into the given scene structure.
  93. void SMDImporter::InternReadFile(
  94. const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler)
  95. {
  96. boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile, "rt"));
  97. // Check whether we can read from the file
  98. if( file.get() == NULL)
  99. {
  100. throw new ImportErrorException( "Failed to open SMD/VTA file " + pFile + ".");
  101. }
  102. iFileSize = (unsigned int)file->FileSize();
  103. // allocate storage and copy the contents of the file to a memory buffer
  104. this->pScene = pScene;
  105. std::vector<char> buff(iFileSize+1);
  106. file->Read( &buff[0], 1, iFileSize);
  107. buff[iFileSize] = '\0';
  108. mBuffer = &buff[0];
  109. iSmallestFrame = (1 << 31);
  110. bHasUVs = true;
  111. iLineNumber = 1;
  112. // reserve enough space for ... hm ... 10 textures
  113. aszTextures.reserve(10);
  114. // reserve enough space for ... hm ... 1000 triangles
  115. asTriangles.reserve(1000);
  116. // reserve enough space for ... hm ... 20 bones
  117. asBones.reserve(20);
  118. // parse the file ...
  119. ParseFile();
  120. // if there are no triangles it seems to be an animation SMD,
  121. // containing only the animation skeleton.
  122. if (asTriangles.empty())
  123. {
  124. if (asBones.empty())
  125. {
  126. throw new ImportErrorException("SMD: No triangles and no bones have "
  127. "been found in the file. This file seems to be invalid.");
  128. }
  129. // set the flag in the scene structure which indicates
  130. // that there is nothing than an animation skeleton
  131. pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
  132. }
  133. if (!asBones.empty())
  134. {
  135. // check whether all bones have been initialized
  136. for (std::vector<SMD::Bone>::const_iterator
  137. i = asBones.begin();
  138. i != asBones.end();++i)
  139. {
  140. if (!(*i).mName.length())
  141. {
  142. DefaultLogger::get()->warn("SMD: Not all bones have been initialized");
  143. break;
  144. }
  145. }
  146. // now fix invalid time values and make sure the animation starts at frame 0
  147. FixTimeValues();
  148. // compute absolute bone transformation matrices
  149. ComputeAbsoluteBoneTransformations();
  150. }
  151. if (!(pScene->mFlags & AI_SCENE_FLAGS_INCOMPLETE))
  152. {
  153. // create output meshes
  154. CreateOutputMeshes();
  155. // build an output material list
  156. CreateOutputMaterials();
  157. }
  158. // build the output animation
  159. CreateOutputAnimations();
  160. // build output nodes (bones are added as empty dummy nodes)
  161. CreateOutputNodes();
  162. }
  163. // ------------------------------------------------------------------------------------------------
  164. // Write an error message with line number to the log file
  165. void SMDImporter::LogErrorNoThrow(const char* msg)
  166. {
  167. char szTemp[1024];
  168. #if _MSC_VER >= 1400
  169. sprintf_s(szTemp,"Line %i: %s",iLineNumber,msg);
  170. #else
  171. ai_assert(strlen(msg) < 1000);
  172. sprintf(szTemp,"Line %i: %s",iLineNumber,msg);
  173. #endif
  174. DefaultLogger::get()->error(szTemp);
  175. }
  176. // ------------------------------------------------------------------------------------------------
  177. // Write a warning with line number to the log file
  178. void SMDImporter::LogWarning(const char* msg)
  179. {
  180. char szTemp[1024];
  181. #if _MSC_VER >= 1400
  182. sprintf_s(szTemp,"Line %i: %s",iLineNumber,msg);
  183. #else
  184. ai_assert(strlen(msg) < 1000);
  185. sprintf(szTemp,"Line %i: %s",iLineNumber,msg);
  186. #endif
  187. DefaultLogger::get()->warn(szTemp);
  188. }
  189. // ------------------------------------------------------------------------------------------------
  190. // Fix invalid time values in the file
  191. void SMDImporter::FixTimeValues()
  192. {
  193. double dDelta = (double)iSmallestFrame;
  194. double dMax = 0.0f;
  195. for (std::vector<SMD::Bone>::iterator
  196. iBone = asBones.begin();
  197. iBone != asBones.end();++iBone)
  198. {
  199. for (std::vector<SMD::Bone::Animation::MatrixKey>::iterator
  200. iKey = (*iBone).sAnim.asKeys.begin();
  201. iKey != (*iBone).sAnim.asKeys.end();++iKey)
  202. {
  203. (*iKey).dTime -= dDelta;
  204. dMax = std::max(dMax, (*iKey).dTime);
  205. }
  206. }
  207. dLengthOfAnim = dMax;
  208. }
  209. // ------------------------------------------------------------------------------------------------
  210. // create output meshes
  211. void SMDImporter::CreateOutputMeshes()
  212. {
  213. // we need to sort all faces by their material index
  214. // in opposition to other loaders we can be sure that each
  215. // material is at least used once.
  216. pScene->mNumMeshes = (unsigned int) aszTextures.size();
  217. pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
  218. typedef std::vector<unsigned int> FaceList;
  219. FaceList* aaiFaces = new FaceList[pScene->mNumMeshes];
  220. // approximate the space that will be required
  221. unsigned int iNum = (unsigned int)asTriangles.size() / pScene->mNumMeshes;
  222. iNum += iNum >> 1;
  223. for (unsigned int i = 0; i < pScene->mNumMeshes;++i)
  224. {
  225. aaiFaces[i].reserve(iNum);
  226. }
  227. // collect all faces
  228. iNum = 0;
  229. for (std::vector<SMD::Face>::const_iterator
  230. iFace = asTriangles.begin();
  231. iFace != asTriangles.end();++iFace,++iNum)
  232. {
  233. if (0xffffffff == (*iFace).iTexture)aaiFaces[(*iFace).iTexture].push_back( 0 );
  234. else if ((*iFace).iTexture >= aszTextures.size())
  235. {
  236. DefaultLogger::get()->error("[SMD/VTA] Material index overflow in face");
  237. aaiFaces[(*iFace).iTexture].push_back((unsigned int)aszTextures.size()-1);
  238. }
  239. else aaiFaces[(*iFace).iTexture].push_back(iNum);
  240. }
  241. // now create the output meshes
  242. for (unsigned int i = 0; i < pScene->mNumMeshes;++i)
  243. {
  244. aiMesh*& pcMesh = pScene->mMeshes[i] = new aiMesh();
  245. ai_assert(!aaiFaces[i].empty()); // should not be empty ...
  246. pcMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
  247. pcMesh->mNumVertices = (unsigned int)aaiFaces[i].size()*3;
  248. pcMesh->mNumFaces = (unsigned int)aaiFaces[i].size();
  249. pcMesh->mMaterialIndex = i;
  250. // storage for bones
  251. typedef std::pair<unsigned int,float> TempWeightListEntry;
  252. typedef std::vector< TempWeightListEntry > TempBoneWeightList;
  253. TempBoneWeightList* aaiBones = new TempBoneWeightList[asBones.size()]();
  254. // try to reserve enough memory without wasting too much
  255. for (unsigned int iBone = 0; iBone < asBones.size();++iBone)
  256. {
  257. aaiBones[iBone].reserve(pcMesh->mNumVertices/asBones.size());
  258. }
  259. // allocate storage
  260. pcMesh->mFaces = new aiFace[pcMesh->mNumFaces];
  261. aiVector3D* pcNormals = pcMesh->mNormals = new aiVector3D[pcMesh->mNumVertices];
  262. aiVector3D* pcVerts = pcMesh->mVertices = new aiVector3D[pcMesh->mNumVertices];
  263. aiVector3D* pcUVs = NULL;
  264. if (bHasUVs)
  265. {
  266. pcUVs = pcMesh->mTextureCoords[0] = new aiVector3D[pcMesh->mNumVertices];
  267. pcMesh->mNumUVComponents[0] = 2;
  268. }
  269. iNum = 0;
  270. for (unsigned int iFace = 0; iFace < pcMesh->mNumFaces;++iFace)
  271. {
  272. pcMesh->mFaces[iFace].mIndices = new unsigned int[3];
  273. pcMesh->mFaces[iFace].mNumIndices = 3;
  274. // fill the vertices
  275. unsigned int iSrcFace = aaiFaces[i][iFace];
  276. SMD::Face& face = asTriangles[iSrcFace];
  277. *pcVerts++ = face.avVertices[0].pos;
  278. *pcVerts++ = face.avVertices[1].pos;
  279. *pcVerts++ = face.avVertices[2].pos;
  280. // fill the normals
  281. *pcNormals++ = face.avVertices[0].nor;
  282. *pcNormals++ = face.avVertices[1].nor;
  283. *pcNormals++ = face.avVertices[2].nor;
  284. // fill the texture coordinates
  285. if (pcUVs)
  286. {
  287. *pcUVs++ = face.avVertices[0].uv;
  288. *pcUVs++ = face.avVertices[1].uv;
  289. *pcUVs++ = face.avVertices[2].uv;
  290. }
  291. for (unsigned int iVert = 0; iVert < 3;++iVert)
  292. {
  293. float fSum = 0.0f;
  294. for (unsigned int iBone = 0;iBone < face.avVertices[iVert].aiBoneLinks.size();++iBone)
  295. {
  296. TempWeightListEntry& pairval = face.avVertices[iVert].aiBoneLinks[iBone];
  297. // FIX: The second check is here just to make sure we won't
  298. // assign more than one weight to a single vertex index
  299. if (pairval.first >= asBones.size() ||
  300. pairval.first == face.avVertices[iVert].iParentNode)
  301. {
  302. DefaultLogger::get()->error("[SMD/VTA] Bone index overflow. "
  303. "The bone index will be ignored, the weight will be assigned "
  304. "to the vertex' parent node");
  305. continue;
  306. }
  307. aaiBones[pairval.first].push_back(TempWeightListEntry(iNum,pairval.second));
  308. fSum += pairval.second;
  309. }
  310. // ******************************************************************
  311. // If the sum of all vertex weights is not 1.0 we must assign
  312. // the rest to the vertex' parent node. Well, at least the doc says
  313. // we should ...
  314. // FIX: We use 0.975 as limit, floating-point inaccuracies seem to
  315. // be very strong in some SMD exporters. Furthermore it is possible
  316. // that the parent of a vertex is 0xffffffff (if the corresponding
  317. // entry in the file was unreadable)
  318. // ******************************************************************
  319. if (fSum < 0.975f && face.avVertices[iVert].iParentNode != 0xffffffff)
  320. {
  321. if (face.avVertices[iVert].iParentNode >= asBones.size())
  322. {
  323. DefaultLogger::get()->error("[SMD/VTA] Bone index overflow. "
  324. "The index of the vertex parent bone is invalid. "
  325. "The remaining weights will be normalized to 1.0");
  326. if (fSum)
  327. {
  328. fSum = 1 / fSum;
  329. for (unsigned int iBone = 0;iBone < face.avVertices[iVert].aiBoneLinks.size();++iBone)
  330. {
  331. TempWeightListEntry& pairval = face.avVertices[iVert].aiBoneLinks[iBone];
  332. if (pairval.first >= asBones.size())continue;
  333. aaiBones[pairval.first].back().second *= fSum;
  334. }
  335. }
  336. }
  337. else
  338. {
  339. aaiBones[face.avVertices[iVert].iParentNode].push_back(
  340. TempWeightListEntry(iNum,1.0f-fSum));
  341. }
  342. }
  343. pcMesh->mFaces[iFace].mIndices[iVert] = iNum++;
  344. }
  345. }
  346. // now build all bones of the mesh
  347. iNum = 0;
  348. for (unsigned int iBone = 0; iBone < asBones.size();++iBone)
  349. {
  350. if (!aaiBones[iBone].empty())++iNum;
  351. }
  352. if (iNum)
  353. {
  354. pcMesh->mNumBones = iNum;
  355. pcMesh->mBones = new aiBone*[pcMesh->mNumBones];
  356. iNum = 0;
  357. for (unsigned int iBone = 0; iBone < asBones.size();++iBone)
  358. {
  359. if (aaiBones[iBone].empty())continue;
  360. aiBone*& bone = pcMesh->mBones[iNum] = new aiBone();
  361. bone->mNumWeights = (unsigned int)aaiBones[iBone].size();
  362. bone->mWeights = new aiVertexWeight[bone->mNumWeights];
  363. bone->mOffsetMatrix = asBones[iBone].mOffsetMatrix;
  364. bone->mName.Set( asBones[iBone].mName );
  365. asBones[iBone].bIsUsed = true;
  366. for (unsigned int iWeight = 0; iWeight < bone->mNumWeights;++iWeight)
  367. {
  368. bone->mWeights[iWeight].mVertexId = aaiBones[iBone][iWeight].first;
  369. bone->mWeights[iWeight].mWeight = aaiBones[iBone][iWeight].second;
  370. }
  371. ++iNum;
  372. }
  373. }
  374. delete[] aaiBones;
  375. }
  376. delete[] aaiFaces;
  377. }
  378. // ------------------------------------------------------------------------------------------------
  379. // add bone child nodes
  380. void SMDImporter::AddBoneChildren(aiNode* pcNode, uint32_t iParent)
  381. {
  382. ai_assert(NULL != pcNode && 0 == pcNode->mNumChildren && NULL == pcNode->mChildren);
  383. // first count ...
  384. for (unsigned int i = 0; i < asBones.size();++i)
  385. {
  386. SMD::Bone& bone = asBones[i];
  387. if (bone.iParent == iParent)++pcNode->mNumChildren;
  388. }
  389. // now allocate the output array
  390. pcNode->mChildren = new aiNode*[pcNode->mNumChildren];
  391. // and fill all subnodes
  392. unsigned int qq = 0;
  393. for (unsigned int i = 0; i < asBones.size();++i)
  394. {
  395. SMD::Bone& bone = asBones[i];
  396. if (bone.iParent != iParent)continue;
  397. aiNode* pc = pcNode->mChildren[qq++] = new aiNode();
  398. pc->mName.Set(bone.mName);
  399. // store the local transformation matrix of the bind pose
  400. pc->mTransformation = bone.sAnim.asKeys[bone.sAnim.iFirstTimeKey].matrix;
  401. pc->mParent = pcNode;
  402. // add children to this node, too
  403. AddBoneChildren(pc,i);
  404. }
  405. }
  406. // ------------------------------------------------------------------------------------------------
  407. // create output nodes
  408. void SMDImporter::CreateOutputNodes()
  409. {
  410. pScene->mRootNode = new aiNode();
  411. if (!(pScene->mFlags & AI_SCENE_FLAGS_INCOMPLETE))
  412. {
  413. // create one root node that renders all meshes
  414. pScene->mRootNode->mNumMeshes = pScene->mNumMeshes;
  415. pScene->mRootNode->mMeshes = new unsigned int[pScene->mNumMeshes];
  416. for (unsigned int i = 0; i < pScene->mNumMeshes;++i)
  417. pScene->mRootNode->mMeshes[i] = i;
  418. }
  419. // now add all bones as dummy sub nodes to the graph
  420. AddBoneChildren(pScene->mRootNode,(uint32_t)-1);
  421. // if we have only one bone we can even remove the root node
  422. if (pScene->mFlags & AI_SCENE_FLAGS_INCOMPLETE &&
  423. 1 == pScene->mRootNode->mNumChildren)
  424. {
  425. aiNode* pcOldRoot = pScene->mRootNode;
  426. pScene->mRootNode = pcOldRoot->mChildren[0];
  427. pcOldRoot->mChildren[0] = NULL;
  428. delete pcOldRoot;
  429. pScene->mRootNode->mParent = NULL;
  430. }
  431. else
  432. {
  433. ::strcpy(pScene->mRootNode->mName.data, "<SMD_root>");
  434. pScene->mRootNode->mName.length = 10;
  435. }
  436. }
  437. // ------------------------------------------------------------------------------------------------
  438. // create output animations
  439. void SMDImporter::CreateOutputAnimations()
  440. {
  441. unsigned int iNumBones = 0;
  442. for (std::vector<SMD::Bone>::const_iterator
  443. i = asBones.begin();
  444. i != asBones.end();++i)
  445. {
  446. if ((*i).bIsUsed)++iNumBones;
  447. }
  448. if (!iNumBones)
  449. {
  450. // just make sure this case doesn't occur ... (it could occur
  451. // if the file was invalid)
  452. return;
  453. }
  454. pScene->mNumAnimations = 1;
  455. pScene->mAnimations = new aiAnimation*[1];
  456. aiAnimation*& anim = pScene->mAnimations[0] = new aiAnimation();
  457. anim->mDuration = dLengthOfAnim;
  458. anim->mNumChannels = iNumBones;
  459. anim->mTicksPerSecond = 25.0; // FIXME: is this correct?
  460. aiNodeAnim** pp = anim->mChannels = new aiNodeAnim*[anim->mNumChannels];
  461. // now build valid keys
  462. unsigned int a = 0;
  463. for (std::vector<SMD::Bone>::const_iterator
  464. i = asBones.begin();
  465. i != asBones.end();++i)
  466. {
  467. if (!(*i).bIsUsed)continue;
  468. aiNodeAnim* p = pp[a] = new aiNodeAnim();
  469. // copy the name of the bone
  470. p->mNodeName.Set( i->mName);
  471. p->mNumRotationKeys = (unsigned int) (*i).sAnim.asKeys.size();
  472. if (p->mNumRotationKeys)
  473. {
  474. p->mNumPositionKeys = p->mNumRotationKeys;
  475. aiVectorKey* pVecKeys = p->mPositionKeys = new aiVectorKey[p->mNumRotationKeys];
  476. aiQuatKey* pRotKeys = p->mRotationKeys = new aiQuatKey[p->mNumRotationKeys];
  477. for (std::vector<SMD::Bone::Animation::MatrixKey>::const_iterator
  478. qq = (*i).sAnim.asKeys.begin();
  479. qq != (*i).sAnim.asKeys.end(); ++qq)
  480. {
  481. pRotKeys->mTime = pVecKeys->mTime = (*qq).dTime;
  482. // compute the rotation quaternion from the euler angles
  483. pRotKeys->mValue = aiQuaternion( (*qq).vRot.x, (*qq).vRot.y, (*qq).vRot.z );
  484. pVecKeys->mValue = (*qq).vPos;
  485. ++pVecKeys; ++pRotKeys;
  486. }
  487. }
  488. ++a;
  489. // there are no scaling keys ...
  490. }
  491. }
  492. // ------------------------------------------------------------------------------------------------
  493. void SMDImporter::ComputeAbsoluteBoneTransformations()
  494. {
  495. // for each bone: determine the key with the lowest time value
  496. // theoretically the SMD format should have all keyframes
  497. // in order. However, I've seen a file where this wasn't true.
  498. for (unsigned int i = 0; i < asBones.size();++i)
  499. {
  500. SMD::Bone& bone = asBones[i];
  501. uint32_t iIndex = 0;
  502. double dMin = 10e10;
  503. for (unsigned int i = 0; i < bone.sAnim.asKeys.size();++i)
  504. {
  505. double d = std::min(bone.sAnim.asKeys[i].dTime,dMin);
  506. if (d < dMin)
  507. {
  508. dMin = d;
  509. iIndex = i;
  510. }
  511. }
  512. bone.sAnim.iFirstTimeKey = iIndex;
  513. }
  514. unsigned int iParent = 0;
  515. while (iParent < asBones.size())
  516. {
  517. for (unsigned int iBone = 0; iBone < asBones.size();++iBone)
  518. {
  519. SMD::Bone& bone = asBones[iBone];
  520. if (iParent == bone.iParent)
  521. {
  522. SMD::Bone& parentBone = asBones[iParent];
  523. uint32_t iIndex = bone.sAnim.iFirstTimeKey;
  524. const aiMatrix4x4& mat = bone.sAnim.asKeys[iIndex].matrix;
  525. aiMatrix4x4& matOut = bone.sAnim.asKeys[iIndex].matrixAbsolute;
  526. // the same for the parent bone ...
  527. iIndex = parentBone.sAnim.iFirstTimeKey;
  528. const aiMatrix4x4& mat2 = parentBone.sAnim.asKeys[iIndex].matrix;
  529. // compute the absolute transformation matrix
  530. matOut = mat * mat2;
  531. }
  532. }
  533. ++iParent;
  534. }
  535. // store the inverse of the absolute transformation matrix
  536. // of the first key as bone offset matrix
  537. for (iParent = 0; iParent < asBones.size();++iParent)
  538. {
  539. SMD::Bone& bone = asBones[iParent];
  540. aiMatrix4x4& mat = bone.sAnim.asKeys[bone.sAnim.iFirstTimeKey].matrixAbsolute;
  541. bone.mOffsetMatrix = mat;
  542. bone.mOffsetMatrix.Inverse();
  543. }
  544. }
  545. // ------------------------------------------------------------------------------------------------
  546. // create output materials
  547. void SMDImporter::CreateOutputMaterials()
  548. {
  549. pScene->mNumMaterials = (unsigned int)aszTextures.size();
  550. pScene->mMaterials = new aiMaterial*[std::max(1u, pScene->mNumMaterials)];
  551. for (unsigned int iMat = 0; iMat < pScene->mNumMaterials;++iMat)
  552. {
  553. MaterialHelper* pcMat = new MaterialHelper();
  554. pScene->mMaterials[iMat] = pcMat;
  555. aiString szName;
  556. szName.length = (size_t)::sprintf(szName.data,"Texture_%i",iMat);
  557. pcMat->AddProperty(&szName,AI_MATKEY_NAME);
  558. ::strcpy(szName.data, aszTextures[iMat].c_str() );
  559. szName.length = aszTextures[iMat].length();
  560. pcMat->AddProperty(&szName,AI_MATKEY_TEXTURE_DIFFUSE(0));
  561. }
  562. // create a default material if necessary
  563. if (0 == pScene->mNumMaterials)
  564. {
  565. pScene->mNumMaterials = 1;
  566. MaterialHelper* pcHelper = new MaterialHelper();
  567. pScene->mMaterials[0] = pcHelper;
  568. int iMode = (int)aiShadingMode_Gouraud;
  569. pcHelper->AddProperty<int>(&iMode, 1, AI_MATKEY_SHADING_MODEL);
  570. aiColor3D clr;
  571. clr.b = clr.g = clr.r = 0.7f;
  572. pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_DIFFUSE);
  573. pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_SPECULAR);
  574. clr.b = clr.g = clr.r = 0.05f;
  575. pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_AMBIENT);
  576. aiString szName;
  577. szName.Set(AI_DEFAULT_MATERIAL_NAME);
  578. pcHelper->AddProperty(&szName,AI_MATKEY_NAME);
  579. }
  580. }
  581. // ------------------------------------------------------------------------------------------------
  582. // Parse the file
  583. void SMDImporter::ParseFile()
  584. {
  585. const char* szCurrent = mBuffer;
  586. // read line per line ...
  587. while (true)
  588. {
  589. if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) break;
  590. // "version <n> \n", <n> should be 1 for hl and hl² SMD files
  591. if (0 == ASSIMP_strincmp(szCurrent,"version",7) &&
  592. IsSpaceOrNewLine(*(szCurrent+7)))
  593. {
  594. szCurrent += 8;
  595. if(!SkipSpaces(szCurrent,&szCurrent)) break;
  596. if (1 != strtol10(szCurrent,&szCurrent))
  597. {
  598. DefaultLogger::get()->warn("SMD.version is not 1. This "
  599. "file format is not known. Continuing happily ...");
  600. }
  601. continue;
  602. }
  603. // "nodes\n" - Starts the node section
  604. if (0 == ASSIMP_strincmp(szCurrent,"nodes",5) &&
  605. IsSpaceOrNewLine(*(szCurrent+5)))
  606. {
  607. szCurrent += 6;
  608. ParseNodesSection(szCurrent,&szCurrent);
  609. continue;
  610. }
  611. // "triangles\n" - Starts the triangle section
  612. if (0 == ASSIMP_strincmp(szCurrent,"triangles",9) &&
  613. IsSpaceOrNewLine(*(szCurrent+9)))
  614. {
  615. szCurrent += 10;
  616. ParseTrianglesSection(szCurrent,&szCurrent);
  617. continue;
  618. }
  619. // "vertexanimation\n" - Starts the vertex animation section
  620. if (0 == ASSIMP_strincmp(szCurrent,"vertexanimation",15) &&
  621. IsSpaceOrNewLine(*(szCurrent+15)))
  622. {
  623. bHasUVs = false;
  624. szCurrent += 16;
  625. ParseVASection(szCurrent,&szCurrent);
  626. continue;
  627. }
  628. // "skeleton\n" - Starts the skeleton section
  629. if (0 == ASSIMP_strincmp(szCurrent,"skeleton",8) &&
  630. IsSpaceOrNewLine(*(szCurrent+8)))
  631. {
  632. szCurrent += 9;
  633. ParseSkeletonSection(szCurrent,&szCurrent);
  634. continue;
  635. }
  636. SkipLine(szCurrent,&szCurrent);
  637. }
  638. return;
  639. }
  640. // ------------------------------------------------------------------------------------------------
  641. unsigned int SMDImporter::GetTextureIndex(const std::string& filename)
  642. {
  643. unsigned int iIndex = 0;
  644. for (std::vector<std::string>::const_iterator
  645. i = aszTextures.begin();
  646. i != aszTextures.end();++i,++iIndex)
  647. {
  648. // case-insensitive ... just for safety
  649. if (0 == ASSIMP_stricmp ( filename.c_str(),(*i).c_str()))return iIndex;
  650. }
  651. iIndex = (unsigned int)aszTextures.size();
  652. aszTextures.push_back(filename);
  653. return iIndex;
  654. }
  655. // ------------------------------------------------------------------------------------------------
  656. // Parse the nodes section of the file
  657. void SMDImporter::ParseNodesSection(const char* szCurrent,
  658. const char** szCurrentOut)
  659. {
  660. while (true)
  661. {
  662. // "end\n" - Ends the nodes section
  663. if (0 == ASSIMP_strincmp(szCurrent,"end",3) &&
  664. IsSpaceOrNewLine(*(szCurrent+3)))
  665. {
  666. szCurrent += 4;
  667. break;
  668. }
  669. ParseNodeInfo(szCurrent,&szCurrent);
  670. }
  671. SkipSpacesAndLineEnd(szCurrent,&szCurrent);
  672. *szCurrentOut = szCurrent;
  673. }
  674. // ------------------------------------------------------------------------------------------------
  675. // Parse the triangles section of the file
  676. void SMDImporter::ParseTrianglesSection(const char* szCurrent,
  677. const char** szCurrentOut)
  678. {
  679. // parse a triangle, parse another triangle, parse the next triangle ...
  680. // and so on until we reach a token that looks quite similar to "end"
  681. while (true)
  682. {
  683. if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) break;
  684. // "end\n" - Ends the triangles section
  685. if (0 == ASSIMP_strincmp(szCurrent,"end",3) &&
  686. IsSpaceOrNewLine(*(szCurrent+3)))
  687. {
  688. szCurrent += 4;
  689. break;
  690. }
  691. ParseTriangle(szCurrent,&szCurrent);
  692. }
  693. SkipSpacesAndLineEnd(szCurrent,&szCurrent);
  694. *szCurrentOut = szCurrent;
  695. }
  696. // ------------------------------------------------------------------------------------------------
  697. // Parse the vertex animation section of the file
  698. void SMDImporter::ParseVASection(const char* szCurrent,
  699. const char** szCurrentOut)
  700. {
  701. unsigned int iCurIndex = 0;
  702. while (true)
  703. {
  704. if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) break;
  705. // "end\n" - Ends the "vertexanimation" section
  706. if (0 == ASSIMP_strincmp(szCurrent,"end",3) &&
  707. IsSpaceOrNewLine(*(szCurrent+3)))
  708. {
  709. szCurrent += 4;
  710. //SkipLine(szCurrent,&szCurrent);
  711. break;
  712. }
  713. // "time <n>\n"
  714. if (0 == ASSIMP_strincmp(szCurrent,"time",4) &&
  715. IsSpaceOrNewLine(*(szCurrent+4)))
  716. {
  717. szCurrent += 5;
  718. // NOTE: The doc says that time values COULD be negative ...
  719. // note2: this is the shape key -> valve docs
  720. int iTime = 0;
  721. if(!ParseSignedInt(szCurrent,&szCurrent,iTime) || configFrameID != (unsigned int)iTime)break;
  722. SkipLine(szCurrent,&szCurrent);
  723. }
  724. else
  725. {
  726. ParseVertex(szCurrent,&szCurrent,asTriangles.back().avVertices[iCurIndex],true);
  727. if(3 == ++iCurIndex)
  728. {
  729. asTriangles.push_back(SMD::Face());
  730. iCurIndex = 0;
  731. }
  732. }
  733. }
  734. if (iCurIndex)
  735. {
  736. // no degenerates, so let this triangle
  737. aszTextures.pop_back();
  738. }
  739. SkipSpacesAndLineEnd(szCurrent,&szCurrent);
  740. *szCurrentOut = szCurrent;
  741. }
  742. // ------------------------------------------------------------------------------------------------
  743. // Parse the skeleton section of the file
  744. void SMDImporter::ParseSkeletonSection(const char* szCurrent,
  745. const char** szCurrentOut)
  746. {
  747. int iTime = 0;
  748. while (true)
  749. {
  750. if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) break;
  751. // "end\n" - Ends the skeleton section
  752. if (0 == ASSIMP_strincmp(szCurrent,"end",3) &&
  753. IsSpaceOrNewLine(*(szCurrent+3)))
  754. {
  755. szCurrent += 4;
  756. //SkipLine(szCurrent,&szCurrent);
  757. break;
  758. }
  759. // "time <n>\n" - Specifies the current animation frame
  760. else if (0 == ASSIMP_strincmp(szCurrent,"time",4) &&
  761. IsSpaceOrNewLine(*(szCurrent+4)))
  762. {
  763. szCurrent += 5;
  764. // NOTE: The doc says that time values COULD be negative ...
  765. if(!ParseSignedInt(szCurrent,&szCurrent,iTime))break;
  766. iSmallestFrame = std::min(iSmallestFrame,iTime);
  767. SkipLine(szCurrent,&szCurrent);
  768. }
  769. else ParseSkeletonElement(szCurrent,&szCurrent,iTime);
  770. }
  771. *szCurrentOut = szCurrent;
  772. }
  773. #define SMDI_PARSE_RETURN { \
  774. SkipLine(szCurrent,&szCurrent); \
  775. *szCurrentOut = szCurrent; \
  776. return; \
  777. }
  778. // ------------------------------------------------------------------------------------------------
  779. // Parse a node line
  780. void SMDImporter::ParseNodeInfo(const char* szCurrent,
  781. const char** szCurrentOut)
  782. {
  783. unsigned int iBone = 0;
  784. SkipSpacesAndLineEnd(szCurrent,&szCurrent);
  785. if(!ParseUnsignedInt(szCurrent,&szCurrent,iBone) || !SkipSpaces(szCurrent,&szCurrent))
  786. {
  787. LogErrorNoThrow("Unexpected EOF/EOL while parsing bone index");
  788. SMDI_PARSE_RETURN;
  789. }
  790. // add our bone to the list
  791. if (iBone >= asBones.size())asBones.resize(iBone+1);
  792. SMD::Bone& bone = asBones[iBone];
  793. bool bQuota = true;
  794. if ('\"' != *szCurrent)
  795. {
  796. LogWarning("Bone name is expcted to be enclosed in "
  797. "double quotation marks. ");
  798. bQuota = false;
  799. }
  800. else ++szCurrent;
  801. const char* szEnd = szCurrent;
  802. while (true)
  803. {
  804. if (bQuota && '\"' == *szEnd)
  805. {
  806. iBone = (unsigned int)(szEnd - szCurrent);
  807. ++szEnd;
  808. break;
  809. }
  810. else if (IsSpaceOrNewLine(*szEnd))
  811. {
  812. iBone = (unsigned int)(szEnd - szCurrent);
  813. break;
  814. }
  815. else if (!(*szEnd))
  816. {
  817. LogErrorNoThrow("Unexpected EOF/EOL while parsing bone name");
  818. SMDI_PARSE_RETURN;
  819. }
  820. ++szEnd;
  821. }
  822. bone.mName = std::string(szCurrent,iBone);
  823. szCurrent = szEnd;
  824. // the only negative bone parent index that could occur is -1 AFAIK
  825. if(!ParseSignedInt(szCurrent,&szCurrent,(int&)bone.iParent))
  826. {
  827. LogErrorNoThrow("Unexpected EOF/EOL while parsing bone parent index. Assuming -1");
  828. SMDI_PARSE_RETURN;
  829. }
  830. // go to the beginning of the next line
  831. SMDI_PARSE_RETURN;
  832. }
  833. // ------------------------------------------------------------------------------------------------
  834. // Parse a skeleton element
  835. void SMDImporter::ParseSkeletonElement(const char* szCurrent,
  836. const char** szCurrentOut,int iTime)
  837. {
  838. aiVector3D vPos;
  839. aiVector3D vRot;
  840. unsigned int iBone = 0;
  841. if(!ParseUnsignedInt(szCurrent,&szCurrent,iBone))
  842. {
  843. DefaultLogger::get()->error("Unexpected EOF/EOL while parsing bone index");
  844. SMDI_PARSE_RETURN;
  845. }
  846. if (iBone >= asBones.size())
  847. {
  848. LogErrorNoThrow("Bone index in skeleton section is out of range");
  849. SMDI_PARSE_RETURN;
  850. }
  851. SMD::Bone& bone = asBones[iBone];
  852. bone.sAnim.asKeys.push_back(SMD::Bone::Animation::MatrixKey());
  853. SMD::Bone::Animation::MatrixKey& key = bone.sAnim.asKeys.back();
  854. key.dTime = (double)iTime;
  855. if(!ParseFloat(szCurrent,&szCurrent,(float&)vPos.x))
  856. {
  857. LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.pos.x");
  858. SMDI_PARSE_RETURN;
  859. }
  860. if(!ParseFloat(szCurrent,&szCurrent,(float&)vPos.y))
  861. {
  862. LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.pos.y");
  863. SMDI_PARSE_RETURN;
  864. }
  865. if(!ParseFloat(szCurrent,&szCurrent,(float&)vPos.z))
  866. {
  867. LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.pos.z");
  868. SMDI_PARSE_RETURN;
  869. }
  870. if(!ParseFloat(szCurrent,&szCurrent,(float&)vRot.x))
  871. {
  872. LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.rot.x");
  873. SMDI_PARSE_RETURN;
  874. }
  875. if(!ParseFloat(szCurrent,&szCurrent,(float&)vRot.y))
  876. {
  877. LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.rot.y");
  878. SMDI_PARSE_RETURN;
  879. }
  880. if(!ParseFloat(szCurrent,&szCurrent,(float&)vRot.z))
  881. {
  882. LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.rot.z");
  883. SMDI_PARSE_RETURN;
  884. }
  885. // build the transformation matrix of the key
  886. key.matrix.FromEulerAngles(vRot.x,vRot.y,vRot.z);
  887. {
  888. aiMatrix4x4 mTemp;
  889. mTemp.a4 = vPos.x;
  890. mTemp.b4 = vPos.y;
  891. mTemp.c4 = vPos.z;
  892. key.matrix = key.matrix * mTemp;
  893. }
  894. // go to the beginning of the next line
  895. SMDI_PARSE_RETURN;
  896. }
  897. // ------------------------------------------------------------------------------------------------
  898. // Parse a triangle
  899. void SMDImporter::ParseTriangle(const char* szCurrent,
  900. const char** szCurrentOut)
  901. {
  902. asTriangles.push_back(SMD::Face());
  903. SMD::Face& face = asTriangles.back();
  904. if(!SkipSpaces(szCurrent,&szCurrent))
  905. {
  906. LogErrorNoThrow("Unexpected EOF/EOL while parsing a triangle");
  907. return;
  908. }
  909. // read the texture file name
  910. const char* szLast = szCurrent;
  911. while (!IsSpaceOrNewLine(*szCurrent++));
  912. face.iTexture = GetTextureIndex(std::string(szLast,
  913. (uintptr_t)szCurrent-(uintptr_t)szLast));
  914. SkipLine(szCurrent,&szCurrent);
  915. // load three vertices
  916. for (unsigned int iVert = 0; iVert < 3;++iVert)
  917. {
  918. ParseVertex(szCurrent,&szCurrent,
  919. face.avVertices[iVert]);
  920. }
  921. *szCurrentOut = szCurrent;
  922. }
  923. // ------------------------------------------------------------------------------------------------
  924. // Parse a float
  925. bool SMDImporter::ParseFloat(const char* szCurrent,
  926. const char** szCurrentOut, float& out)
  927. {
  928. if(!SkipSpaces(&szCurrent))
  929. return false;
  930. *szCurrentOut = fast_atof_move(szCurrent,out);
  931. return true;
  932. }
  933. // ------------------------------------------------------------------------------------------------
  934. // Parse an unsigned int
  935. bool SMDImporter::ParseUnsignedInt(const char* szCurrent,
  936. const char** szCurrentOut, unsigned int& out)
  937. {
  938. if(!SkipSpaces(&szCurrent))
  939. return false;
  940. out = strtol10(szCurrent,szCurrentOut);
  941. return true;
  942. }
  943. // ------------------------------------------------------------------------------------------------
  944. // Parse a signed int
  945. bool SMDImporter::ParseSignedInt(const char* szCurrent,
  946. const char** szCurrentOut, int& out)
  947. {
  948. if(!SkipSpaces(&szCurrent))
  949. return false;
  950. out = strtol10s(szCurrent,szCurrentOut);
  951. return true;
  952. }
  953. // ------------------------------------------------------------------------------------------------
  954. // Parse a vertex
  955. void SMDImporter::ParseVertex(const char* szCurrent,
  956. const char** szCurrentOut, SMD::Vertex& vertex,
  957. bool bVASection /*= false*/)
  958. {
  959. if (SkipSpaces(&szCurrent) && IsLineEnd(*szCurrent))
  960. {
  961. SkipSpacesAndLineEnd(szCurrent,&szCurrent);
  962. return ParseVertex(szCurrent,szCurrentOut,vertex,bVASection);
  963. }
  964. if(!ParseSignedInt(szCurrent,&szCurrent,(int&)vertex.iParentNode))
  965. {
  966. LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.parent");
  967. SMDI_PARSE_RETURN;
  968. }
  969. if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.pos.x))
  970. {
  971. LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.pos.x");
  972. SMDI_PARSE_RETURN;
  973. }
  974. if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.pos.y))
  975. {
  976. LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.pos.y");
  977. SMDI_PARSE_RETURN;
  978. }
  979. if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.pos.z))
  980. {
  981. LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.pos.z");
  982. SMDI_PARSE_RETURN;
  983. }
  984. if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.nor.x))
  985. {
  986. LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.nor.x");
  987. SMDI_PARSE_RETURN;
  988. }
  989. if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.nor.y))
  990. {
  991. LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.nor.y");
  992. SMDI_PARSE_RETURN;
  993. }
  994. if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.nor.z))
  995. {
  996. LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.nor.z");
  997. SMDI_PARSE_RETURN;
  998. }
  999. if (bVASection)SMDI_PARSE_RETURN;
  1000. if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.uv.x))
  1001. {
  1002. LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.uv.x");
  1003. SMDI_PARSE_RETURN;
  1004. }
  1005. if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.uv.y))
  1006. {
  1007. LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.uv.y");
  1008. SMDI_PARSE_RETURN;
  1009. }
  1010. // now read the number of bones affecting this vertex
  1011. // all elements from now are fully optional, we don't need them
  1012. unsigned int iSize = 0;
  1013. if(!ParseUnsignedInt(szCurrent,&szCurrent,iSize))SMDI_PARSE_RETURN;
  1014. vertex.aiBoneLinks.resize(iSize,std::pair<unsigned int, float>(0,0.0f));
  1015. for (std::vector<std::pair<unsigned int, float> >::iterator
  1016. i = vertex.aiBoneLinks.begin();
  1017. i != vertex.aiBoneLinks.end();++i)
  1018. {
  1019. if(!ParseUnsignedInt(szCurrent,&szCurrent,(*i).first))SMDI_PARSE_RETURN;
  1020. if(!ParseFloat(szCurrent,&szCurrent,(*i).second))SMDI_PARSE_RETURN;
  1021. }
  1022. // go to the beginning of the next line
  1023. SMDI_PARSE_RETURN;
  1024. }