将Wavefront .obj转换为.off格式。

4
3个回答

3
您可以使用开源的GUI软件MeshLab
  • 文件 > 导入网格 (Ctrl-I)
  • 文件 > 导出网格为 并选择“对象文件格式(.off)”

4
如果您喜欢使用命令行,MeshLab有一个命令行版本(MeshLabServer),可以在命令行界面上执行相同的操作:meshlabserver -i input.obj -o output.off (如果需要进行一些筛选,还可以通过指定脚本文件来实现...) - ALoopingIcon

2

您可以使用CLI、闭源、仅二进制的meshconv工具进行操作。

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

然而,我的结果似乎与我在Meshlab中得到的答案有些不同,因为我无法在CGAL中加载生成的.off文件(错误看起来像这个)。


-1

这应该适用于三角网格

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"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接