将 Wavefront .obj 转换为 .off
Convert Wavefront .obj to .off
如何转换 Wavefront's .obj file to a .off file?
您可以使用开源 GUI 软件 Meshlab。
File
> Import Mesh
(Ctrl-I)
File
> Export Mesh As
并选择 "Object file format (.off)"
您可以使用 CLI,闭源,仅限二进制文件,meshconv
chmod u+x meshconv
./meshconv input.obj -c off -o output.off
但是结果似乎与我使用 Meshlab 得到的答案有点不同,因为我无法在 CGAL 中加载生成的 .off 文件(错误看起来像 this one)。
这应该适用于三角形网格
def conv_obj(file):
x = open(file)
k = 0
while "\n" in x.readline():
k += 1
x = open(file)
out = str()
v = 0
f = 0
for i in range(k) :
y = x.readline().split()
if len(y) > 0 and y[0] == "v" :
v += 1
out += str(y[1]) + " " + str(y[2]) + " " + str(y[3]) + "\n"
if len(y) > 0 and y[0] == "f" :
f += 1
out += "3 " + str(int(y[1])-1) + " " + str(int(y[2])-1) + " " + str(int(y[3])-1) + "\n"
out1 = "OFF\n" + str(v) + " " + str(f) + " " + "0" + "\n" + out
w = open(file.strip("obj") + "off", "w")
w.write(out1)
w.close()
x.close()
return "done"
如何转换 Wavefront's .obj file to a .off file?
您可以使用开源 GUI 软件 Meshlab。
File
>Import Mesh
(Ctrl-I)File
>Export Mesh As
并选择 "Object file format (.off)"
您可以使用 CLI,闭源,仅限二进制文件,meshconv
chmod u+x meshconv
./meshconv input.obj -c off -o output.off
但是结果似乎与我使用 Meshlab 得到的答案有点不同,因为我无法在 CGAL 中加载生成的 .off 文件(错误看起来像 this one)。
这应该适用于三角形网格
def conv_obj(file):
x = open(file)
k = 0
while "\n" in x.readline():
k += 1
x = open(file)
out = str()
v = 0
f = 0
for i in range(k) :
y = x.readline().split()
if len(y) > 0 and y[0] == "v" :
v += 1
out += str(y[1]) + " " + str(y[2]) + " " + str(y[3]) + "\n"
if len(y) > 0 and y[0] == "f" :
f += 1
out += "3 " + str(int(y[1])-1) + " " + str(int(y[2])-1) + " " + str(int(y[3])-1) + "\n"
out1 = "OFF\n" + str(v) + " " + str(f) + " " + "0" + "\n" + out
w = open(file.strip("obj") + "off", "w")
w.write(out1)
w.close()
x.close()
return "done"