Coverage Report

Created: 2026-05-04 07:03

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
38.9k
        mBuffer(),
87
38.9k
        mEnd(nullptr),
88
38.9k
        pScene(nullptr),
89
38.9k
        iFileSize( 0 ),
90
38.9k
        iSmallestFrame( INT_MAX ),
91
38.9k
        dLengthOfAnim( 0.0 ),
92
38.9k
        bHasUVs(false ),
93
38.9k
        iLineNumber((unsigned int)-1)  {
94
    // empty
95
38.9k
}
96
97
98
// ------------------------------------------------------------------------------------------------
99
// Returns whether the class can handle the format of the given file.
100
0
bool SMDImporter::CanRead( const std::string& filename, IOSystem* /*pIOHandler*/, bool) const {
101
0
    return SimpleExtensionCheck(filename, "smd", "vta");
102
0
}
103
104
// ------------------------------------------------------------------------------------------------
105
// Get a list of all supported file extensions
106
38.9k
const aiImporterDesc* SMDImporter::GetInfo () const {
107
38.9k
    return &desc;
108
38.9k
}
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
        static constexpr char rootName[11] = "<SMD_root>";
460
0
        pScene->mRootNode->mName.length = 10;
461
0
        ::strncpy(pScene->mRootNode->mName.data, rootName, pScene->mRootNode->mName.length);
462
0
    }
