SMDLoader.cpp 36 KB

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