1.2 Lession 1 Wavefront .obj File

[TOC]

参考

介绍

OBJ (or .OBJ)是Wavefront公司开发的3D几何定义文件。包含每个顶点的位置、纹理坐标和UV坐标、
法线等。

顶点坐标逆时针定义,所以无需法线定义。

文件格式

# this is a comment
  # List of geometric vertices, with (x, y, z [,w]) coordinates, w is optional and defaults to 1.0.
  v 0.123 0.234 0.345 1.0
  v ...
  ...
  # List of texture coordinates, in (u, [,v ,w]) coordinates, these will vary between 0 and 1. v, w are optional and default to 0.
  vt 0.500 1 [0]
  vt ...
  ...
  # List of vertex normals in (x,y,z) form; normals might not be unit vectors.
  vn 0.707 0.000 0.707
  vn ...
  ...
  # Parameter space vertices in ( u [,v] [,w] ) form; free form geometry statement ( see below )
  vp 0.310000 3.210000 2.100000
  vp ...
  ...
  # Polygonal face element (see below)
  f 1 2 3
  f 3/1 4/2 5/3
  f 6/4/1 3/5/3 7/6/5
  f 7//1 8//2 9//3
  f ...
  ...
  # Line element (see below)
  l 5 8 1 2 4 9
关键字 功能 说明
v 几何顶点 (x,y,z[,w]) 坐标,w可选,默认1,后面可能会跟RGB的顶点颜色
vt 纹理坐标 (u, [,v ,w]) coordinates, 0-1. v, w are optional and default to 0.
vn 法线 (x,y,z) form 不一定是单位向量
vp Parameter space vertices in ( u [,v] [,w] ) form
f f v1 v2 v3 .... f v1/vt1 v2/vt2 v3/vt3 ... f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 .. f v1//vn1 v2//vn2 v3//vn3 ...
l 线 l 5 8 1 2 4 9
mtllib 材质 mtllib [external .mtl file name]
l 单元格

MTL

关键字 功能 说明
newmtl 材质命名 newmtl Colored
Ka ambient color Ka 1.000 1.000 1.000
Kd diffuse color Kd 1.000 1.000 1.000
Ks specular color Ks 0.000 0.000 0.000 # black (off)
Ns weighted using the specular exponent Ns 10.000 # ranges between 0 and 1000