java - 正在解析 .obj 文件 : How to do materials/textures?

标签 java opengl graphics jogl .obj

我是 OpenGL 的新手。我正在使用 JOGL 玩弄它。我正在使用这个 model .

我成功地将它渲染到窗口。但是,我想应用纹理/ Material 。我不太确定该怎么做。

来自 .obj 文件:

f 6307/4525/3 6303/4524/3 6327/4523/3 6315/4526/3
usemtl kahki_light_pave_W.png
f 6445/3470/305 6437/4623/305 6593/4624/305 6597/4625/305
f 6594/4626/306 6438/4627/306 6446/4628/306 6598/4629/306
f 6595/4630/307 6439/4631/307 6447/4632/307 6599/4633/307
f 6448/3482/308 6440/4634/308 6596/4635/308 6600/4636/308

维基百科告诉我,在 usemtl 语句之后和下一个 usemtl 语句之前的所有内容都应该使用 khaki_light_pave_W.png。但是,我不确定如何在 OpenGL 中执行此操作。

文件顶部定义了一堆顶点:

v 19.886690 3.093822 -21.149584
v 23.886690 3.093822 -21.149584
vt 0.918121 0.920883
vt 0.918121 0.959193
vt -0.537323 1.541370
vt -0.537323 1.503060
vt 0.462677 0.503060

我需要为纹理使用 vt 顶点吗? f 语句包含索引。这些指标是否进入 v 顶点、vt 或两者?

最佳答案

tl;dr:vt 条目指定纹理坐标,f 条目索引(从 1 开始!)到三个单独的数组(vvtvn)。

来自spec ,“引用顶点数据”部分:

For all elements, reference numbers are used to identify geometric vertices, texture vertices, vertex normals, and parameter space vertices.

Each of these types of vertices is numbered separately, starting with 1. This means that the first geometric vertex in the file is 1, the second is 2, and so on. The first texture vertex in the file is 1, the second is 2, and so on. The numbering continues sequentially throughout the entire file. Frequently, files have multiple lists of vertex data. This numbering sequence continues even when vertex data is separated by other data.

In addition to counting vertices down from the top of the first list in the file, you can also count vertices back up the list from an element's position in the file. When you count up the list from an element, the reference numbers are negative. A reference number of -1 indicates the vertex immediately above the element. A reference number of -2 indicates two references above and so on

关于java - 正在解析 .obj 文件 : How to do materials/textures?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3738080/

相关文章:

iphone - 绘制视网膜分辨率的图像反射

java - Cassandra 每日数据清除?

java - List的逐次继承

c++ - 如何在 OpenGL 中更改对象的旋转速率?

c++ - sdl表面到opengl纹理

graphics - "translate"图形对象是什么意思?

c# - 在大于 5000x3000 的桌面上绘制单个移动图像的最快方法?

java - 在 Eclipse 中使用 windowbuilder 在哪里下载 Windows XP 的外观?

java - 如何在Spring@RestController中映射多个bean?

c++ - 如何为圆环创建索引