open3d 构建mesh

  • 方法一
    使用顶点坐标以及三角形索引。这有点像OpenGL了。
# 输入是顶点以及每个三角形的索引
def get_non_manifold_vertex_mesh(verts, triangles):
    # verts = np.array(
    #     [
    #         [-1, 0, -1],
    #         [1, 0, -1],
    #         [0, 1, -1],
    #         [0, 0, 0],
    #         [-1, 0, 1],
    #         [1, 0, 1],
    #         [0, 1, 1],
    #     ],
    #     dtype=np.float64,
    # )

    # triangles = np.array([
    #     [0, 1, 2],
    #     [0, 1, 3],
    #     [1, 2, 3],
    #     [2, 0, 3],
    #     [4, 5, 6],
    #     [4, 5, 3],
    #     [5, 6, 3],
    #     [4, 6, 3],
    # ]) 
    
    mesh = o3d.geometry.TriangleMesh()
    mesh.vertices = o3d.utility.Vector3dVector(verts)
    mesh.triangles = o3d.utility.Vector3iVector(triangles)
    mesh.compute_vertex_normals()  # 估计法向量后支持光照渲染
    
    # mesh.compute_triangle_normals()
    # mesh.rotate(
    #     mesh.get_rotation_matrix_from_xyz((np.pi / 4, 0, np.pi / 4)),
    #     center=mesh.get_center(),
    # )
    
    return mesh


axis_pcd = o3d.geometry.TriangleMesh.create_coordinate_frame(size=8, origin=[0, 0, 0])

o3d.visualization.draw_geometries([mesh,
                                   axis_pcd
                                   ],
                                  # zoom=0.3412,
                                  # front=[0.4257, -0.2125, -0.8795],
                                  # lookat=[2.6172, 2.0475, 1.532],
                                  # up=[-0.0694, -0.9768, 0.2024]
                                  # point_show_normal=True
                                  )

你可能感兴趣的:(图形与渲染,图形学)