Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
#include "config.h"

#include "Headers/DVDConverter.h"
#include "Headers/MeshImporter.h"

#include <assimp/types.h>
#include <assimp/scene.h>
#include <assimp/Importer.hpp>
#include <assimp/Exporter.hpp>
#include <assimp/postprocess.h>
#include "Utility/Headers/XMLParser.h"
#include "Core/Headers/Console.h"
#include "Core/Headers/StringHelper.h"
#include "Core/Headers/PlatformContext.h"
#include "Utility/Headers/Localization.h"
#include "Platform/Video/Headers/GFXDevice.h"
#include "Geometry/Shapes/Headers/Mesh.h"
#include "Geometry/Shapes/Headers/SkinnedSubMesh.h"
#include "Geometry/Animations/Headers/SceneAnimator.h"
#include "Geometry/Animations/Headers/AnimationUtils.h"
#include "Platform/Video/Buffers/VertexBuffer/Headers/VertexBuffer.h"

namespace Divide {
    namespace {
        static const bool g_removeLinesAndPoints = true;

        struct vertexWeight {
            U8 _boneID;
            F32 _boneWeight;
            vertexWeight(U8 ID, F32 weight) : _boneID(ID), _boneWeight(weight) {}
        };

        /// Recursively creates an internal node structure matching the current scene and animation.
        Bone* createBoneTree(aiNode* pNode, Bone* parent) {
            Bone* internalNode = MemoryManager_NEW Bone(pNode->mName.data);
            // set the parent; in case this is the root node, it will be null
            internalNode->_parent = parent;

            internalNode->_localTransform = pNode->mTransformation;
            if (!Config::USE_OPENGL_RENDERING) {
                internalNode->_localTransform.Transpose();
            }

            internalNode->_originalLocalTransform = internalNode->_localTransform;
            calculateBoneToWorldTransform(internalNode);

            // continue for all child nodes and assign the created internal nodes as our
            // children recursively call this function on all children
            for (U32 i = 0; i < pNode->mNumChildren; ++i) {
                internalNode->_children.push_back(
                    createBoneTree(pNode->mChildren[i], internalNode));
            }

            return internalNode;
        }

    };

    hashMapImpl<U32, TextureWrap> DVDConverter::fillTextureWrapMap() {
        hashMapImpl<U32, TextureWrap> wrapMap;
        wrapMap[aiTextureMapMode_Wrap] = TextureWrap::CLAMP;
        wrapMap[aiTextureMapMode_Clamp] = TextureWrap::CLAMP_TO_EDGE;
        wrapMap[aiTextureMapMode_Mirror] = TextureWrap::REPEAT;
        wrapMap[aiTextureMapMode_Decal] = TextureWrap::DECAL;
        return wrapMap;
    }

    hashMapImpl<U32, Material::ShadingMode> DVDConverter::fillShadingModeMap() {
        hashMapImpl<U32, Material::ShadingMode> shadingMap;
        shadingMap[aiShadingMode_Fresnel] = Material::ShadingMode::COOK_TORRANCE;
        shadingMap[aiShadingMode_NoShading] = Material::ShadingMode::FLAT;
        shadingMap[aiShadingMode_CookTorrance] = Material::ShadingMode::COOK_TORRANCE;
        shadingMap[aiShadingMode_Minnaert] = Material::ShadingMode::OREN_NAYAR;
        shadingMap[aiShadingMode_OrenNayar] = Material::ShadingMode::OREN_NAYAR;
        shadingMap[aiShadingMode_Toon] = Material::ShadingMode::TOON;
        shadingMap[aiShadingMode_Blinn] = Material::ShadingMode::BLINN_PHONG;
        shadingMap[aiShadingMode_Phong] = Material::ShadingMode::PHONG;
        shadingMap[aiShadingMode_Gouraud] = Material::ShadingMode::BLINN_PHONG;
        shadingMap[aiShadingMode_Flat] = Material::ShadingMode::FLAT;
        return shadingMap;
    }