463
0
}
464
465
// ------------------------------------------------------------------------------------------------
466
// create output animations
467
0
void SMDImporter::CreateOutputAnimations(const std::string &pFile, IOSystem* pIOHandler) {
468
0
    std::vector<std::tuple<std::string, std::string>> animFileList;
469
470
0
    if (bLoadAnimationList) {
471
0
        GetAnimationFileList(pFile, pIOHandler, animFileList);
472
0
    }
473
0
    int animCount = static_cast<int>( animFileList.size() + 1u );
474
0
    pScene->mNumAnimations = 1;
475
0
    pScene->mAnimations = new aiAnimation*[animCount];
476
0
    memset(pScene->mAnimations, 0, sizeof(aiAnimation*)*animCount);
477
0
    CreateOutputAnimation(0, "");
478
479
0
    for (auto &animFile : animFileList) {
480
0
        ReadSmd(std::get<1>(animFile), pIOHandler);
481
0
        if (asBones.empty()) {
482
0
            continue;
483
0
        }
484
485
0
        FixTimeValues();
486
0
        CreateOutputAnimation(pScene->mNumAnimations++, std::get<0>(animFile));
487
0
    }
488
0
}
489
490
0
void SMDImporter::CreateOutputAnimation(int index, const std::string &name) {
491
0
    aiAnimation*& anim = pScene->mAnimations[index] = new aiAnimation();
492
493
0
    if (name.length()) {
494
0
        anim->mName.Set(name.c_str());
495
0
    }
496
0
    anim->mDuration = dLengthOfAnim;
497
0
    anim->mNumChannels = static_cast<unsigned int>( asBones.size() );
498
0
    anim->mTicksPerSecond = 25.0; // FIXME: is this correct?
499
500
0
    aiNodeAnim** pp = anim->mChannels = new aiNodeAnim*[anim->mNumChannels];
501
502
    // now build valid keys
503
0
    unsigned int a = 0;
504
0
    for (const auto &asBone : asBones) {
505
0
        aiNodeAnim* p = pp[a] = new aiNodeAnim();
506
507
        // copy the name of the bone
508
0
        p->mNodeName.Set(asBone.mName);
509
510
0
        p->mNumRotationKeys = (unsigned int)asBone.sAnim.asKeys.size();
511
0
        if (p->mNumRotationKeys){
512
0
            p->mNumPositionKeys = p->mNumRotationKeys;
513
0
            aiVectorKey* pVecKeys = p->mPositionKeys = new aiVectorKey[p->mNumRotationKeys];
514
0
            aiQuatKey* pRotKeys = p->mRotationKeys = new aiQuatKey[p->mNumRotationKeys];
515
516
0
            for (const auto &asKey : asBone.sAnim.asKeys) {
517
0
                pRotKeys->mTime = pVecKeys->mTime = asKey.dTime;
518
519
                // compute the rotation quaternion from the euler angles
520
                // aiQuaternion: The order of the parameters is yzx?
521
0
                pRotKeys->mValue = aiQuaternion(asKey.vRot.y, asKey.vRot.z, asKey.vRot.x);
522
0
                pVecKeys->mValue = asKey.vPos;
523
524
0
                ++pVecKeys; ++pRotKeys;
525
0
            }
526
0
        }
527
0
        ++a;
528
529
        // there are no scaling keys ...
530
0
    }
531
0
}
532
533
0
void SMDImporter::GetAnimationFileList(const std::string &pFile, IOSystem* pIOHandler, std::vector<std::tuple<std::string, std::string>>& outList) {
534
0
    auto base = DefaultIOSystem::absolutePath(pFile);
535
0
    auto name = DefaultIOSystem::completeBaseName(pFile);
536
0
    auto path = base + "/" + name + "_animation.txt";
537
538
0
    std::unique_ptr<IOStream> file(pIOHandler->Open(path.c_str(), "rb"));
539
0
    if (file == nullptr) {
540
0
        return;
541
0
    }
542
543
    // Allocate storage and copy the contents of the file to a memory buffer
544
0
    std::vector<char> buf;
545
0
    size_t fileSize = file->FileSize();
546
0
    buf.resize(fileSize + 1);
547
0
    TextFileToBuffer(file.get(), buf);
548
549
    /*
550
        *_animation.txt format:
551
        name path
552
        idle idle.smd
553
        jump anim/jump.smd
554
        walk.smd
555
        ...
556
    */
557
0
    std::string animName, animPath;
558
0
    char *tok1, *tok2;
559
0
    char *context1, *context2;
560
561
0
    tok1 = strtok_s(&buf[0], "\r\n", &context1);
562
0
    while (tok1 != nullptr) {
563
0
        tok2 = strtok_s(tok1, " \t", &context2);
564
0
        if (tok2) {
565
0
            char *p = tok2;
566
0
            tok2 = strtok_s(nullptr, " \t", &context2);
567
0
            if (tok2) {
568
0
                animPath = tok2;
569
0
                animName = p;
570
0
            } else  {
571
                // No name
572
0
                animPath = p;
573
0
                animName = DefaultIOSystem::completeBaseName(animPath);
574
0
            }
575
0
            outList.emplace_back(animName, base + "/" + animPath);
576
0
        }
577
0
        tok1 = strtok_s(nullptr, "\r\n", &context1);
578
0
    }
579
0
}
580
581
// ------------------------------------------------------------------------------------------------
582
// create output materials
583
0
void SMDImporter::CreateOutputMaterials() {
584
0
    ai_assert( nullptr != pScene );
585
586
0
    pScene->mNumMaterials = (unsigned int)aszTextures.size();
587
0
    pScene->mMaterials = new aiMaterial*[std::max(1u, pScene->mNumMaterials)];
588
589
0
    for (unsigned int iMat = 0; iMat < pScene->mNumMaterials; ++iMat) {
590
0
        aiMaterial* pcMat = new aiMaterial();
591
0
        ai_assert( nullptr != pcMat );
592
0
        pScene->mMaterials[iMat] = pcMat;
593
594
0
        aiString szName;
595
0
        szName.length = static_cast<ai_uint32>(ai_snprintf(szName.data, AI_MAXLEN, "Texture_%u", iMat));
596
0
        pcMat->AddProperty(&szName,AI_MATKEY_NAME);
597
598
0
        if (aszTextures[iMat].length())
599
0
        {
600
0
            ::strncpy(szName.data, aszTextures[iMat].c_str(), AI_MAXLEN - 1);
601
0
            szName.length = static_cast<ai_uint32>( aszTextures[iMat].length() );
602
0
            pcMat->AddProperty(&szName,AI_MATKEY_TEXTURE_DIFFUSE(0));
603
0
        }
604
0
    }
605
606
    // create a default material if necessary
607
0
    if (0 == pScene->mNumMaterials) {
608
0
        pScene->mNumMaterials = 1;
609
610
0
        aiMaterial* pcHelper = new aiMaterial();
611
0
        pScene->mMaterials[0] = pcHelper;
612
613
0
        int iMode = static_cast<int>(aiShadingMode_Gouraud);
614
0
        pcHelper->AddProperty<int>(&iMode, 1, AI_MATKEY_SHADING_MODEL);
615
616
0
        aiColor3D clr;
617
0
        clr.b = clr.g = clr.r = 0.7f;
618
0
        pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_DIFFUSE);
619
0
        pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_SPECULAR);
