我该如何将Wavefront的.obj文件转换为.off文件?
这应该适用于三角网格
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"
meshlabserver -i input.obj -o output.off
(如果需要进行一些筛选,还可以通过指定脚本文件来实现...) - ALoopingIcon