2

I have integrated 'Assimp' librairy to load my OBJ/MTL files components.

All works correctly.

But let's have a focus on a following MTL file example:

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

newmtl PlaneMtl
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2

map_Ka ambient_texture.jpg
map_Kd diffuse_texture.jpg
map_Ks specular_texture.jpg
map_Bump bump_texture.jpg

And let's examine the following code:

aiMesh *pMesh = scene->mMeshes[idz];
aiMaterial *pMaterial = scene->mMaterials[pMesh->mMaterialIndex];

aiString ambient_texture_path, diffuse_texture_path, specular_texture_path, bump_texture_path;
pMaterial->GetTexture(aiTextureType_AMBIENT, 0, &ambient_texture_path);
pMaterial->GetTexture(aiTextureType_DIFFUSE, 0, &diffuse_texture_path);
pMaterial->GetTexture(aiTextureType_SPECULAR, 0, &specular_texture_path);
pMaterial->GetTexture(aiTextureType_HEIGHT, 0, &bump_texture_path);

std::cout << "AmbientTexture: " << ambient_texture_path.C_Str() << std::endl;
std::cout << "DiffuseTexture: " << diffuse_texture_path.C_Str() << std::endl;
std::cout << "SpecularTexture: " << specular_texture_path.C_Str() << std::endl;
std::cout << "BumpTexture: " << bump_texture_path.C_Str() << std::endl;

Here's the output:

ambient_texture.jpg
diffuse_texture.jpg
specular_texture.jpg
bump_texture.jpg

As you can see all works perfectly and the keywords 'map_Ka, map_Kd, map_Ks and map_Bump' refer to ambient, diffuse, specular and bump (height) map respectively. So these keywords are correct.

But what about normal texture (for normal mapping) and displacement texture (for displacement mapping) for example ?

I tried to add the following lines in my MTL file to test:

map_Normal normal_texture.jpg
map_Disp disp_texture.jpg

using the code:

aiString normal_texture_path, displacement_texture_path;

pMaterial->GetTexture(aiTextureType_NORMALS, 0, &normal_texture_path);
pMaterial->GetTexture(aiTextureType_DISPLACEMENT, 0, &displacement_texture_path);

std::cout << "NormalTexture: " << normal_texture_path.C_Str() << std::endl;
std::cout << "DispTexture: " << displacement_texture_path.C_Str() << std::endl;

and the output:

NormalTexture:
DispTexture:

So the keyword 'map_Normal' and 'map_Disp' are not corrects and so are not part of Wavefront MTL documentation.

I couldn't try to find a correct and official documentation about WaveFront MTL format (only the ones on Wikipedia or tutorials nut nothing official and complete).

Does it exist an official documentation about Wavefront MTL and OBJ format with all the keywords explained within ?

If it's not the case does anyone knows the keywords for normal and displacement texture ?

genpfault
  • 51,148
  • 11
  • 85
  • 139
user1364743
  • 5,283
  • 6
  • 51
  • 90

2 Answers2

2

I know this is an old question, but I needed to use normal maps, and I'm using Assimp and OBJ files, so I searched and found the answer to this. After looking at the source code of Assimp you can see in assimp/code/ObjFileMtlImporter.cpp:

static const std::string DiffuseTexture      = "map_Kd";
static const std::string AmbientTexture      = "map_Ka";
static const std::string SpecularTexture     = "map_Ks";
static const std::string OpacityTexture      = "map_d";
static const std::string EmissiveTexture    = "map_emissive";
static const std::string EmissiveTexture_1  = "map_Ke";
static const std::string BumpTexture1        = "map_bump";
static const std::string BumpTexture2        = "map_Bump";
static const std::string BumpTexture3        = "bump";
static const std::string NormalTexture       = "map_Kn";
static const std::string ReflectionTexture   = "refl";
static const std::string DisplacementTexture = "disp";
static const std::string SpecularityTexture = "map_ns";

So as you can see, Assimp use map_Kn to refer to normal textures anddisp for displacement textures (confirmed when I loaded a model after modifying its MTL).

genpfault
  • 51,148
  • 11
  • 85
  • 139
Chadys
  • 156
  • 2
  • 5
  • According to [Wikipedia](https://en.wikipedia.org/wiki/Wavefront_.obj_file), one group wants people to use ``norm`` for normal maps. – Chuck Walbourn Jun 12 '18 at 22:40
0

Alias/Wavefront is now so old and passed through so many owning companies that I very much doubt you will find an 'official' specification anywhere.

I suggest the excellent write-up by Paul Bourke, which includes the keywords details for bump and displacement maps. (But not normal maps - I don't think they were ever official for OBJ)

http://paulbourke.net/dataformats/mtl/

Hope this helps.

Hugh Fisher
  • 2,321
  • 13
  • 8