    hashMapImpl<U32, Material::TextureOperation> DVDConverter::fillTextureOperationMap() {
        hashMapImpl<U32, Material::TextureOperation> operationMap;
        operationMap[aiTextureOp_Multiply] = Material::TextureOperation::MULTIPLY;
        operationMap[aiTextureOp_Add] = Material::TextureOperation::ADD;
        operationMap[aiTextureOp_Subtract] = Material::TextureOperation::SUBTRACT;
        operationMap[aiTextureOp_Divide] = Material::TextureOperation::DIVIDE;
        operationMap[aiTextureOp_SmoothAdd] = Material::TextureOperation::SMOOTH_ADD;
        operationMap[aiTextureOp_SignedAdd] = Material::TextureOperation::SIGNED_ADD;
        operationMap[/*aiTextureOp_Replace*/ 7] = Material::TextureOperation::REPLACE;
        return operationMap;
    }


    hashMapImpl<U32, TextureWrap>
    DVDConverter::aiTextureMapModeTable = DVDConverter::fillTextureWrapMap();
    hashMapImpl<U32, Material::ShadingMode>
    DVDConverter::aiShadingModeInternalTable = DVDConverter::fillShadingModeMap();
    hashMapImpl<U32, Material::TextureOperation>
    DVDConverter::aiTextureOperationTable = DVDConverter::fillTextureOperationMap();

DVDConverter::DVDConverter()
{
}

DVDConverter::DVDConverter(PlatformContext& context, Import::ImportData& target, const stringImpl& file, bool& result) {
    result = load(context, target, file);
}

DVDConverter::~DVDConverter()
{
}

bool DVDConverter::load(PlatformContext& context, Import::ImportData& target, const stringImpl& file) {
    Assimp::Importer importer;

    importer.SetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE,
                                g_removeLinesAndPoints ? aiPrimitiveType_LINE | aiPrimitiveType_POINT
                                                       : 0);

    importer.SetPropertyInteger(AI_CONFIG_IMPORT_TER_MAKE_UVS, 1);
    importer.SetPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE, 80.0f);

    U32 ppsteps =
        aiProcess_TransformUVCoords |  // preprocess UV transformations
                                       // (scaling, translation ...)
        aiProcess_FindInstances |      // search for instanced meshes and remove
                                       // them by references to one master
        aiProcess_OptimizeMeshes |     // join small meshes, if possible;
        aiProcess_OptimizeGraph |      // Nodes without
                                       // animations/bones/lights/cameras are
                                       // collapsed & joined.
        aiProcess_CalcTangentSpace | aiProcess_GenSmoothNormals |
        aiProcess_JoinIdenticalVertices | aiProcess_ImproveCacheLocality |
        aiProcess_LimitBoneWeights | aiProcess_RemoveRedundantMaterials |
        aiProcess_Triangulate | aiProcess_GenUVCoords | aiProcess_SortByPType |
        aiProcess_FindDegenerates | aiProcess_FindInvalidData | 0;

    if (!Config::USE_OPENGL_RENDERING) {
        ppsteps |= aiProcess_ConvertToLeftHanded;
    }

    const aiScene* aiScenePointer = importer.ReadFile(file.c_str(), ppsteps);

    if (!aiScenePointer) {
        Console::errorfn(Locale::get(_ID("ERROR_IMPORTER_FILE")), file.c_str(),
                         importer.GetErrorString());
        return nullptr;
    }

    target._hasAnimations = aiScenePointer->HasAnimations();
    if (target._hasAnimations) {
        target._skeleton = createBoneTree(aiScenePointer->mRootNode, nullptr);
        target._bones.reserve(to_int(target._skeleton->hierarchyDepth()));

        for (U16 meshPointer = 0; meshPointer < aiScenePointer->mNumMeshes; ++meshPointer) {
            const aiMesh* mesh = aiScenePointer->mMeshes[meshPointer];
            for (U32 n = 0; n < mesh->mNumBones; ++n) {
                const aiBone* bone = mesh->mBones[n];

                Bone* found = target._skeleton->find(bone->mName.data);
                assert(found != nullptr);

                found->_offsetMatrix = bone->mOffsetMatrix;
                target._bones.push_back(found);
            }
        }

        for (size_t i(0); i < aiScenePointer->mNumAnimations; i++) {
            aiAnimation* animation = aiScenePointer->mAnimations[i];
            if (animation->mDuration > 0.0f) {
                target._animations.push_back(std::make_shared<AnimEvaluator>(animation, to_uint(i)));
            }
        }
    }
    
    U32 vertCount = 0;
    for (U16 n = 0; n < aiScenePointer->mNumMeshes; ++n) {
        vertCount += aiScenePointer->mMeshes[n]->mNumVertices;
    }

    target._vertexBuffer = context.gfx().newVB();
    target._vertexBuffer->useLargeIndices(vertCount + 1 > std::numeric_limits<U16>::max());
    target._vertexBuffer->setVertexCount(vertCount);

    U8 submeshBoneOffset = 0;
    U32 previousOffset = 0;
    U32 numMeshes = aiScenePointer->mNumMeshes;
    target._subMeshData.reserve(numMeshes);

    for (U16 n = 0; n < numMeshes; ++n) {
        aiMesh* currentMesh = aiScenePointer->mMeshes[n];
        // Skip points and lines ... for now -Ionut
        if (currentMesh->mNumVertices == 0) {
            continue;
        }

        Import::SubMeshData subMeshTemp;

        subMeshTemp._name = currentMesh->mName.C_Str();
        subMeshTemp._index = to_uint(n);
        if (subMeshTemp._name.empty()) {
            subMeshTemp._name = Util::StringFormat("%s-submesh-%d", 
                                                   file.substr(file.rfind("/") + 1, file.length()).c_str(),
                                                   n);
        }
       
        subMeshTemp._boneCount = currentMesh->mNumBones;
        loadSubMeshGeometry(currentMesh, 
                            target._vertexBuffer,
                            subMeshTemp,
                            submeshBoneOffset,
                            previousOffset);

        loadSubMeshMaterial(subMeshTemp._material,
                            aiScenePointer->mMaterials[currentMesh->mMaterialIndex],
                            subMeshTemp._name + "_material",
                            file,
                            subMeshTemp._boneCount > 0);
                            

        target._subMeshData.push_back(subMeshTemp);
    }

    return true;
}