620
621
0
        clr.b = clr.g = clr.r = 0.05f;
622
0
        pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_AMBIENT);
623
624
0
        aiString szName;
625
0
        szName.Set(AI_DEFAULT_MATERIAL_NAME);
626
0
        pcHelper->AddProperty(&szName,AI_MATKEY_NAME);
627
0
    }
628
0
}
629
630
// ------------------------------------------------------------------------------------------------
631
// Parse the file
632
0
void SMDImporter::ParseFile() {
633
0
    const char* szCurrent = &mBuffer[0];
634
635
    // read line per line ...
636
0
    for ( ;; ) {
637
0
        if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent, mEnd)) {
638
0
            break;
639
0
        }
640
641
        // "version <n> \n", <n> should be 1 for hl and hl2 SMD files
642
0
        if (TokenMatch(szCurrent,"version",7)) {
643
0
            if(!SkipSpaces(szCurrent,&szCurrent, mEnd)) break;
644
0
            if (1 != strtoul10(szCurrent,&szCurrent)) {
645
0
                ASSIMP_LOG_WARN("SMD.version is not 1. This "
646
0
                    "file format is not known. Continuing happily ...");
647
0
            }
648
0
            continue;
649
0
        }
650
        // "nodes\n" - Starts the node section
651
0
        if (TokenMatch(szCurrent,"nodes",5)) {
652
0
            ParseNodesSection(szCurrent, &szCurrent, mEnd);
653
0
            continue;
654
0
        }
655
        // "triangles\n" - Starts the triangle section
656
0
        if (TokenMatch(szCurrent,"triangles",9)) {
657
0
            ParseTrianglesSection(szCurrent, &szCurrent, mEnd);
658
0
            continue;
659
0
        }
660
        // "vertexanimation\n" - Starts the vertex animation section
661
0
        if (TokenMatch(szCurrent,"vertexanimation",15)) {
662
0
            bHasUVs = false;
663
0
            ParseVASection(szCurrent, &szCurrent, mEnd);
664
0
            continue;
665
0
        }
666
        // "skeleton\n" - Starts the skeleton section
667
0
        if (TokenMatch(szCurrent,"skeleton",8)) {
668
0
            ParseSkeletonSection(szCurrent, &szCurrent, mEnd);
669
0
            continue;
670
0
        }
671
0
        SkipLine(szCurrent, &szCurrent, mEnd);
672
0
    }
