将Wavefront .obj转换为.off

时间:2017-02-09 17:03:37

标签: geometry file-format file-conversion wavefront

如何将Wavefront's .obj文件转换为.off file

3 个答案:

答案 0 :(得分:2)

您可以使用开源GUI软件Meshlab

  • Import Mesh> File(Ctrl-I)
  • Export Mesh As> PYTHONPATH并选择“目标文件格式(.off)”

答案 1 :(得分:1)

您可以使用CLI,闭源,仅二进制,meshconv

chmod u+x meshconv
./meshconv input.obj -c off -o output.off

Howether结果似乎与我在使用Meshlab的答案中得到的结果略有不同,因为我无法在CGAL中加载生成的.off文件(错误看起来像this one)。

答案 2 :(得分:0)

这应该适用于三角形网格

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"