SMDLoader.cpp 39 KB

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