【问题标题】:Convert Wavefront .obj to .off将 Wavefront .obj 转换为 .off
【发布时间】:2017-06-27 19:32:23
【问题描述】:

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

【问题讨论】:

    标签: geometry file-format file-conversion wavefront


    【解决方案1】:

    您可以使用开源GUI软件Meshlab

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

    【讨论】:

    • 如果您更喜欢命令行,meshlab 与命令行版本 (meshlabserver) 捆绑在一起,可以在 CLI 上执行相同操作:meshlabserver -i input.obj -o output.off 最终还通过指定脚本文件...)
    【解决方案2】:

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

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

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

    【讨论】:

      【解决方案3】:

      这应该适用于三角形网格

      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"
      

      【讨论】:

        猜你喜欢
        • 2016-04-12
        • 2019-01-17
        • 2012-02-05
        • 2019-10-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-23
        相关资源
        最近更新 更多