void DVDConverter::loadSubMeshGeometry(const aiMesh* source,
                                       VertexBuffer* targetBuffer,
                                       Import::SubMeshData& subMeshData,
                                       U8& submeshBoneOffsetOut,
                                       U32& previousVertOffset) {
    BoundingBox importBB;
    U32 previousOffset = previousVertOffset;
    previousVertOffset += source->mNumVertices;

    for (U32 j = 0; j < source->mNumVertices; ++j) {
        U32 idx = j + previousOffset;
        targetBuffer->modifyPositionValue(idx, source->mVertices[j].x,
                                               source->mVertices[j].y,
                                               source->mVertices[j].z);

        targetBuffer->modifyNormalValue(idx, source->mNormals[j].x,
                                             source->mNormals[j].y,
                                             source->mNormals[j].z);

        importBB.add(targetBuffer->getPosition(idx));
    }
    
    subMeshData._minPos = importBB.getMin();
    subMeshData._maxPos = importBB.getMax();

    if (source->mTextureCoords[0] != nullptr) {
        for (U32 j = 0; j < source->mNumVertices; ++j) {
            targetBuffer->modifyTexCoordValue(j + previousOffset,
                                             source->mTextureCoords[0][j].x,
                                             source->mTextureCoords[0][j].y);
        }
    }

    if (source->mTangents != nullptr) {
        for (U32 j = 0; j < source->mNumVertices; ++j) {
            targetBuffer->modifyTangentValue(j + previousOffset,
                                             source->mTangents[j].x,
                                             source->mTangents[j].y,
                                             source->mTangents[j].z);
        }
    } else {
        Console::d_printfn(Locale::get(_ID("SUBMESH_NO_TANGENT")), subMeshData._name.c_str());
    }

    if (source->mNumBones > 0) {
        assert(source->mNumBones < std::numeric_limits<U8>::max());  ///<Fit in U8

        vectorImpl<vectorImpl<vertexWeight> > weightsPerVertex(source->mNumVertices);
        for (U8 a = 0; a < source->mNumBones; ++a) {
            const aiBone* bone = source->mBones[a];
            for (U32 b = 0; b < bone->mNumWeights; ++b) {
                weightsPerVertex[bone->mWeights[b].mVertexId].push_back(
                    vertexWeight(a, bone->mWeights[b].mWeight));
            }
        }

        vec4<F32> weights;
        P32       indices;
        for (U32 j = 0; j < source->mNumVertices; ++j) {
            U32 idx = j + previousOffset;

            indices.i = 0;
            weights.reset();
            // guaranteed to be max 4 thanks to aiProcess_LimitBoneWeights 
            for (U8 a = 0; a < weightsPerVertex[j].size(); ++a) {
                indices.b[a] = to_ubyte(weightsPerVertex[j][a]._boneID + submeshBoneOffsetOut);
                weights[a] = weightsPerVertex[j][a]._boneWeight;
            }

            targetBuffer->modifyBoneIndices(idx, indices);
            targetBuffer->modifyBoneWeights(idx, weights);
        }

        submeshBoneOffsetOut += to_ubyte(source->mNumBones);
    }

    U32 currentIndice = 0;
    vec3<U32> triangleTemp;

    subMeshData._triangles.reserve(source->mNumFaces * 3);
    for (U32 k = 0; k < source->mNumFaces; k++) {
        // guaranteed to be 3 thanks to aiProcess_Triangulate 
        for (U32 m = 0; m < 3; ++m) {
            currentIndice = source->mFaces[k].mIndices[m] + previousOffset;
            targetBuffer->addIndex(currentIndice);
            triangleTemp[m] = currentIndice;
        }

        subMeshData._triangles.push_back(triangleTemp);
    }

    subMeshData._partitionOffset = to_uint(targetBuffer->partitionBuffer());
}

