我注意到trimesh.section
方法返回一个Path3D
,其中相交面的索引被粘贴到路径的metadata['face_index']
中。我还注意到,人脸索引的数量与路径实体的节点数量相对应:
paths = inner.section(plane_origin=origin, plane_normal=norm)
assert(len([node for path in paths.entities for node in path.nodes]) == len(paths.metadata['face_index']))
然而,对于路径实体的节点,face_index似乎是无序的。给定一个特定的路径实体,如何在网格上找到路径实体所在的面?
我能够用face_ajacency图找到要删除的面,但似乎必须有更好的方法来做到这一点,因为这项工作基本上已经在对section
:的调用中完成了
paths = inner.section(plane_origin=origin, plane_normal=norm)
# find the closed path entity with a centroid nearest to the plane origin
nearest, idx = _find_nearest_closed_path(origin, paths)
face_adjacency = trimesh.graph.face_adjacency(inner.faces[paths.metadata['face_index']])
graph = nx.Graph()
graph.add_edges_from(face_adjacency)
ccs = list(nx.connected_components(graph))
nearest, idx = _find_nearest_closed_path(origin, paths)
# making a big assumption that the connected_components are in the same order as the Path3D entities...
remove_faces = paths.metadata['face_index'][np.asarray(list(ccs[idx]))]
mask = np.full(inner.faces.shape[0], True, dtype=bool)
mask[remove_faces] = False
# update the mesh
inner.update_faces(mask)