本文主要介绍,如何从MeshLab中导出过滤器脚本(.mlx)以及如何在python中通过PyMeshLab包调用该脚本从而实现批量处理的功能。下面以网格remesh为例进行详细介绍:
一、导出过滤器脚本
(1) 首先将网格导入到MeshLab软件中;
(2) 从菜单Filters 按下图所示选择相应功能,
然后它会弹出如下窗口:
根据需要设置需要的阈值,再点击Apply, 网格就变成为下图所示:
(3)然后导出.mlx过滤器文件:
弹出对话框:
点击 Save Script将其保存在某个地方,命名为remesh.mlx, 其内容如下:
<!DOCTYPE FilterScript>
<FilterScript>
<filter name="Remeshing: Isotropic Explicit Remeshing">
<Param tooltip="Number of iterations of the remeshing operations to repeat on the mesh." value="3" description="Iterations" type="RichInt" name="Iterations"/>
<Param tooltip="Toggles adaptive isotropic remeshing." value="false" description="Adaptive remeshing" type="RichBool" name="Adaptive"/>
<Param tooltip="If checked the remeshing operations will be applied only to the selected faces." value="false" description="Remesh only selected faces" type="RichBool" name="SelectedOnly"/>
<Param max="16.5006" tooltip="Sets the target length for the remeshed mesh edges." value="0.16501" description="Target Length" type="RichAbsPerc" name="TargetLen" min="0"/>
<Param tooltip="Minimum angle between faces of the original to consider the shared edge as a feature to be preserved." value="30" description="Crease Angle" type="RichFloat" name="FeatureDeg"/>
<Param tooltip="If toggled each local operation must deviate from original mesh by [Max. surface distance]" value="false" description="Check Surface Distance" type="RichBool" name="CheckSurfDist"/>
<Param max="16.5006" tooltip="Maximal surface deviation allowed for each local operation" value="0.16501" description="Max. Surface Distance" type="RichAbsPerc" name="MaxSurfDist" min="0"/>
<Param tooltip="If checked the remeshing operations will include a refine step." value="true" description="Refine Step" type="RichBool" name="SplitFlag"/>
<Param tooltip="If checked the remeshing operations will include a collapse step." value="true" description="Collapse Step" type="RichBool" name="CollapseFlag"/>
<Param tooltip="If checked the remeshing operations will include a edge-swap step, aimed at improving the vertex valence of the resulting mesh." value="true" description="Edge-Swap Step" type="RichBool" name="SwapFlag"/>
<Param tooltip="If checked the remeshing operations will include a smoothing step, aimed at relaxing the vertex positions in a Laplacian sense." value="true" description="Smooth Step" type="RichBool" name="SmoothFlag"/>
<Param tooltip="If checked the remeshing operations will include a step to reproject the mesh vertices on the original surface." value="true" description="Reproject Step" type="RichBool" name="ReprojectFlag"/>
</filter>
</FilterScript>
至此,我们已经实现如何从MeshLab中导出所需的过滤器脚本。
二、在python中通过PyMeshLab包调用该脚本从而实现相应的功能
(1)首先需要安装pymeshlab包
(2)其次,调用的代码示例如下:
import pymeshlab as ml
import os
data_path = r'E:\remesh_example\full_upper/'
files_list = os.listdir(data_path)
out_path = r'E:\remesh_example\full_upper_out/'
if not os.path.exists(out_path):
os.mkdir(out_path)
ms = ml.MeshSet()
for file in files_list:
ms.load_new_mesh(os.path.join(data_path,file))
ms.load_filter_script('remesh.mlx')
ms.apply_filter_script()
ms.save_current_mesh(os.path.join(out_path,file))
仿照上面这些步骤,我们也可以从meshlab中导出其他过滤器脚本,从而在python中实现你想要的功能。
参考:meshlab - 2020.12 Meshlabserver.exe 在哪里 - IT工具网 (coder.work)https://www.coder.work/article/7748126