Coverage Report

Created: 2026-02-05 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/assimp/code/AssetLib/MDC/MDCLoader.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 Implementation of the MDC importer class */
43
44
#ifndef ASSIMP_BUILD_NO_MDC_IMPORTER
45
46
// internal headers
47
#include "MDCLoader.h"
48
#include "AssetLib/MD3/MD3FileData.h"
49
#include "MDCNormalTable.h" // shouldn't be included by other units
50
51
#include <assimp/importerdesc.h>
52
#include <assimp/scene.h>
53
#include <assimp/DefaultLogger.hpp>
54
#include <assimp/IOSystem.hpp>
55
#include <assimp/Importer.hpp>
56
#include <assimp/StringUtils.h>
57
58
#include <memory>
59
60
using namespace Assimp;
61
using namespace Assimp::MDC;
62
63
static constexpr aiImporterDesc desc = {
64
    "Return To Castle Wolfenstein Mesh Importer",
65
    "",
66
    "",
67
    "",
68
    aiImporterFlags_SupportBinaryFlavour,
69
    0,
70
    0,
71
    0,
72
    0,
73
    "mdc"
74
};
75
76
// ------------------------------------------------------------------------------------------------
77
void MDC::BuildVertex(const Frame &frame,
78
        const BaseVertex &bvert,
79
        const CompressedVertex &cvert,
80
        aiVector3D &vXYZOut,
81
0
        aiVector3D &vNorOut) {
82
    // compute the position
83
0
    const float xd = (cvert.xd - AI_MDC_CVERT_BIAS) * AI_MDC_DELTA_SCALING;
84
0
    const float yd = (cvert.yd - AI_MDC_CVERT_BIAS) * AI_MDC_DELTA_SCALING;
85
0
    const float zd = (cvert.zd - AI_MDC_CVERT_BIAS) * AI_MDC_DELTA_SCALING;
86
0
    vXYZOut.x = frame.localOrigin.x + AI_MDC_BASE_SCALING * (bvert.x + xd);
87
0
    vXYZOut.y = frame.localOrigin.y + AI_MDC_BASE_SCALING * (bvert.y + yd);
88
0
    vXYZOut.z = frame.localOrigin.z + AI_MDC_BASE_SCALING * (bvert.z + zd);
89
90
    // compute the normal vector .. ehm ... lookup it in the table :-)
91
0
    vNorOut.x = mdcNormals[cvert.nd][0];
92
0
    vNorOut.y = mdcNormals[cvert.nd][1];
93
0
    vNorOut.z = mdcNormals[cvert.nd][2];
94
0
}
95
96
// ------------------------------------------------------------------------------------------------
97
// Constructor to be privately used by Importer
98
MDCImporter::MDCImporter() :
99
        configFrameID(),
100
        pcHeader(),
101
        mBuffer(),
