c++ - Assimp 面孔指数

标签 c++ opengl assimp

我已经使用 Assimp 一段时间了,现在我正在尝试加载 .obj 文件。它加载完美,但我想在加载后操作面部数据。

基本上我在简单的cube.obj文件中有这个(完整文件 - http://pastebin.com/ha3VkZPM)

# 8 Vertices
v -1.0 -0.003248 1.0
v 1.0 -0.003248 1.0
v -1.0 1.996752 1.0
v 1.0 1.996752 1.0
v 1.0 -0.003248 -1.0
v -1.0 -0.003248 -1.0
v 1.0 1.996752 -1.0
v -1.0 1.996752 -1.0


# 36 Texture Coordinates
vt 1.0 0.0
vt 0.0 0.0
...

# 36 Vertex Normals
vn 0.0 0.0 1.0
vn 0.0 0.0 1.0
...

f 1/1/1 2/2/2 3/3/3
f 2/4/4 4/5/5 3/6/6
f 5/7/7 6/8/8 7/9/9
f 6/10/10 8/11/11 7/12/12
f 3/13/13 6/14/14 1/15/15
f 3/16/16 8/17/17 6/18/18
f 7/19/19 2/20/20 5/21/21
f 7/22/22 4/23/23 2/24/24
f 3/25/25 7/26/26 8/27/27
f 3/28/28 4/29/29 7/30/30
f 2/31/31 6/32/32 5/33/33
f 2/34/34 1/35/35 6/36/36

据我了解,面输入是 V/T/N(顶点索引、纹理坐标索引和法线索引)。

所以 f 1/1/1 2/2/2 3/3/3 表示一个由顶点 (1,2,3) 组成的三角形 - 对吗?

从此面条目中 - 我只想提取顶点索引。

现在进入 Assimp - 我现在有了这个 - 其中 Indices 是一个 STL::vector

for (uint32 i = 0; i < pMesh->mNumFaces; i++) {
    const aiFace& Face = pMesh->mFaces[i];
    if(Face.mNumIndices == 3) {
        Indices.push_back(Face.mIndices[0]);
        Indices.push_back(Face.mIndices[1]);
        Indices.push_back(Face.mIndices[2]);

}

以下是 pMesh->mNumFace = 12 的值 - 所以这是正确的。

(for 1st face) 
Face.mindices[0] should probably point to 1/1/1
Face.mindices[1] should probably point to 2/2/2
Face.mindices[2] should probably point to 3/3/3

现在如何仅提取顶点索引?当我检查 Face.mIndices[0] 的值时,其索引分别为 0,1,2... 为什么会这样? Assimp Faces all have indices (0,1,2)

我在 Google 和 StackOverflow 上进行了搜索 - 这里有一些类似的问题,但我似乎无法弄清楚。

https://stackoverflow.com/questions/32788756/how-to-keep-vertex-order-from-obj-file-using-assimp-library

Assimp and D3D model loading: Mesh not being displayed in D3D

Assimp not properly loading indices

如果您需要更多信息,请告诉我。谢谢。

最佳答案

OpenGL 和 DirectX 使用与 obj 格式略有不同的索引顶点数据的方式。与可以对位置/纹理坐标等使用不同索引的文件格式相比,显卡需要为整个顶点使用一个索引缓冲区。

蜜蜂说:Assimp 传递 obj 格式并将其转换为单索引缓冲区表示形式。基本上这意味着,每个唯一的顶点-纹理坐标-法线组合将给出一个顶点,而索引缓冲区指向这个新的顶点列表。

据我所知,使用 Assimp 访问原始索引是不可能的。

关于c++ - Assimp 面孔指数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32847055/

相关文章:

c++ - 复制嵌套 vector 的最简单方法是什么

C++ : how can I fourier transform an array into an other array of different size using fftw3

c++ - 虚拟赋值运算符不允许 static_cast

c - GLib:哈希表无法正确找到值

c++ - 如何改进我的 C++ 代码?

opengl - 如何在四边形的正面和背面设置不同的颜色

c++ - 需要 OpenGL/PBO 像素绘图示例

c++ - glGetUniformIndices 没有返回正确的索引

c++ - strncasecmp 和 strcasecmp 尚未声明

ios - ARKit 中带有动画的 .fbx 文件