2

我已经集成了“Assimp”库来加载我的 OBJ/MTL 文件组件。

一切正常。

但让我们关注以下 MTL 文件示例:

# 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

让我们检查以下代码:

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;

这是输出:

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

如您所见,所有功能都完美无缺,关键字“map_Ka、map_Kd、map_Ks 和 map_Bump”分别指的是环境、漫反射、镜面反射和凹凸(高度)贴图。所以这些关键词是正确的。

但是例如法线纹理(用于法线贴图)和置换纹理(用于置换贴图)呢?

我试图在我的 MTL 文件中添加以下行来测试:

map_Normal normal_texture.jpg
map_Disp disp_texture.jpg

使用代码:

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;

和输出:

NormalTexture:
DispTexture:

因此关键字“map_Normal”和“map_Disp”不正确,因此不是 Wavefront MTL 文档的一部分。

我无法尝试找到有关 WaveFront MTL 格式的正确和官方文档(只有 Wikipedia 或教程上的文档,没有任何官方和完整的文档)。

是否存在有关 Wavefront MTL 和 OBJ 格式的官方文档,其中解释了所有关键字?

如果不是这样,有人知道法线和置换纹理的关键字吗?

4

2 回答 2

2

我知道这是一个老问题,但我需要使用法线贴图,而且我使用的是 Assimp 和 OBJ 文件,所以我搜索并找到了答案。查看 Assimp 的源代码后,您可以看到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";

如您所见,Assimp 用于map_Kn引用普通纹理和disp置换纹理(在修改 MTL 后加载模型时确认)。

于 2017-04-28T14:13:22.090 回答
0

Alias/Wavefront 现在已经很老了,并且通过了很多拥有公司,我非常怀疑你会在任何地方找到“官方”规范。

我建议 Paul Bourke 撰写出色的文章,其中包括凹凸贴图和置换贴图的关键字详细信息。(但不是法线贴图——我不认为它们是 OBJ 的官方贴图)

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

希望这可以帮助。

于 2014-10-20T02:00:03.363 回答