DirectX/C++ Issue Rendering 3D models Texture Using DirectX11

  .obj, assimp, c++, directx-11, visual-studio

Half The Model Is not applying any texture properly

I am currently using assimp to import .obj files and when I apply any texture to the model.

Currently how I load in the model data

bool Model::LoadModel(const std::string& filePath)
{
    Assimp::Importer importer;
    const aiScene* pScene = importer.ReadFile
    (
        filePath,
        aiProcess_Triangulate | aiProcess_ConvertToLeftHanded
    );

    if (pScene == nullptr)
        return false;

    this->ProcessNode(pScene->mRootNode, pScene);

    return true;
}

void Model::ProcessNode(aiNode* node, const aiScene* scene)
{
    for (UINT i = 0; i < node->mNumMeshes; i++)
    {
        aiMesh* mesh = scene->mMeshes[node->mMeshes[i]];
        meshes.push_back(this->ProcessMesh(mesh, scene));
    }

    for (UINT i = 0; i < node->mNumChildren; i++)
    {
        this->ProcessNode(node->mChildren[i], scene);
    }
}

Mesh Model::ProcessMesh(aiMesh* mesh, const aiScene* scene)
{
    // Data to fill
    std::vector<Vertex> vertices;
    std::vector<DWORD> indices;

    //Get vertices
    for (UINT i = 0; i < mesh->mNumVertices; i++)
    {
        Vertex vertex;

        vertex.pos.x = mesh->mVertices[i].x;
        vertex.pos.y = mesh->mVertices[i].y;
        vertex.pos.z = mesh->mVertices[i].z;

        if (mesh->mTextureCoords[0])
        {
            vertex.texCoord.x = (float)mesh->mTextureCoords[0][i].x;
            vertex.texCoord.y = (float)mesh->mTextureCoords[0][i].y;
        }

        vertices.push_back(vertex);
    }

Not sure if there is something wrong with the way I load the indices in or something to do with the UV’s. From what I’ve gathered all the information should be read in properly.

Source: Windows Questions C++

LEAVE A COMMENT