import - Assimp 与 MeshLab Wavefront 对象 (.obj) 导入

标签 import 3d wavefront assimp meshlab

我想知道为什么当我使用 Assimp 库导入 Wavefront 对象文件 (.obj) 时,它会使某些顶点加倍,我在 Assimp SourceForge 讨论 ( http://sourceforge.net/p/assimp/discussion/817654/thread/026e9640/?limit=25#ba6c ) 中找到了以下答案:

Imagine the following: You upload a range of vertices to the graphics card. You then tell the GPU via an index buffer that you want the first triangle to be formed by vertex 3, 6 and 7. The second triangle is then 1, 2 and 6. What would happen? The GPU would draw you a cube, but each corner of the cube would share the same UV data, normal vectors, vertex colours or whatever else your mesh needs.

Now how do we get a cube corner but get different UV mappings on all sides touching that corner? We can't tell the GPU to "use vertex 3, but instead of the UV coords of that vertex, please use UV coords instead." The GPU can't do this. That's why it's necessary to duplicate the vertex at that corner. Now you have two vertices for the same position, but with different UV coords.

And that's what Assimp is doing for you. If you do specify JoinIdenticalVertices, you'll get a cube with 24 vertices. Why? A cube has 8 corners, but there are 3 cube sides touching at each corner, and each of that cube sides has a different UV coords set for that corner, so you end up with 3 versions of each corner. If you do not specify JoinIdenticalVertices, you get a plain array of vertices without any reuse. And that means that you need 2 triangles with 3 vertices each for every cube side, ending up at 36 vertices.

An alternative would be to use 3D uv coords and a cube map to texture that cube. This is a special case that only works for a cube, but there it would work. The GPU does the mapping to 6 textures internally then. The description above is the general case, it works like this for each and every mesh that you might encounter.

这确实有道理。
假设我不知道MeshLab如何处理.obj导入操作,如果我找到的答案是正确的,那么当我导入这样一个对象时,顶点计数器不会'增加吗?这只是他们如何进行计数的问题还是有办法导入 .obj 文件而不必在具有法线/切线/UV 时分割顶点?

最佳答案

这不是特定于实现的(例如,它们有多个向量 - 每个变量一个),但逻辑是相同的。

Meshlab 为每个 3D 坐标生成一个顶点,除了公共(public)位置之外,还具有多个可能的变量“值”,例如法线和纹理。这些顶点存储在顶点向量中。

这些多个值存储在单独的顶点数据向量(我将其称为 VDV)中。三角形面将指向 VDV 中的 3 个条目,但顶点可以指向任意数量的条目。

在渲染时,VDV 将用于索引目的,但在计算内容和计算顶点数时使用实际顶点。他们对正常的东西有单独的“组合”值,考虑了所有相邻的面。

关于import - Assimp 与 MeshLab Wavefront 对象 (.obj) 导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26024283/

相关文章:

php - 将多个文本文件导入到mysql数据库中的不同表中

import - 是否可以只从包中导入一个函数?

python - 如何在 matplotlib 中对条形图制作 3d 效果?

CSS 3D 变换在 Chrome 16 中随机工作

c++ - 了解现代 OpenGL 中的代码绘制 .obj 并设置不同的位置

java - NoClassDefFoundError:org/jagatoo/input/listeners/InputListener

MATLAB : import package for base class

c++ - 使用 OpenGL 渲染 3D 对象(.obj 文件)时闪烁

java - 从相机获取物体坐标

opengl - 显示不全是三角形或四边形的 .obj 文件