673
0
}
674
675
0
void SMDImporter::ReadSmd(const std::string &pFile, IOSystem* pIOHandler) {
676
0
    std::unique_ptr<IOStream> file(pIOHandler->Open(pFile, "rb"));
677
678
    // Check whether we can read from the file
679
0
    if (file == nullptr) {
680
0
        throw DeadlyImportError("Failed to open SMD/VTA file ", pFile, ".");
681
0
    }
682
683
0
    iFileSize = (unsigned int)file->FileSize();
684
685
    // Allocate storage and copy the contents of the file to a memory buffer
686
0
    mBuffer.resize(iFileSize + 1);
687
0
    TextFileToBuffer(file.get(), mBuffer);
688
0
    mEnd = &mBuffer[mBuffer.size() - 1] + 1;
689
690
0
    iSmallestFrame = INT_MAX;
691
0
    bHasUVs = true;
692
0
    iLineNumber = 1;
693
694
    // Reserve enough space for ... hm ... 10 textures
695
0
    aszTextures.reserve(10);
696
697
    // Reserve enough space for ... hm ... 1000 triangles
698
0
    asTriangles.reserve(1000);
699
700
    // Reserve enough space for ... hm ... 20 bones
701
0
    asBones.reserve(20);
702
703
0
    aszTextures.clear();
704
0
    asTriangles.clear();
705
0
    asBones.clear();
706
707
    // parse the file ...
708
0
    ParseFile();
709
0
}
710
711
// ------------------------------------------------------------------------------------------------
712
0
unsigned int SMDImporter::GetTextureIndex(const std::string& filename) {
713
0
    unsigned int iIndex = 0;
714
0
    for (std::vector<std::string>::const_iterator
715
0
            i =  aszTextures.begin();
716
0
            i != aszTextures.end();++i,++iIndex) {
717
        // case-insensitive ... it's a path
718
0
        if (0 == ASSIMP_stricmp ( filename.c_str(),(*i).c_str())) {
719
0
            return iIndex;
720
0
        }
721
0
    }
722
0
    iIndex = (unsigned int)aszTextures.size();
723
0
    aszTextures.push_back(filename);
724
0
    return iIndex;
725
0
}
726
727
// ------------------------------------------------------------------------------------------------
728
// Parse the nodes section of the file
729
0
void SMDImporter::ParseNodesSection(const char* szCurrent, const char** szCurrentOut, const char *end) {
730
0
    for ( ;; ) {
731
        // "end\n" - Ends the nodes section
732
0
        if (0 == ASSIMP_strincmp(szCurrent, "end", 3) && IsSpaceOrNewLine(*(szCurrent+3))) {
733
0
            szCurrent += 4;
734
0
            break;
735
0
        }
736
0
        ParseNodeInfo(szCurrent,&szCurrent, end);
737
0
    }
738
0
    SkipSpacesAndLineEnd(szCurrent, &szCurrent, end);
739
0
    *szCurrentOut = szCurrent;
740
0
}
741
742
// ------------------------------------------------------------------------------------------------
743
// Parse the triangles section of the file
744
0
void SMDImporter::ParseTrianglesSection(const char *szCurrent, const char **szCurrentOut, const char *end) {
745
    // Parse a triangle, parse another triangle, parse the next triangle ...
746
    // and so on until we reach a token that looks quite similar to "end"
747
0
    for ( ;; ) {
748
0
        if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent, end)) {
749
0
            break;
750
0
        }
751
752
        // "end\n" - Ends the triangles section
753
0
        if (TokenMatch(szCurrent,"end",3)) {
754
0
            break;
755
0
        }
756
0
        ParseTriangle(szCurrent,&szCurrent, end);
757
0
    }
758
0
    SkipSpacesAndLineEnd(szCurrent,&szCurrent, end);
759
0
    *szCurrentOut = szCurrent;
760
0
}
761
// ------------------------------------------------------------------------------------------------
762
// Parse the vertex animation section of the file
763
0
void SMDImporter::ParseVASection(const char *szCurrent, const char **szCurrentOut, const char *end) {
764
0
    unsigned int iCurIndex = 0;
765
0
    for ( ;; ) {
766
0
        if (!SkipSpacesAndLineEnd(szCurrent,&szCurrent, end)) {
767
0
            break;
768
0
        }
769
770
        // "end\n" - Ends the "vertexanimation" section
771
0
        if (TokenMatch(szCurrent,"end",3)) {
772
0
            break;
773
0
        }
774
775
        // "time <n>\n"
776
0
        if (TokenMatch(szCurrent,"time",4)) {
777
            // NOTE: The doc says that time values COULD be negative ...
778
            // NOTE2: this is the shape key -> valve docs
779
0
            int iTime = 0;
780
0
            if (!ParseSignedInt(szCurrent, &szCurrent, end, iTime) || configFrameID != (unsigned int)iTime) {
781
0
                break;
782
0
            }
783
0
            SkipLine(szCurrent,&szCurrent, end);
784
0
        } else {
785
0
            if(0 == iCurIndex) {
786
0
                asTriangles.emplace_back();
787
0
            }
788
0
            if (++iCurIndex == 3) {
789
0
                iCurIndex = 0;
790
0
            }
791
0
            ParseVertex(szCurrent,&szCurrent, end, asTriangles.back().avVertices[iCurIndex],true);
792
0
        }
793
0
    }
794
795
0
    if (iCurIndex != 2 && !asTriangles.empty()) {
796
        // we want to no degenerates, so throw this triangle away
797
0
        asTriangles.pop_back();
798
0
    }
799
800
0
    SkipSpacesAndLineEnd(szCurrent,&szCurrent, end);
801
0
    *szCurrentOut = szCurrent;
802
0
}
803
804
// ------------------------------------------------------------------------------------------------
805
// Parse the skeleton section of the file
806
0
void SMDImporter::ParseSkeletonSection(const char *szCurrent, const char **szCurrentOut, const char *end) {
807
0
    int iTime = 0;
808
0
    for ( ;; ) {
809
0
        if (!SkipSpacesAndLineEnd(szCurrent,&szCurrent, end)) {
810
0
            break;
811
0
        }
812
813
        // "end\n" - Ends the skeleton section
814
0
        if (TokenMatch(szCurrent,"end",3)) {
815
0
            break;
816
0
        } else if (TokenMatch(szCurrent,"time",4)) {
817
            // "time <n>\n" - Specifies the current animation frame
818
0
            if (!ParseSignedInt(szCurrent, &szCurrent, end, iTime)) {
819
0
                break;
820
0
            }
821
822
0
            iSmallestFrame = std::min(iSmallestFrame,iTime);
823
0
            SkipLine(szCurrent, &szCurrent, end);
824
0
        } else {
825
0
            ParseSkeletonElement(szCurrent, &szCurrent, end, iTime);
826
0
        }
827
0
    }
828
0
    *szCurrentOut = szCurrent;
829
0
}
830
831
// ------------------------------------------------------------------------------------------------
832
0
#define SMDI_PARSE_RETURN { \
833
0
    SkipLine(szCurrent,&szCurrent, end); \