void DVDConverter::loadSubMeshMaterial(Import::MaterialData& material,
                                       const aiMaterial* source,
                                       const stringImpl& materialName,
                                       const stringImpl& assetLocation,
                                       bool skinned) {

    material._name = materialName;
    Material::ColourData& data = material._colourData;
    // default diffuse colour
    data._diffuse.set(0.8f, 0.8f, 0.8f, 1.0f);
    // Load diffuse colour
    aiColor4D diffuse;
    if (AI_SUCCESS == aiGetMaterialColor(source, AI_MATKEY_COLOR_DIFFUSE, &diffuse)) {
        data._diffuse.setV(&diffuse.r);
    } else {
        Console::d_printfn(Locale::get(_ID("MATERIAL_NO_DIFFUSE")), materialName.c_str());
    }

    // Ignore ambient colour
    vec4<F32> ambientTemp(0.0f, 0.0f, 0.0f, 1.0f);
    aiColor4D ambient;
    if (AI_SUCCESS == aiGetMaterialColor(source, AI_MATKEY_COLOR_AMBIENT, &ambient)) {
        ambientTemp.setV(&ambient.r);
    } else {
        // no ambient
    }

    // default specular colour
    data._specular.set(1.0f, 1.0f, 1.0f, 1.0f);
    // Load specular colour
    aiColor4D specular;
    if (AI_SUCCESS == aiGetMaterialColor(source, AI_MATKEY_COLOR_SPECULAR, &specular)) {
        data._specular.setV(&specular.r);
    } else {
        Console::d_printfn(Locale::get(_ID("MATERIAL_NO_SPECULAR")), materialName.c_str());
    }

    // default emissive colour
    data._emissive.set(0.0f, 0.0f, 0.0f, 1.0f);
    // Load emissive colour
    aiColor4D emissive;
    if (AI_SUCCESS == aiGetMaterialColor(source, AI_MATKEY_COLOR_EMISSIVE, &emissive)) {
        data._emissive.setV(&emissive.r);
    }

    // Load material opacity value
    aiGetMaterialFloat(source, AI_MATKEY_OPACITY, &data._diffuse.a);

    // default shading model
    I32 shadingModel = to_const_int(Material::ShadingMode::PHONG);
    // Load shading model
    aiGetMaterialInteger(source, AI_MATKEY_SHADING_MODEL, &shadingModel);
    material._shadingMode = aiShadingModeInternalTable[shadingModel];

    // Default shininess values
    F32 shininess = 15, strength = 1;
    // Load shininess
    aiGetMaterialFloat(source, AI_MATKEY_SHININESS, &shininess);
    // Load shininess strength
    aiGetMaterialFloat(source, AI_MATKEY_SHININESS_STRENGTH, &strength);
    F32 finalValue = shininess * strength;
    CLAMP<F32>(finalValue, 0.0f, 255.0f);
    data._shininess = finalValue;

    // check if material is two sided
    I32 two_sided = 0;
    aiGetMaterialInteger(source, AI_MATKEY_TWOSIDED, &two_sided);
    material._doubleSided = two_sided != 0;

    aiString tName;
    aiTextureMapping mapping;
    U32 uvInd;
    F32 blend;
    aiTextureOp op = aiTextureOp_Multiply;
    aiTextureMapMode mode[3] = {_aiTextureMapMode_Force32Bit,
                                _aiTextureMapMode_Force32Bit,
                                _aiTextureMapMode_Force32Bit};

    U8 count = 0;
    // Compare load results with the standard success value
    aiReturn result = AI_SUCCESS;
    // While we still have diffuse textures
    while (result == AI_SUCCESS) {
        // Load each one
        result = source->GetTexture(aiTextureType_DIFFUSE, count, &tName,
                                    &mapping, &uvInd, &blend, &op, mode);
        if (result != AI_SUCCESS) {
            break;
        }
        // get full path
        stringImpl path(Paths::g_assetsLocation + Paths::g_texturesLocation + tName.data);

        FileWithPath fileResult = splitPathToNameAndLocation(path);
        const stringImpl& img_name = fileResult._fileName;
        const stringImpl& img_path = fileResult._path;

        // if we have a name and an extension
        if (!img_name.substr(img_name.find_first_of(".")).empty()) {

            ShaderProgram::TextureUsage usage = count == 1 ? ShaderProgram::TextureUsage::UNIT1
                                                           : ShaderProgram::TextureUsage::UNIT0;

            Import::TextureEntry& texture = material._textures[to_uint(usage)];

            // Load the texture resource
            if (IS_IN_RANGE_INCLUSIVE(mode[0], aiTextureMapMode_Wrap,
                                      aiTextureMapMode_Decal) &&
                IS_IN_RANGE_INCLUSIVE(mode[1], aiTextureMapMode_Wrap,
                                      aiTextureMapMode_Decal) &&
                IS_IN_RANGE_INCLUSIVE(mode[2], aiTextureMapMode_Wrap,
                                      aiTextureMapMode_Decal)) {
                texture._wrapU = aiTextureMapModeTable[mode[0]];
                texture._wrapV = aiTextureMapModeTable[mode[1]];
                texture._wrapW = aiTextureMapModeTable[mode[2]];
            }
            texture._textureName = img_name;
            texture._texturePath = img_path;
            // The first texture is always "Replace"
            texture._operation = count == 0 ? Material::TextureOperation::REPLACE
                                            : aiTextureOperationTable[op];
            material._textures[to_uint(usage)] = texture;
                                                                
        }  // endif

        tName.Clear();
        count++;
        if (count == 2) {
            break;
        }
        STUBBED("ToDo: Use more than 2 textures for each material. Fix This! -Ionut")
    }  // endwhile

    result = source->GetTexture(aiTextureType_NORMALS, 0, &tName, &mapping,
                                &uvInd, &blend, &op, mode);
    if (result == AI_SUCCESS) {
        stringImpl path(Paths::g_assetsLocation + Paths::g_texturesLocation + tName.data);

        FileWithPath fileResult = splitPathToNameAndLocation(path);
        const stringImpl& img_name = fileResult._fileName;
        const stringImpl& img_path = fileResult._path;

        Import::TextureEntry& texture = material._textures[to_const_uint(ShaderProgram::TextureUsage::NORMALMAP)];

        if (img_name.rfind('.') != stringImpl::npos) {
            if (IS_IN_RANGE_INCLUSIVE(mode[0], aiTextureMapMode_Wrap,
                                      aiTextureMapMode_Decal) &&
                IS_IN_RANGE_INCLUSIVE(mode[1], aiTextureMapMode_Wrap,
                                      aiTextureMapMode_Decal) &&
                IS_IN_RANGE_INCLUSIVE(mode[2], aiTextureMapMode_Wrap,
                                      aiTextureMapMode_Decal)) {
                texture._wrapU = aiTextureMapModeTable[mode[0]];
                texture._wrapV = aiTextureMapModeTable[mode[1]];
                texture._wrapW = aiTextureMapModeTable[mode[2]];
            }
            texture._textureName = img_name;
            texture._texturePath = img_path;
            texture._operation = aiTextureOperationTable[op];
            material._textures[to_const_uint(ShaderProgram::TextureUsage::NORMALMAP)] = texture;
            material._bumpMethod = Material::BumpMethod::NORMAL;
        }  // endif
    } // endif

    result = source->GetTexture(aiTextureType_HEIGHT, 0, &tName, &mapping,
                                &uvInd, &blend, &op, mode);
    if (result == AI_SUCCESS) {
        stringImpl path(Paths::g_assetsLocation + Paths::g_texturesLocation + tName.data);

        FileWithPath fileResult = splitPathToNameAndLocation(path);
        const stringImpl& img_name = fileResult._fileName;
        const stringImpl& img_path = fileResult._path;

        Import::TextureEntry& texture = material._textures[to_const_uint(ShaderProgram::TextureUsage::NORMALMAP)];
        if (img_name.rfind('.') != stringImpl::npos) {
            if (IS_IN_RANGE_INCLUSIVE(mode[0], aiTextureMapMode_Wrap,
                                      aiTextureMapMode_Decal) &&
                IS_IN_RANGE_INCLUSIVE(mode[1], aiTextureMapMode_Wrap,
                                      aiTextureMapMode_Decal) &&
                IS_IN_RANGE_INCLUSIVE(mode[2], aiTextureMapMode_Wrap,
                                      aiTextureMapMode_Decal)) {
                texture._wrapU = aiTextureMapModeTable[mode[0]];
                texture._wrapV = aiTextureMapModeTable[mode[1]];
                texture._wrapW = aiTextureMapModeTable[mode[2]];
            }
            texture._textureName = img_name;
            texture._texturePath = img_path;
            texture._operation = aiTextureOperationTable[op];
            material._textures[to_const_uint(ShaderProgram::TextureUsage::NORMALMAP)] = texture;
            material._bumpMethod = Material::BumpMethod::NORMAL;
        }  // endif
    } // endif

    I32 flags = 0;
    aiGetMaterialInteger(source, AI_MATKEY_TEXFLAGS_DIFFUSE(0), &flags);
    material._ignoreAlpha = (flags & aiTextureFlags_IgnoreAlpha) != 0;

    if (!material._ignoreAlpha) {
        result = source->GetTexture(aiTextureType_OPACITY, 0, &tName, &mapping,
                                    &uvInd, &blend, &op, mode);
        if (result == AI_SUCCESS) {
            stringImpl path(Paths::g_assetsLocation + Paths::g_texturesLocation + tName.data);

            FileWithPath fileResult = splitPathToNameAndLocation(path);
            const stringImpl& img_name = fileResult._fileName;
            const stringImpl& img_path = fileResult._path;

            Import::TextureEntry& texture = material._textures[to_const_uint(ShaderProgram::TextureUsage::OPACITY)];

            if (img_name.rfind('.') != stringImpl::npos) {
                if (IS_IN_RANGE_INCLUSIVE(mode[0], aiTextureMapMode_Wrap,
                                          aiTextureMapMode_Decal) &&
                    IS_IN_RANGE_INCLUSIVE(mode[1], aiTextureMapMode_Wrap,
                                          aiTextureMapMode_Decal) &&
                    IS_IN_RANGE_INCLUSIVE(mode[2], aiTextureMapMode_Wrap,
                                          aiTextureMapMode_Decal)) {
                    texture._wrapU = aiTextureMapModeTable[mode[0]];
                    texture._wrapV = aiTextureMapModeTable[mode[1]];
                    texture._wrapW = aiTextureMapModeTable[mode[2]];
                }
                texture._textureName = img_name;
                texture._texturePath = img_path;
                texture._operation = aiTextureOperationTable[op];
                material._textures[to_const_uint(ShaderProgram::TextureUsage::OPACITY)] = texture;
                material._doubleSided = true;
            }  // endif
        } 
    }

    result = source->GetTexture(aiTextureType_SPECULAR, 0, &tName, &mapping,
                                &uvInd, &blend, &op, mode);
    if (result == AI_SUCCESS) {
        stringImpl path(Paths::g_assetsLocation + Paths::g_texturesLocation + tName.data);

        FileWithPath fileResult = splitPathToNameAndLocation(path);
        const stringImpl& img_name = fileResult._fileName;
        const stringImpl& img_path = fileResult._path;

        Import::TextureEntry& texture = material._textures[to_const_uint(ShaderProgram::TextureUsage::SPECULAR)];
        if (img_name.rfind('.') != stringImpl::npos) {
            if (IS_IN_RANGE_INCLUSIVE(mode[0], aiTextureMapMode_Wrap,
                                      aiTextureMapMode_Decal) &&
                IS_IN_RANGE_INCLUSIVE(mode[1], aiTextureMapMode_Wrap,
                                      aiTextureMapMode_Decal) &&
                IS_IN_RANGE_INCLUSIVE(mode[2], aiTextureMapMode_Wrap,
                                      aiTextureMapMode_Decal)) {
                texture._wrapU = aiTextureMapModeTable[mode[0]];
                texture._wrapV = aiTextureMapModeTable[mode[1]];
                texture._wrapW = aiTextureMapModeTable[mode[2]];
            }
            texture._textureName = img_name;
            texture._texturePath = img_path;
            texture._operation = aiTextureOperationTable[op];
            material._textures[to_const_uint(ShaderProgram::TextureUsage::SPECULAR)] = texture;
        }  // endif
    }      // endif
}
};

