Function import


#include <Source/Falcor/Scene/Importers/AssimpImporter.h>

static bool import(const std::string &filename, SceneBuilder &builder, const SceneBuilder::InstanceMatrices &instances, const Dictionary &dict)


No description yet.


Lines 995-1094 in Source/Falcor/Scene/Importers/AssimpImporter.cpp. Line 36 in Source/Falcor/Scene/Importers/AssimpImporter.h.

bool AssimpImporter::import(const std::string& filename, SceneBuilder& builder, const SceneBuilder::InstanceMatrices& instances, const Dictionary& dict)
    TimeReport timeReport;
    std::string fullpath;
    if (findFileInDataDirectories(filename, fullpath) == false)
        logError("Can't find file '" + filename + "'");
        return false;
    const SceneBuilder::Flags builderFlags = builder.getFlags();
    uint32_t assimpFlags = aiProcessPreset_TargetRealtime_MaxQuality |
        aiProcess_FlipUVs |
    assimpFlags &= ~(aiProcess_CalcTangentSpace); // Never use Assimp's tangent gen code
    assimpFlags &= ~(aiProcess_FindDegenerates); // Avoid converting degenerated triangles to lines
    assimpFlags &= ~(aiProcess_OptimizeGraph); // Never use as it doesn't handle transforms with negative determinants
    assimpFlags &= ~(aiProcess_RemoveRedundantMaterials); // Avoid merging materials as it doesn't load all fields we care about, we merge in 'SceneBuilder' instead.
    assimpFlags &= ~(aiProcess_SplitLargeMeshes); // Avoid splitting large meshes
    if (is_set(builderFlags, SceneBuilder::Flags::DontMergeMeshes)) assimpFlags &= ~aiProcess_OptimizeMeshes; // Avoid merging original meshes
    // Configure importer to remove vertex components we don't support.
    // It'll load faster and helps 'aiProcess_JoinIdenticalVertices' find identical vertices.
    int removeFlags = aiComponent_COLORS;
    for (uint32_t uvLayer = 1; uvLayer < AI_MAX_NUMBER_OF_TEXTURECOORDS; uvLayer++) removeFlags |= aiComponent_TEXCOORDSn(uvLayer);
    if (!is_set(builderFlags, SceneBuilder::Flags::UseOriginalTangentSpace)) removeFlags |= aiComponent_TANGENTS_AND_BITANGENTS;
    Assimp::Importer importer;
    importer.SetPropertyInteger(AI_CONFIG_PP_RVC_FLAGS, removeFlags);
    const aiScene* pScene = importer.ReadFile(fullpath, assimpFlags);
    timeReport.measure("Loading asset file");
    if (pScene == nullptr)
        std::string str("Can't open file '");
        str = str + std::string(filename) + "'\n" + importer.GetErrorString();
        return false;
    timeReport.measure("Verifying scene");
    // Extract the folder name
    auto last = fullpath.find_last_of("/\\");
    std::string modelFolder = fullpath.substr(0, last);
    ImporterData data(pScene, builder, instances);
    // Enable special treatment for obj and gltf files
    ImportMode importMode = ImportMode::Default;
    if (hasSuffix(filename, ".obj", false)) importMode = ImportMode::OBJ;
    if (hasSuffix(filename, ".gltf", false) || hasSuffix(filename, ".glb", false)) importMode = ImportMode::GLTF2;
    if (createAllMaterials(data, modelFolder, importMode) == false)
        logError("Can't create materials for model " + filename);
        return false;
    timeReport.measure("Creating materials");
    if (createSceneGraph(data) == false)
        logError("Can't create draw lists for model " + filename);
        return false;
    timeReport.measure("Creating scene graph");
    addMeshInstances(data, data.pScene->mRootNode);
    timeReport.measure("Creating meshes");
    if (createAnimations(data) == false)
        logError("Can't create animations for model " + filename);
        return false;
    timeReport.measure("Creating animations");
    if (createCameras(data, importMode) == false)
        logError("Can't create a camera for model " + filename);
        return false;
    timeReport.measure("Creating cameras");
    if (createLights(data) == false)
        logError("Can't create a lights for model " + filename);
        return false;
    timeReport.measure("Creating lights");
    return true;

Add Discussion as Guest

Log in