834
0
    *szCurrentOut = szCurrent; \
835
0
    return; \
836
0
}
837
// ------------------------------------------------------------------------------------------------
838
// Parse a node line
839
0
void SMDImporter::ParseNodeInfo(const char *szCurrent, const char **szCurrentOut, const char *end) {
840
0
    unsigned int iBone  = 0;
841
0
    SkipSpacesAndLineEnd(szCurrent, &szCurrent, end);
842
0
    if ( !ParseUnsignedInt(szCurrent, &szCurrent, end, iBone) || !SkipSpaces(szCurrent,&szCurrent, end)) {
843
0
        throw DeadlyImportError("Unexpected EOF/EOL while parsing bone index");
844
0
    }
845
0
    if (iBone == UINT_MAX) {
846
0
        LogErrorNoThrow("Invalid bone number while parsing bone index");
847
0
        SMDI_PARSE_RETURN;
848
0
    }
849
    // add our bone to the list
850
0
    if (iBone >= asBones.size()) {
851
0
        asBones.resize(iBone+1);
852
0
    }
853
0
    SMD::Bone& bone = asBones[iBone];
854
855
0
    bool bQuota = true;
856
0
    if ('\"' != *szCurrent) {
857
0
        LogWarning("Bone name is expected to be enclosed in "
858
0
            "double quotation marks. ");
859
0
        bQuota = false;
860
0
    } else {
861
0
        ++szCurrent;
862
0
    }
863
864
0
    const char* szEnd = szCurrent;
865
0
    for ( ;; ) {
866
0
        if (bQuota && '\"' == *szEnd) {
867
0
            iBone = (unsigned int)(szEnd - szCurrent);
868
0
            ++szEnd;
869
0
            break;
870
0
        } else if (!bQuota && IsSpaceOrNewLine(*szEnd)) {
871
0
            iBone = (unsigned int)(szEnd - szCurrent);
872
0
            break;
873
0
        } else if (!(*szEnd)) {
874
0
            LogErrorNoThrow("Unexpected EOF/EOL while parsing bone name");
875
0
            SMDI_PARSE_RETURN;
876
0
        }
877
0
        ++szEnd;
878
0
    }
879
0
    bone.mName = std::string(szCurrent,iBone);
880
0
    szCurrent = szEnd;
881
882
    // the only negative bone parent index that could occur is -1 AFAIK
883
0
    if(!ParseSignedInt(szCurrent, &szCurrent, end, (int&)bone.iParent))  {
884
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing bone parent index. Assuming -1");
885
0
        SMDI_PARSE_RETURN;
886
0
    }
887
888
    // go to the beginning of the next line
889
0
    SMDI_PARSE_RETURN;
890
0
}
891
892
// ------------------------------------------------------------------------------------------------
893
// Parse a skeleton element
894
0
void SMDImporter::ParseSkeletonElement(const char *szCurrent, const char **szCurrentOut, const char *end, int iTime) {
895
0
    aiVector3D vPos;
896
0
    aiVector3D vRot;
897
898
0
    unsigned int iBone  = 0;
899
0
    if (!ParseUnsignedInt(szCurrent, &szCurrent, end, iBone)) {
900
0
        ASSIMP_LOG_ERROR("Unexpected EOF/EOL while parsing bone index");
901
0
        SMDI_PARSE_RETURN;
902
0
    }
903
0
    if (iBone >= asBones.size()) {
904
0
        LogErrorNoThrow("Bone index in skeleton section is out of range");
905
0
        SMDI_PARSE_RETURN;
906
0
    }
907
0
    SMD::Bone& bone = asBones[iBone];
908
909
0
    bone.sAnim.asKeys.emplace_back();
910
0
    SMD::Bone::Animation::MatrixKey& key = bone.sAnim.asKeys.back();
911
912
0
    key.dTime = (double)iTime;
913
0
    if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vPos.x)) {
914
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.pos.x");
915
0
        SMDI_PARSE_RETURN;
916
0
    }
