select_by_index
方法通过传入索引列表,来选取 TriangleMesh
对象中指定索引的三角形网格。
select_by_index(indices: List[int]) -> open3d.geometry.TriangleMesh
indices
: 选中三角形网格的索引列表,类型为 List[int]
。返回新的 TriangleMesh
对象,该对象包含了指定索引的三角形网格。
import open3d as o3d
import numpy as np
# 创建 TriangleMesh 对象
vertices = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0.5, 0.5, 0.5]], dtype=np.float32)
triangles = np.array([[0, 1, 2], [0, 2, 3], [0, 3, 1], [1, 3, 2]], dtype=np.int32)
mesh = o3d.geometry.TriangleMesh()
mesh.vertices = o3d.utility.Vector3dVector(vertices)
mesh.triangles = o3d.utility.Vector3iVector(triangles)
# 选择指定索引的三角形网格
selected_triangles = mesh.select_by_index([0, 1])
# 显示 TriangleMesh 对象
o3d.visualization.draw_geometries([mesh, selected_triangles])