SMDLoader.cpp 39 KB

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