c++ - NormalTexture 在 Wavefront 资源 Material 格式中如何表示?

标签 c++ opengl assimp wavefront

我已经集成了“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 格式的正确且官方的文档(只有维基百科或教程上的文档没有任何官方和完整的内容)。

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

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

最佳答案

我知道这是一个老问题,但我需要使用法线贴图,并且我正在使用 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 后加载模型时确认)。

关于c++ - NormalTexture 在 Wavefront 资源 Material 格式中如何表示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26453143/

相关文章:

c++ - 光线追踪 - 折射错误

C++ 策略对象和构建器模式

C++ 初学者 : what is the point of using a variable by reference if using "const"?

ios - 在 IOS 中使用线程时,assimp 无法导入 3d 模型

c++ - OpenGL 中的访问冲突

c++ - Assimp 不在 OpenGL 中的 MD5 模型 Bob 的节点中加载骨骼名称

c++ - 在 C Linux 中使用三个线程使用信号量同步按顺序打印 3 4 5 50 次

c++ - SwapBuffers 随着时间的推移变慢

c++ - Opengl 三角形基准

c++ - Phong 照明模型实际上并没有照亮任何东西