917
0
    if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vPos.y)) {
918
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.pos.y");
919
0
        SMDI_PARSE_RETURN;
920
0
    }
921
0
    if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vPos.z)) {
922
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.pos.z");
923
0
        SMDI_PARSE_RETURN;
924
0
    }
925
0
    if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vRot.x)) {
926
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.rot.x");
927
0
        SMDI_PARSE_RETURN;
928
0
    }
929
0
    if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vRot.y)) {
930
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.rot.y");
931
0
        SMDI_PARSE_RETURN;
932
0
    }
933
0
    if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vRot.z)) {
934
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.rot.z");
935
0
        SMDI_PARSE_RETURN;
936
0
    }
937
    // build the transformation matrix of the key
938
0
    key.matrix.FromEulerAnglesXYZ(vRot.x,vRot.y,vRot.z); {
939
0
        aiMatrix4x4 mTemp;
940
0
        mTemp.a4 = vPos.x;
941
0
        mTemp.b4 = vPos.y;
942
0
        mTemp.c4 = vPos.z;
943
0
        key.matrix = mTemp * key.matrix;
944
0
    }
945
0
    key.vPos = vPos;
946
0
    key.vRot = vRot;
947
    // go to the beginning of the next line
948
0
    SMDI_PARSE_RETURN;
949
0
}
950
951
// ------------------------------------------------------------------------------------------------
952
// Parse a triangle
953
0
void SMDImporter::ParseTriangle(const char *szCurrent, const char **szCurrentOut, const char *end) {
954
0
    asTriangles.emplace_back();
955
0
    SMD::Face& face = asTriangles.back();
956
957
0
    if(!SkipSpaces(szCurrent, &szCurrent, end)) {
958
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing a triangle");
959
0
        return;
960
0
    }
961
962
    // read the texture file name
963
0
    const char* szLast = szCurrent;
964
0
    while (!IsSpaceOrNewLine(*++szCurrent));
965
966
    // ... and get the index that belongs to this file name
967
0
    face.iTexture = GetTextureIndex(std::string(szLast,(uintptr_t)szCurrent-(uintptr_t)szLast));
968
969
0
    SkipSpacesAndLineEnd(szCurrent, &szCurrent, end);
970
971
    // load three vertices
972
0
    for (auto &avVertex : face.avVertices) {
973
0
        ParseVertex(szCurrent, &szCurrent, end, avVertex);
974
0
    }
975
0
    *szCurrentOut = szCurrent;
976
0
}
977
978
// ------------------------------------------------------------------------------------------------
979
// Parse a float
980
0
bool SMDImporter::ParseFloat(const char *szCurrent, const char **szCurrentOut, const char *end, float &out) {
981
0
    if (!SkipSpaces(&szCurrent, end)) {
982
0
        return false;
983
0
    }
984
985
0
    *szCurrentOut = fast_atoreal_move(szCurrent,out);
986
0
    return true;
987
0
}
988
989
// ------------------------------------------------------------------------------------------------
990
// Parse an unsigned int
991
0
bool SMDImporter::ParseUnsignedInt(const char *szCurrent, const char **szCurrentOut, const char *end, unsigned int &out) {
992
0
    if(!SkipSpaces(&szCurrent, end)) {
993
0
        return false;
994
0
    }
995
996
0
    out = strtoul10(szCurrent,szCurrentOut);
997
0
    return true;
998
0
}
999
1000
// ------------------------------------------------------------------------------------------------
1001
// Parse a signed int
1002
0
bool SMDImporter::ParseSignedInt(const char *szCurrent, const char **szCurrentOut, const char *end, int &out) {
1003
0
    if(!SkipSpaces(&szCurrent, end)) {
1004
0
        return false;
1005
0
    }
1006
1007
0
    out = strtol10(szCurrent,szCurrentOut);
1008
0
    return true;
1009
0
}
1010
1011
// ------------------------------------------------------------------------------------------------
1012
// Parse a vertex
1013
void SMDImporter::ParseVertex(const char* szCurrent,
1014
        const char **szCurrentOut, const char *end, SMD::Vertex &vertex,
1015
0
        bool bVASection /*= false*/) {
1016
0
    if (SkipSpaces(&szCurrent, end) && IsLineEnd(*szCurrent)) {
1017
0
        SkipSpacesAndLineEnd(szCurrent,&szCurrent, end);
1018
0
        return ParseVertex(szCurrent, szCurrentOut, end, vertex, bVASection);
1019
0
    }
1020
0
    if(!ParseSignedInt(szCurrent, &szCurrent, end, (int&)vertex.iParentNode)) {
1021
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.parent");
1022
0
        SMDI_PARSE_RETURN;
1023
0
    }
1024
0
    if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vertex.pos.x)) {
1025
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.pos.x");
1026
0
        SMDI_PARSE_RETURN;
1027
0
    }