102
31.7k
        fileSize() {
103
    // empty
104
31.7k
}
105
106
// ------------------------------------------------------------------------------------------------
107
// Returns whether the class can handle the format of the given file.
108
968
bool MDCImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const {
109
968
    static constexpr uint32_t tokens[] = { AI_MDC_MAGIC_NUMBER_LE };
110
968
    return CheckMagicToken(pIOHandler, pFile, tokens, AI_COUNT_OF(tokens));
111
968
}
112
113
// ------------------------------------------------------------------------------------------------
114
31.9k
const aiImporterDesc *MDCImporter::GetInfo() const {
115
31.9k
    return &desc;
116
31.9k
}
117
118
// ------------------------------------------------------------------------------------------------
119
// Validate the header of the given MDC file
120
0
void MDCImporter::ValidateHeader() {
121
0
    AI_SWAP4(this->pcHeader->ulVersion);
122
0
    AI_SWAP4(this->pcHeader->ulFlags);
123
0
    AI_SWAP4(this->pcHeader->ulNumFrames);
124
0
    AI_SWAP4(this->pcHeader->ulNumTags);
125
0
    AI_SWAP4(this->pcHeader->ulNumSurfaces);
126
0
    AI_SWAP4(this->pcHeader->ulNumSkins);
127
0
    AI_SWAP4(this->pcHeader->ulOffsetBorderFrames);
128
129
0
    if (pcHeader->ulIdent != AI_MDC_MAGIC_NUMBER_BE &&
130
0
            pcHeader->ulIdent != AI_MDC_MAGIC_NUMBER_LE) {
131
0
        throw DeadlyImportError("Invalid MDC magic word: expected IDPC, found ",
132
0
                                ai_str_toprintable((char *)&pcHeader->ulIdent, 4));
133
0
    }
134
135
0
    if (pcHeader->ulVersion != AI_MDC_VERSION) {
136
0
        ASSIMP_LOG_WARN("Unsupported MDC file version (2 (AI_MDC_VERSION) was expected)");
137
0
    }
138
139
0
    if (pcHeader->ulOffsetBorderFrames + pcHeader->ulNumFrames * sizeof(MDC::Frame) > this->fileSize ||
140
0
            pcHeader->ulOffsetSurfaces + pcHeader->ulNumSurfaces * sizeof(MDC::Surface) > this->fileSize) {
141
0
        throw DeadlyImportError("Some of the offset values in the MDC header are invalid "
142
0
                                "and point to something behind the file.");
143
0
    }
144
145
0
    if (this->configFrameID >= this->pcHeader->ulNumFrames) {
146
0
        throw DeadlyImportError("The requested frame is not available");
147
0
    }
148
0
}
149
150
// ------------------------------------------------------------------------------------------------
151
// Validate the header of a given MDC file surface
152
0
void MDCImporter::ValidateSurfaceHeader(BE_NCONST MDC::Surface *pcSurf) {
153
0
    AI_SWAP4(pcSurf->ulFlags);
154
0
    AI_SWAP4(pcSurf->ulNumCompFrames);
155
0
    AI_SWAP4(pcSurf->ulNumBaseFrames);
156
0
    AI_SWAP4(pcSurf->ulNumShaders);
157
0
    AI_SWAP4(pcSurf->ulNumVertices);
158
0
    AI_SWAP4(pcSurf->ulNumTriangles);
159
0
    AI_SWAP4(pcSurf->ulOffsetTriangles);
160
0
    AI_SWAP4(pcSurf->ulOffsetTexCoords);
161
0
    AI_SWAP4(pcSurf->ulOffsetBaseVerts);
162
0
    AI_SWAP4(pcSurf->ulOffsetCompVerts);
163
0
    AI_SWAP4(pcSurf->ulOffsetShaders);
164
0
    AI_SWAP4(pcSurf->ulOffsetFrameBaseFrames);
165
0
    AI_SWAP4(pcSurf->ulOffsetFrameCompFrames);
166
0
    AI_SWAP4(pcSurf->ulOffsetEnd);
167
168
0
    const unsigned int iMax = this->fileSize - (unsigned int)((int8_t *)pcSurf - (int8_t *)pcHeader);
169
170
0
    if (pcSurf->ulOffsetBaseVerts + pcSurf->ulNumVertices * sizeof(MDC::BaseVertex) > iMax ||
171
0
            (pcSurf->ulNumCompFrames && pcSurf->ulOffsetCompVerts + pcSurf->ulNumVertices * sizeof(MDC::CompressedVertex) > iMax) ||
172
0
            pcSurf->ulOffsetTriangles + pcSurf->ulNumTriangles * sizeof(MDC::Triangle) > iMax ||
173
0
            pcSurf->ulOffsetTexCoords + pcSurf->ulNumVertices * sizeof(MDC::TexturCoord) > iMax ||
174
0
            pcSurf->ulOffsetShaders + pcSurf->ulNumShaders * sizeof(MDC::Shader) > iMax ||
175
0
            pcSurf->ulOffsetFrameBaseFrames + pcSurf->ulNumBaseFrames * 2 > iMax ||
176
0
            (pcSurf->ulNumCompFrames && pcSurf->ulOffsetFrameCompFrames + pcSurf->ulNumCompFrames * 2 > iMax) ||
177
0
            pcSurf->ulOffsetEnd > iMax) {
178
0
        throw DeadlyImportError("Some of the offset values in the MDC surface header "
179
0
                                "are invalid and point somewhere behind the file.");
180
0
    }
181
0
}
182
183
// ------------------------------------------------------------------------------------------------
184
// Setup configuration properties
185
0
void MDCImporter::SetupProperties(const Importer *pImp) {
186
    // The AI_CONFIG_IMPORT_MDC_KEYFRAME option overrides the
187
    // AI_CONFIG_IMPORT_GLOBAL_KEYFRAME option.
188
0
    if (static_cast<unsigned int>(-1) == (configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_MDC_KEYFRAME, -1))) {
189
0
        configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_GLOBAL_KEYFRAME, 0);