Commits for Divide-Framework/trunk/Source Code/Geometry/Importer/DVDConverter.cpp

Diff revisions: vs.
Revision Author Commited Message
832 Diff Diff IonutCava picture IonutCava Thu 26 Jan, 2017 17:23:11 +0000

[IonutCava]
- More path related work
- Initial code to centralize file I/O (does not compile yet)

830 Diff Diff IonutCava picture IonutCava Wed 25 Jan, 2017 17:29:44 +0000

[IonutCava]
- Add a new Platform element: File
— Move all predefined paths to FileManagement System
- Split MathHelper into MathHelper and StringHelper

829 Diff Diff IonutCava picture IonutCava Tue 24 Jan, 2017 17:28:39 +0000

[IonutCava]
- Separate resourceLocation for resources into resourceLocation and resourceName.
- More XML config loading refactoring

804 Diff Diff IonutCava picture IonutCava Thu 01 Dec, 2016 17:20:59 +0000

[IonutCava]
- Singleton elimination update Part I: get it to compile
— The following classes are no longer Singletons: GFXDevice, GL_API, DX_API, SFXWrapper, FmodWrapper, SDLWrapper, ALWrapper, PXDevice, InputInterface, RenderPassManager, SceneManager and ResourceManager;
— Refactor system to a Context / Component based implementation (Pass relevant context to objects: e.g. GFXDevice object to Textures, GUI to GUIElements, etc)
— Make devices and managers components of the kernel
— Allow multiple Resource caches to co-exist. This may prove useful for later when a more fragmented memory model is need (per frame / per scene / global caches / etc)

  • next steps: part II – cleanup/refactor new code, part III – optimise code, part IV – remove remaining Singletons (e.g. Application, ParamHandler, FrameListenerManager, Recast, PostFX and DebugInterface)
