3dmax做一个box;
导出为cube1.obj;
记事本打开看一下该obj文件;
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
# File Created: 10.06.2023 23:16:04
mtllib cube1.mtl
#
# object Box001
#
v -41.2323 0.0000 31.8849
v -41.2323 0.0000 -1.4230
v -10.7806 0.0000 -1.4230
v -10.7806 0.0000 31.8849
v -41.2323 19.6241 31.8849
v -10.7806 19.6241 31.8849
v -10.7806 19.6241 -1.4230
v -41.2323 19.6241 -1.4230
# 8 vertices
vn 0.0000 -1.0000 -0.0000
vn 0.0000 1.0000 -0.0000
vn 0.0000 0.0000 1.0000
vn 1.0000 0.0000 -0.0000
vn 0.0000 0.0000 -1.0000
vn -1.0000 0.0000 -0.0000
# 6 vertex normals
vt 1.0000 0.0000 0.0000
vt 1.0000 1.0000 0.0000
vt 0.0000 1.0000 0.0000
vt 0.0000 0.0000 0.0000
# 4 texture coords
g Box001
usemtl wire_143225087
s 2
f 1/1/1 2/2/1 3/3/1 4/4/1
s 4
f 5/4/2 6/1/2 7/2/2 8/3/2
s 8
f 1/4/3 4/1/3 6/2/3 5/3/3
s 16
f 4/4/4 3/1/4 7/2/4 6/3/4
s 32
f 3/4/5 2/1/5 8/2/5 7/3/5
s 64
f 2/4/6 1/1/6 5/2/6 8/3/6
# 6 polygons
先初步看一下资料;
由v开头行都表示顶点的信息:
v 开头表示一个位置信息;
vt 开头表示一个uv坐标信息;
vn 开头表示一个法线信息;
以f开头的行表示面的顶点索引;
下面初步的先读取一下前面的数量信息;VC6单文档工程;
void CObjtestView::OnDraw(CDC* pDC)
{
CObjtestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int vnNum=0, vtNum=0, vNum=0, fNum=0;
CStdioFile file;
CString strline;
CString str1;
if(NULL != file.Open("cube2.obj", CFile::modeRead))
{
while (file.ReadString(strline))
{
if (strline[0] == 'v') {
if (strline[1] == 'n') {//vn
vnNum++;
}
else if (strline[1] == 't') {//vt
vtNum++;
}
else {//v
vNum++;
}
}
if (strline[0] == 'f') {
fNum++;
}
}
file.Close();
}
else
{
AfxMessageBox("文件打开失败!");
}
str1.Format("位置信息:%d", vNum);
pDC->TextOut(20, 20, str1);
str1.Format("法线信息:%d", vnNum);
pDC->TextOut(20, 50, str1);
str1.Format("uv坐标信息:%d", vtNum);
pDC->TextOut(20, 80, str1);
str1.Format("面:%d", fNum);
pDC->TextOut(20, 110, str1);
}
运行如下;
再做一个锥体,导出为cube2.obj;
cube2.obj;
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
# File Created: 11.06.2023 00:00:56
mtllib cube2.mtl
#
# object Pyramid001
#
v -30.7754 31.3645 15.8823
v -37.3507 0.0050 23.6445
v -24.2001 0.0050 23.6445
v -24.2001 0.0050 8.1202
v -37.3507 0.0050 8.1202
v -30.7754 0.0050 15.8823
# 6 vertices
vn 0.0000 0.2403 0.9707
vn 0.9787 0.2052 -0.0000
vn 0.0000 0.2403 -0.9707
vn -0.9787 0.2052 -0.0000
vn 0.0000 -1.0000 -0.0000
# 5 vertex normals
vt 0.5000 1.0000 0.0000
vt 0.0000 0.0000 0.0000
vt 1.0000 0.0000 0.0000
vt 0.0764 0.0000 0.0000
vt 1.0764 0.0000 0.0000
vt 0.0000 1.0000 0.0000
vt 0.5000 0.5000 0.0000
vt 1.0000 1.0000 0.0000
# 8 texture coords
g Pyramid001
usemtl wire_061135006
s 4
f 1/1/1 2/2/1 3/3/1
s 2
f 1/1/2 3/4/2 4/5/2
s 16
f 1/1/3 4/2/3 5/3/3
s 32
f 1/1/4 5/4/4 2/5/4
s 8
f 2/6/5 6/7/5 3/8/5
f 3/8/5 6/7/5 4/3/5
f 4/3/5 6/7/5 5/2/5
f 5/2/5 6/7/5 2/6/5
# 0 polygons - 8 triangles
读取此obj文件的数量信息如下;不知道3dmax导出锥体为什么有8个面,可能是一个面是2个三角形面;
要读取的文件放到源码目录;