【问题标题】:WaveFront .obj files - What does the "f" command do?WaveFront .obj 文件 - “f”命令有什么作用?
【发布时间】:2013-05-26 11:22:43
【问题描述】:

我一直在阅读 David Brackeen 的 Developing Games In Java。直到现在我都明白了书中的一切。在 Wavefront 对象文件中,我了解 v 命令的作用,但我不了解 f 命令。例如:

# OBJ - Wavefront object file
# The javagamebook loader only understands these commands:
#   mtllib <filename>    - Load materials from an external .mtl
#                          file.
#   v <x> <y> <z>        - Define a vertex with floating-point
#                          coords (x,y,z).
#   f <v1> <v2> <v3> ... - Define a new face. a face is a flat,
#                          convex polygon with vertices in
#                          counter-clockwise order. Positive
#                          numbers indicate the index of the
#                          vertex that is defined in the file.
#                          Negative numbers indicate the vertex
#                          defined relative to last vertex read.
#                          For example, 1 indicates the first
#                          vertex in the file, -1 means the last
#                          vertex read, and -2 is the vertex
#                          before that.
#   g <name>             - Define a new group by name. The faces
#                          following are added to this group.
#   usemtl <name>        - Use the named material (loaded from a
#                          .mtl file) for the faces in this group.

# load materials
mtllib textures.mtl

# define vertices
v 16 32 16
v 16 32 -16
v 16 0 16
v 16 0 -16
v -16 32 16
v -16 32 -16
v -16 0 16
v -16 0 -16

g myCube
usemtl wall1
f 1 3 4 2
f 6 8 7 5
f 2 6 5 1
f 3 7 8 4
f 1 5 7 3
f 4 8 6 2

f 命令在这里有什么作用?

【问题讨论】:

    标签: java wavefront


    【解决方案1】:

    一个立方体有八个角(由顶点或点表示),由 v 定义(v 表示顶点)一个面 (f) 是由角的坐标 (v) 定义的表面,有关说明,请参见 @987654321 @。

        v1+-----------+  v2
         /            /
        /     f1     /
       /            /
    v4+------------+v3
      |            |
      |            |
      |     f2     |
      |            |
      |            |
    v6+------------+v5
    

    这意味着面f1是由v1、v2、v3和v4定义的; f2 通过 v4、v3、v5、v6。

    【讨论】:

    • 您已经交换了 v3 和 v4。在问题中,f1 是 1 3 4 2,逆时针方向。
    【解决方案2】:

    f 表示模型的一个面(例如,三角形或四边形)。这些数字是顶点列表中的索引,指示您应该将其连接起来以形成面的方式。

    在发布的 obj 文件中,您找到的第一个 f 表示该面由一个四边形(因为有 4 个顶点)组成,顶点为 #1、#3、#4 和 #2。

    重要提示:您应该按指定顺序连接顶点,以避免以后法线计算出现问题和/或非多边形(自相交)形状出现问题。

    【讨论】:

      猜你喜欢
      • 2012-07-14
      • 2015-08-15
      • 2019-10-18
      • 2011-12-09
      • 2013-09-06
      • 2010-10-19
      • 2012-02-05
      • 2012-08-20
      • 2016-08-27
      相关资源
      最近更新 更多