1028
0
    if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vertex.pos.y)) {
1029
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.pos.y");
1030
0
        SMDI_PARSE_RETURN;
1031
0
    }
1032
0
    if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vertex.pos.z)) {
1033
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.pos.z");
1034
0
        SMDI_PARSE_RETURN;
1035
0
    }
1036
0
    if(!ParseFloat(szCurrent,&szCurrent,end, (float&)vertex.nor.x)) {
1037
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.nor.x");
1038
0
        SMDI_PARSE_RETURN;
1039
0
    }
1040
0
    if(!ParseFloat(szCurrent,&szCurrent, end, (float&)vertex.nor.y)) {
1041
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.nor.y");
1042
0
        SMDI_PARSE_RETURN;
1043
0
    }
1044
0
    if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vertex.nor.z)) {
1045
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.nor.z");
1046
0
        SMDI_PARSE_RETURN;
1047
0
    }
1048
1049
0
    if (bVASection) {
1050
0
        SMDI_PARSE_RETURN;
1051
0
    }
1052
1053
0
    if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vertex.uv.x)) {
1054
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.uv.x");
1055
0
        SMDI_PARSE_RETURN;
1056
0
    }
1057
0
    if(!ParseFloat(szCurrent, &szCurrent, end, (float&)vertex.uv.y)) {
1058
0
        LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.uv.y");
1059
0
        SMDI_PARSE_RETURN;
1060
0
    }
1061
1062
    // now read the number of bones affecting this vertex
1063
    // all elements from now are fully optional, we don't need them
1064
0
    unsigned int iSize = 0;
1065
0
    if(!ParseUnsignedInt(szCurrent, &szCurrent, end, iSize)) {
1066
0
        SMDI_PARSE_RETURN;
1067
0
    }
1068
0
    vertex.aiBoneLinks.resize(iSize,std::pair<unsigned int, float>(0,0.0f));
1069
1070
0
    for (auto &aiBoneLink : vertex.aiBoneLinks) {
1071
0
        if(!ParseUnsignedInt(szCurrent, &szCurrent, end, aiBoneLink.first)) {
1072
0
            SMDI_PARSE_RETURN;
1073
0
        }
1074
0
        if(!ParseFloat(szCurrent, &szCurrent, end, aiBoneLink.second)) {
1075
0
            SMDI_PARSE_RETURN;
1076
0
        }
1077
0
    }
1078
1079
    // go to the beginning of the next line
1080
0
    SMDI_PARSE_RETURN;
1081
0
}
1082
1083
} // namespace Assimp
1084
1085
#endif // !! ASSIMP_BUILD_NO_SMD_IMPORTER