190
0
    }
191
0
}
192
193
// ------------------------------------------------------------------------------------------------
194
// Imports the given file into the given scene structure.
195
void MDCImporter::InternReadFile(
196
0
        const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
197
0
    std::unique_ptr<IOStream> file(pIOHandler->Open(pFile));
198
199
    // Check whether we can read from the file
200
0
    if (file == nullptr) {
201
0
        throw DeadlyImportError("Failed to open MDC file ", pFile, ".");
202
0
    }
203
204
    // check whether the mdc file is large enough to contain the file header
205
0
    fileSize = static_cast<unsigned int>(file->FileSize());
206
0
    if (fileSize < sizeof(MDC::Header)) {
207
0
        throw DeadlyImportError("MDC File is too small.");
208
0
    }
209
210
0
    std::vector<unsigned char> mBuffer2(fileSize);
211
0
    file->Read(&mBuffer2[0], 1, fileSize);
212
0
    mBuffer = &mBuffer2[0];
213
214
    // validate the file header
215
0
    this->pcHeader = (BE_NCONST MDC::Header *)this->mBuffer;
216
0
    this->ValidateHeader();
217
218
0
    std::vector<std::string> aszShaders;
219
220
    // get a pointer to the frame we want to read
221
0
    BE_NCONST MDC::Frame *pcFrame = (BE_NCONST MDC::Frame *)(this->mBuffer +
222
0
                                                             this->pcHeader->ulOffsetBorderFrames);
223
224
    // no need to swap the other members, we won't need them
225
0
    pcFrame += configFrameID;
226
0
    AI_SWAP4(pcFrame->localOrigin[0]);
227
0
    AI_SWAP4(pcFrame->localOrigin[1]);
228
0
    AI_SWAP4(pcFrame->localOrigin[2]);
229
230
    // get the number of valid surfaces
231
0
    BE_NCONST MDC::Surface *pcSurface, *pcSurface2;
232
0
    pcSurface = pcSurface2 = reinterpret_cast<BE_NCONST MDC::Surface *>(mBuffer + pcHeader->ulOffsetSurfaces);
233
0
    unsigned int iNumShaders = 0;
234
0
    for (unsigned int i = 0; i < pcHeader->ulNumSurfaces; ++i) {
235
        // validate the surface header
236
0
        this->ValidateSurfaceHeader(pcSurface2);
237
238
0
        if (pcSurface2->ulNumVertices && pcSurface2->ulNumTriangles) {
239
0
            ++pScene->mNumMeshes;
240
0
        }
241
0
        iNumShaders += pcSurface2->ulNumShaders;
242
0
        pcSurface2 = reinterpret_cast<BE_NCONST MDC::Surface *>((BE_NCONST int8_t *)pcSurface2 + pcSurface2->ulOffsetEnd);
243
0
    }
244
0
    aszShaders.reserve(iNumShaders);
245
0
    pScene->mMeshes = new aiMesh *[pScene->mNumMeshes];
246
247
    // necessary that we don't crash if an exception occurs
248
0
    for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
249
0
        pScene->mMeshes[i] = nullptr;
250
0
    }
251
252
    // now read all surfaces
253
0
    unsigned int iDefaultMatIndex = UINT_MAX;
