1# Open3D: www.open3d.org 2# The MIT License (MIT) 3# See license file or visit www.open3d.org for details 4 5import copy 6import numpy as np 7from open3d import * 8 9if __name__ == "__main__": 10 11 print("Testing mesh in open3d ...") 12 mesh = read_triangle_mesh("../../TestData/knot.ply") 13 print(mesh) 14 print(np.asarray(mesh.vertices)) 15 print(np.asarray(mesh.triangles)) 16 print("") 17 18 print("Try to render a mesh with normals (exist: " + 19 str(mesh.has_vertex_normals()) + 20 ") and colors (exist: " + str(mesh.has_vertex_colors()) + ")") 21 draw_geometries([mesh]) 22 print("A mesh with no normals and no colors does not seem good.") 23 24 print("Computing normal and rendering it.") 25 mesh.compute_vertex_normals() 26 print(np.asarray(mesh.triangle_normals)) 27 draw_geometries([mesh]) 28 29 print("We make a partial mesh of only the first half triangles.") 30 mesh1 = copy.deepcopy(mesh) 31 mesh1.triangles = Vector3iVector( 32 np.asarray(mesh1.triangles)[:len(mesh1.triangles)//2, :]) 33 mesh1.triangle_normals = Vector3dVector( 34 np.asarray(mesh1.triangle_normals) 35 [:len(mesh1.triangle_normals)//2, :]) 36 print(mesh1.triangles) 37 draw_geometries([mesh1]) 38 39 print("Painting the mesh") 40 mesh1.paint_uniform_color([1, 0.706, 0]) 41 draw_geometries([mesh1]) 42