Search code examples
c++openglassimp

Assimp Loading Emission Map


I'm using Assimp to load my models and meshes which has been working great until now. I'm trying to load an emission map from a .mtl file generated when I export a .obj file from blender. It loads the diffuse, normal and specular maps just fine, but for some reason, it doesnt seem to find the emission map in the file at all.

Here is the .mtl file:

# Blender MTL File: 'basiclevel.blend'
# Material Count: 1

newmtl megaGem
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
map_Kd Textures\gemB_diff.jpg
map_Ke Textures\gemB_emit.jpg
map_Ks Textures\gemB_spec.jpg
map_Bump Textures\gemB_norm.jpg

(I have shortened the file paths as they were long and quite unclear, the diffuse, normal and specular maps load and render just fine)

I am loading the textures like so:

std::vector<glTexture> emissionTextures = loadTextures(
    material,
    aiTextureType_EMISSIVE,
    MAP_TYPE::EMISSION
);
meshTextures.insert(
    meshTextures.end(),
    emissionTextures.begin(),
    emissionTextures.end()
);
if (emissionTextures.size() > 0) {
    meshMaterial.emissionTexture = emissionTextures[0];
}

Where loadTextures() is just a function that gets the texture paths in the mtl file corresponding to the aiTextureType, and either loads them from file or gets them from the cache if they have been loaded before. Again this is working completely fine for everything except the emission textures. (Also, excuse the hacky way of checking the length of the vector and grabbing the first one, I need to figure out a nicer way of checking if textures of that type have been loaded in the future).

I'm thinking that the aiTextureType aiTextureType_EMISSIVE maybe doesnt correspond correctly to the mtl map_Ke tag? Which would explain why my ResourceManager doesn't even attempt to load it.

Is aiTextureType_EMISSIVE the correct thing I should be checking here? If not, how should I be checking for emission maps in my obj files corresponding material file?


Solution

  • It is a known bug of assimp (https://github.com/assimp/assimp/issues/804) that was resolved. But if you're like me and have an older version, the map_Ke tag isn't mapped to aiTextureType_EMISSIVE. The solution is to instead use the keyword map_emissive in your .mtl file that assimp recognises for emissive texture (in earlier version, it handles both keywords)