MCPcopy Create free account
hub / github.com/TEA-Lab/TwoByTwo / combine_meshes

Function combine_meshes

data_util/preprocess_obj_blender.py:41–78  ·  view source on GitHub ↗
(instance_dir)

Source from the content-addressed store, hash-verified

39
40# use pyblender change the non-triangle mesh to triangle mesh
41def combine_meshes(instance_dir):
42 triangulate_mesh_with_pyblender(instance_dir)
43
44 # Load the two meshes
45 mesh1_path = os.path.join(current_dir, instance_dir, "partA_tri.obj")
46 mesh2_path = os.path.join(current_dir, instance_dir, "partB_tri.obj")
47 combined_mesh_path = os.path.join(current_dir, instance_dir, "combined_mesh.obj")
48
49 if not file_exists(mesh1_path) or not file_exists(mesh2_path):
50 sys.exit(1)
51
52
53 mesh1 = o3d.io.read_triangle_mesh(mesh1_path)
54 # mesh1.triangulate()
55 mesh2 = o3d.io.read_triangle_mesh(mesh2_path)
56 # mesh2.triangulate()
57
58 if not mesh1.has_vertices():
59 raise ValueError("mesh1 does not contain any vertices.", mesh1_path)
60 if not mesh2.has_vertices():
61 raise ValueError("mesh2 does not contain any vertices.", mesh2_path)
62
63 # Combine vertices and triangles
64 combined_vertices = np.vstack((np.asarray(mesh1.vertices), np.asarray(mesh2.vertices)))
65 combined_triangles = np.vstack((np.asarray(mesh1.triangles), np.asarray(mesh2.triangles) + len(mesh1.vertices)))
66
67 # Create a new mesh with the combined vertices and triangles
68 combined_mesh = o3d.geometry.TriangleMesh()
69 combined_mesh.vertices = o3d.utility.Vector3dVector(combined_vertices)
70 combined_mesh.triangles = o3d.utility.Vector3iVector(combined_triangles)
71
72 # Optionally combine vertex colors if they exist
73 if mesh1.has_vertex_colors() and mesh2.has_vertex_colors():
74 combined_colors = np.vstack((np.asarray(mesh1.vertex_colors), np.asarray(mesh2.vertex_colors)))
75 combined_mesh.vertex_colors = o3d.utility.Vector3dVector(combined_colors)
76
77 # print("Combined mesh saved to {}".format(combined_mesh_path))
78 return (mesh1, mesh2, combined_mesh)
79
80def calculate_center_and_scale_two_seperate_part(instance_dir):
81

Calls 2

file_existsFunction · 0.85

Tested by

no test coverage detected