801 Diff Diff IonutCava picture IonutCava Sun 27 Nov, 2016 21:28:01 +0000

[IonutCava]
- More performance analysis guided optimizations.
- Some refactoring to allow later removal of Singletons status for: GFXDevice, SFXDevice, PXDevice, GUI and Input.
— Pass a PlatformContext around objects to access these classes.

776 Diff Diff IonutCava picture IonutCava Thu 06 Oct, 2016 15:57:56 +0000

[IonutCava]
- Improve the CommandBuffer system to include the notion of a RenderPass /RenderSubPass with output render target info stored in them (not used yet)

753 Diff Diff IonutCava picture IonutCava Thu 28 Jul, 2016 14:26:48 +0000

[IonutCava]
- Very small cleanup and renaming changes
- Updated PhysX build as well

721 Diff Diff IonutCava picture IonutCava Wed 08 Jun, 2016 15:47:49 +0000

[IonutCava]
- Spelling: change all references from our code of “color” to the PROPER British version of “colour” because it sounds 100x better

712 Diff Diff IonutCava picture IonutCava Tue 24 May, 2016 16:18:37 +0000

[IonutCava]
- Added the concept of “buffer” to be used by GenericVertexData and ShaderBuffer without caring if it’s persistent or not.
— Persistent buffers handle their own locking instead of relying on the parent class
- HiZ occlusion culling fixes and optimizations

693 IonutCava picture IonutCava Thu 28 Apr, 2016 16:19:35 +0000

[IonutCava]
- Cleanup Time and Profiling code