本文记录了几种常见的3D文件格式,包括:
- obj
- ply
- pcd
OBJ
OBJ从几何学上定义的文件格式。OBJ文件由一行行文本组成,每行由一两个标记字母,也就是关键字(Keyword)开头,关键字说明这一行是什么数据。
常用的关键字:
- v 几何体顶点 (Geometric vertices)
- vt 贴图坐标点 (Texture vertices):uv贴图坐标
- vn 顶点法线 (Vertex normals)
- f 面 (Face):由顶点、uv纹理坐标、法线索引确定的表面
一个立方体的例子:
# Blender v3.1.2 OBJ File: ''
# www.blender.org
mtllib mycube.mtl
o Cube
v 1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 1.000000
vt 0.625000 0.500000
vt 0.875000 0.500000
vt 0.875000 0.750000
vt 0.625000 0.750000
vt 0.375000 0.750000
vt 0.625000 1.000000
vt 0.375000 1.000000
vt 0.375000 0.000000
vt 0.625000 0.000000
vt 0.625000 0.250000
vt 0.375000 0.250000
vt 0.125000 0.500000
vt 0.375000 0.500000
vt 0.125000 0.750000
vn 0.0000 1.0000 0.0000
vn 0.0000 0.0000 1.0000
vn -1.0000 0.0000 0.0000
vn 0.0000 -1.0000 0.0000
vn 1.0000 0.0000 0.0000
vn 0.0000 0.0000 -1.0000
usemtl Material
s off
f 1/1/1 5/2/1 7/3/1 3/4/1
usemtl Material.001
f 4/5/2 3/4/2 7/6/2 8/7/2
f 8/8/3 7/9/3 5/10/3 6/11/3
f 6/12/4 2/13/4 4/5/4 8/14/4
f 2/13/5 1/1/5 3/4/5 4/5/5
f 6/11/6 5/10/6 1/1/6 2/13/6
PLY
PLY是一种多边形文件格式,有文件头。
还是立方体的例子:
ply
format ascii 1.0 { ascii/binary, format version number }
comment made by anonymous { comments keyword specified, like all lines }
comment this file is a cube
element vertex 8 { define "vertex" element, 8 of them in file }
property float32 x { vertex contains float "x" coordinate }
property float32 y { y coordinate is also a vertex property }
property float32 z { z coordinate, too }
element face 6 { there are 6 "face" elements in the file }
property list uint8 int32 vertex_index { "vertex_indices" is a list of ints }
end_header { delimits the end of the header }
0 0 0 { start of vertex list }
0 0 1
0 1 1
0 1 0
1 0 0
1 0 1
1 1 1
1 1 0
4 0 1 2 3 { start of face list }
4 7 6 5 4
4 0 4 5 1
4 1 5 6 2
4 2 6 7 3
4 3 7 4 0
PCD
一个例子:
# .PCD v.7 - Point Cloud Data file format
VERSION .7
FIELDS x y z rgb
SIZE 4 4 4 4
TYPE F FFF
COUNT 1 1 1 1
WIDTH 213
HEIGHT 1
VIEWPOINT 0 0 0 1 0 0 0
POINTS 213
DATA ascii
0.93773 0.33763 0 4.2108e+06
0.90805 0.35641 0 4.2108e+06