Coverage Report

Created: 2026-09-14 07:44

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