254
0
    for (unsigned int i = 0, iNum = 0; i < pcHeader->ulNumSurfaces; ++i) {
255
0
        if (!pcSurface->ulNumVertices || !pcSurface->ulNumTriangles) continue;
256
0
        aiMesh *pcMesh = pScene->mMeshes[iNum++] = new aiMesh();
257
258
0
        pcMesh->mNumFaces = pcSurface->ulNumTriangles;
259
0
        pcMesh->mNumVertices = pcMesh->mNumFaces * 3;
260
261
        // store the name of the surface for use as node name.
262
0
        pcMesh->mName.Set(std::string(pcSurface->ucName, strnlen(pcSurface->ucName, AI_MDC_MAXQPATH - 1)));
263
264
        // go to the first shader in the file. ignore the others.
265
0
        if (pcSurface->ulNumShaders) {
266
0
            const MDC::Shader *pcShader = (const MDC::Shader *)((int8_t *)pcSurface + pcSurface->ulOffsetShaders);
267
0
            pcMesh->mMaterialIndex = (unsigned int)aszShaders.size();
268
269
            // create a new shader
270
0
            aszShaders.emplace_back(pcShader->ucName,
271
0
                    ::strnlen(pcShader->ucName, sizeof(pcShader->ucName)));
272
0
        }
273
        // need to create a default material
274
0
        else if (UINT_MAX == iDefaultMatIndex) {
275
0
            pcMesh->mMaterialIndex = iDefaultMatIndex = (unsigned int)aszShaders.size();
276
0
            aszShaders.emplace_back();
277
0
        }
278
        // otherwise assign a reference to the default material
279
0
        else
280
0
            pcMesh->mMaterialIndex = iDefaultMatIndex;
281
282
        // allocate output storage for the mesh
283
0
        aiVector3D *pcVertCur = pcMesh->mVertices = new aiVector3D[pcMesh->mNumVertices];
284
0
        aiVector3D *pcNorCur = pcMesh->mNormals = new aiVector3D[pcMesh->mNumVertices];
285
0
        aiVector3D *pcUVCur = pcMesh->mTextureCoords[0] = new aiVector3D[pcMesh->mNumVertices];
286
0
        aiFace *pcFaceCur = pcMesh->mFaces = new aiFace[pcMesh->mNumFaces];
287
288
        // create all vertices/faces
289
0
        BE_NCONST MDC::Triangle *pcTriangle = (BE_NCONST MDC::Triangle *)((int8_t *)pcSurface + pcSurface->ulOffsetTriangles);
290
291
0
        BE_NCONST MDC::TexturCoord *const pcUVs = (BE_NCONST MDC::TexturCoord *)((int8_t *)pcSurface + pcSurface->ulOffsetTexCoords);
292
293
        // get a pointer to the uncompressed vertices
294
0
        int16_t iOfs = *((int16_t *)((int8_t *)pcSurface +
295
0
                                     pcSurface->ulOffsetFrameBaseFrames) +
296
0
                         this->configFrameID);
297
298
0
        AI_SWAP2(iOfs);
299
300
0
        BE_NCONST MDC::BaseVertex *const pcVerts = (BE_NCONST MDC::BaseVertex *)((int8_t *)pcSurface + pcSurface->ulOffsetBaseVerts) +
301
0
                                                   ((int)iOfs * pcSurface->ulNumVertices * 4);
302
303
        // do the main swapping stuff ...
304
#if (defined AI_BUILD_BIG_ENDIAN)
305
306
        // swap all triangles
307
        for (unsigned int i = 0; i < pcSurface->ulNumTriangles; ++i) {
308
            AI_SWAP4(pcTriangle[i].aiIndices[0]);
309
            AI_SWAP4(pcTriangle[i].aiIndices[1]);
310
            AI_SWAP4(pcTriangle[i].aiIndices[2]);
311
        }
312
313
        // swap all vertices
314
        for (unsigned int i = 0; i < pcSurface->ulNumVertices * pcSurface->ulNumBaseFrames; ++i) {
315
            AI_SWAP2(pcVerts->normal);
316
            AI_SWAP2(pcVerts->x);
317
            AI_SWAP2(pcVerts->y);
318
            AI_SWAP2(pcVerts->z);
319
        }
320
321
        // swap all texture coordinates
322
        for (unsigned int i = 0; i < pcSurface->ulNumVertices; ++i) {
323
            AI_SWAP4(pcUVs->u);
324
            AI_SWAP4(pcUVs->v);
325
        }
326
327
#endif
328
329
        // boundary check for pcVerts
330
0
        auto surfStart = reinterpret_cast<const uint8_t*>(pcSurface);
331
0
        const uint8_t* surfEnd = surfStart + pcSurface->ulOffsetEnd;
332
0
        auto vertBufStart = reinterpret_cast<const uint8_t*>(pcVerts);
333
0
        const size_t needVertBytes = sizeof(MDC::BaseVertex) * pcSurface->ulNumVertices;
334
0
        if (vertBufStart < surfStart || vertBufStart + needVertBytes > surfEnd) {
335
0
            throw DeadlyImportError("MDCImporter: pcVerts points outside of surface block.");
336
0
        }
337
338
0
        const MDC::CompressedVertex *pcCVerts = nullptr;
339
0
        int16_t *mdcCompVert = nullptr;
340
341
        // access compressed frames for large frame numbers, but never for the first
342
0
        if (this->configFrameID && pcSurface->ulNumCompFrames > 0) {
343
0
            mdcCompVert = (int16_t *)((int8_t *)pcSurface + pcSurface->ulOffsetFrameCompFrames) + this->configFrameID;
344
0
            AI_SWAP2P(mdcCompVert);
345
0
            if (*mdcCompVert >= 0) {
346
0
                pcCVerts = (const MDC::CompressedVertex *)((int8_t *)pcSurface +
347
0
                                                           pcSurface->ulOffsetCompVerts) +
348
0
                           *mdcCompVert * pcSurface->ulNumVertices;
349
0
                auto cvertBufStart = reinterpret_cast<const uint8_t*>(pcCVerts);
350
0
                const size_t needCompVertBytes = sizeof(MDC::CompressedVertex) * pcSurface->ulNumVertices;
351
0
                if (cvertBufStart < surfStart || cvertBufStart > surfEnd ||
352
0
                    needCompVertBytes > static_cast<size_t>(surfEnd - cvertBufStart)) {
353
0
                    throw DeadlyImportError("MDCImporter: pcCVerts points outside of surface block.");
354
0
                }
355
0
            } else
356
0
                mdcCompVert = nullptr;
357
0
        }
358
359
        // copy all faces
360
0
        for (unsigned int iFace = 0; iFace < pcSurface->ulNumTriangles; ++iFace,
361
0
                          ++pcTriangle, ++pcFaceCur) {
362
0
            const unsigned int iOutIndex = iFace * 3;
363
0
            pcFaceCur->mNumIndices = 3;
364
0
            pcFaceCur->mIndices = new unsigned int[3];
365
366
0
            for (unsigned int iIndex = 0; iIndex < 3; ++iIndex,
367
0
                              ++pcVertCur, ++pcUVCur, ++pcNorCur) {
368
0
                uint32_t quak = pcTriangle->aiIndices[iIndex];
369
0
                if (quak >= pcSurface->ulNumVertices) {
370
0
                    ASSIMP_LOG_ERROR("MDC vertex index is out of range");
371
0
                    quak = pcSurface->ulNumVertices - 1;
372
0
                }
373
374
                // compressed vertices?
375
0
                if (mdcCompVert) {
376
0
                    MDC::BuildVertex(*pcFrame, pcVerts[quak], pcCVerts[quak],
377
0
                            *pcVertCur, *pcNorCur);
378
0
                } else {
379
                    // copy position
380
0
                    pcVertCur->x = pcVerts[quak].x * AI_MDC_BASE_SCALING;
381
0
                    pcVertCur->y = pcVerts[quak].y * AI_MDC_BASE_SCALING;
382
0
                    pcVertCur->z = pcVerts[quak].z * AI_MDC_BASE_SCALING;
383
384
                    // copy normals
385
0
                    MD3::LatLngNormalToVec3(pcVerts[quak].normal, &pcNorCur->x);
386
387
                    // copy texture coordinates
388
0
                    pcUVCur->x = pcUVs[quak].u;
389
0
                    pcUVCur->y = ai_real(1.0) - pcUVs[quak].v; // DX to OGL
390
0
                }
391
0
                pcVertCur->x += pcFrame->localOrigin[0];
392
0
                pcVertCur->y += pcFrame->localOrigin[1];
393
0
                pcVertCur->z += pcFrame->localOrigin[2];
394
0
            }
395
396
            // swap the face order - DX to OGL
397
0
            pcFaceCur->mIndices[0] = iOutIndex + 2;
398
0
            pcFaceCur->mIndices[1] = iOutIndex + 1;
399
0
            pcFaceCur->mIndices[2] = iOutIndex + 0;
400
0
        }
401
402
0
        pcSurface = reinterpret_cast<BE_NCONST MDC::Surface *>((BE_NCONST int8_t *)pcSurface + pcSurface->ulOffsetEnd);
403
0
    }
