使用pymeshlab时无法保存网格(MeshSet.save_current_mesh())

问题描述 投票:0回答:1

我尝试了最简单的 Pymeshlab 示例,但出现异常。

import pymeshlab


ms = pymeshlab.MeshSet()
ms.load_new_mesh('test.obj')
ms.generate_convex_hull()
ms.save_current_mesh('convex_hull.ply')
File "main.py", line 7, in <module>
    ms.save_current_mesh('convex_hull.ply')
pymeshlab.pmeshlab.PyMeshLabException

异常很奇怪。它什么都不包含。

Screen shoot

我的obj文件是正常的。我的 python 版本是 3.11.2

谁能告诉我怎么处理?

python pymeshlab
1个回答
0
投票

我可以确认这个测试用例在我的电脑上运行,所以你可以试试这个来调试你的程序。

  1. 我建议调试您的代码,添加如下行:
print(ms.current_mesh().vertex_number(),'vertex')
print(ms.current_mesh().face_number(), 'faces')

在调用

ms.generate_convex_hull()
之前和之后。这允许检查网格是否已正确导入和构建。请注意,您的输入网格可能会以某种方式退化(例如,在您的屏幕截图中,每个 Z 坐标都具有相同的值)。

  1. 确保您有权在执行脚本的目录(包含 test.obj 文件的同一目录)中写入文件。尝试使用纯 python 编写一个小文本文件,(不是 meshlab)
with open("convex_hull.txt", "w") as f:
    print("Test file output", file=f)
    print(ms.current_mesh().vertex_number(),'vertex', file=f)
    print(ms.current_mesh().face_number(), 'faces', file=f)
© www.soinside.com 2019 - 2024. All rights reserved.