404
405
    // create a flat node graph with a root node and one child for each surface
406
0
    if (!pScene->mNumMeshes)
407
0
        throw DeadlyImportError("Invalid MDC file: File contains no valid mesh");
408
0
    else if (1 == pScene->mNumMeshes) {
409
0
        pScene->mRootNode = new aiNode();
410
0
        if (nullptr != pScene->mMeshes[0]) {
411
0
            pScene->mRootNode->mName = pScene->mMeshes[0]->mName;
412
0
            pScene->mRootNode->mNumMeshes = 1;
413
0
            pScene->mRootNode->mMeshes = new unsigned int[1];
414
0
            pScene->mRootNode->mMeshes[0] = 0;
415
0
        }
416
0
    } else {
417
0
        pScene->mRootNode = new aiNode();
418
0
        pScene->mRootNode->mNumChildren = pScene->mNumMeshes;
419
0
        pScene->mRootNode->mChildren = new aiNode *[pScene->mNumMeshes];
420
0
        pScene->mRootNode->mName.Set("<root>");
421
0
        for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
422
0
            aiNode *pcNode = pScene->mRootNode->mChildren[i] = new aiNode();
423
0
            pcNode->mParent = pScene->mRootNode;
424
0
            pcNode->mName = pScene->mMeshes[i]->mName;
425
0
            pcNode->mNumMeshes = 1;
426
0
            pcNode->mMeshes = new unsigned int[1];
427
0
            pcNode->mMeshes[0] = i;
428
0
        }
429
0
    }
430
431
    // create materials
432
0
    pScene->mNumMaterials = (unsigned int)aszShaders.size();
433
0
    pScene->mMaterials = new aiMaterial *[pScene->mNumMaterials];
434
0
    for (unsigned int i = 0; i < pScene->mNumMaterials; ++i) {
435
0
        aiMaterial *pcMat = new aiMaterial();
436
0
        pScene->mMaterials[i] = pcMat;
437
438
0
        const std::string &name = aszShaders[i];
439
440
0
        int iMode = (int)aiShadingMode_Gouraud;
441
0
        pcMat->AddProperty<int>(&iMode, 1, AI_MATKEY_SHADING_MODEL);
442
443
        // add a small ambient color value - RtCW seems to have one
444
0
        aiColor3D clr;
445
0
        clr.b = clr.g = clr.r = 0.05f;
446
0
        pcMat->AddProperty<aiColor3D>(&clr, 1, AI_MATKEY_COLOR_AMBIENT);
447
448
0
        if (name.length())
449
0
            clr.b = clr.g = clr.r = 1.0f;
450
0
        else
451
0
            clr.b = clr.g = clr.r = 0.6f;
452
453
0
        pcMat->AddProperty<aiColor3D>(&clr, 1, AI_MATKEY_COLOR_DIFFUSE);
454
0
        pcMat->AddProperty<aiColor3D>(&clr, 1, AI_MATKEY_COLOR_SPECULAR);
455
456
0
        if (name.length()) {
457
0
            aiString path;
458
0
            path.Set(name);
459
0
            pcMat->AddProperty(&path, AI_MATKEY_TEXTURE_DIFFUSE(0));
460
0
        }
461
0
    }
462
463
    // Now rotate the whole scene 90 degrees around the x axis to convert to internal coordinate system
464
0
    pScene->mRootNode->mTransformation = aiMatrix4x4(
465
0
            1.f, 0.f, 0.f, 0.f,
466
0
            0.f, 0.f, 1.f, 0.f,
467
0
            0.f, -1.f, 0.f, 0.f,
468
0
            0.f, 0.f, 0.f, 1.f);
469
0
}
470
471
#endif // !! ASSIMP_BUILD_NO_MDC_IMPORTER