MCPcopy Create free account
hub / github.com/apple/ml-pointersect / clean_meshes

Function clean_meshes

pointersect/data/dataset_helper.py:39–103  ·  view source on GitHub ↗

Clean the meshes in mesh_filenames. Note that the actual cleaning will only be executed by rank=0. The rest of the ranks should wait for rank=0 to finish. Args: mesh_filenames: a list containing the meshes to be cleaned. The mesh_filenames are relat

(
        mesh_filenames: T.List[str],
        dataset_root_dir: str,
        cleaned_root_dir: str,
        skip_exist: bool,
        printout: bool = True,
)

Source from the content-addressed store, hash-verified

37
38
39def clean_meshes(
40 mesh_filenames: T.List[str],
41 dataset_root_dir: str,
42 cleaned_root_dir: str,
43 skip_exist: bool,
44 printout: bool = True,
45) -> T.List[str]:
46 """
47 Clean the meshes in mesh_filenames.
48
49 Note that the actual cleaning will only be executed by rank=0.
50 The rest of the ranks should wait for rank=0 to finish.
51
52 Args:
53 mesh_filenames:
54 a list containing the meshes to be cleaned.
55 The mesh_filenames are relative filepath within `dataset_root_dir` or full path.
56 dataset_root_dir:
57 the root dir where all meshes locate
58 cleaned_root_dir:
59 only for cleaning obj
60
61 Returns:
62 cleaned_mesh_filenames:
63 a list containing the cleaned meshes
64 """
65
66 # print(f'clean_meshes: dataset_root_dir = {dataset_root_dir}', flush=True)
67 # print(f'clean_meshes: cleaned_root_dir = {cleaned_root_dir}', flush=True)
68
69 if isinstance(mesh_filenames, str): # str, list, or tuple
70 mesh_filenames = [mesh_filenames]
71
72 cleaned_mesh_filenames = []
73 for mesh_filename in mesh_filenames:
74 name, ext = os.path.splitext(mesh_filename)
75 if ext.lower() == '.obj':
76 rel_mesh_filename = os.path.relpath(mesh_filename, dataset_root_dir)
77 cleaned_filename = preprocess_obj.generated_cleaned_mesh(
78 input_dir=dataset_root_dir,
79 output_dir=cleaned_root_dir,
80 relative_filepath=rel_mesh_filename,
81 skip_exist=skip_exist,
82 printout=printout,
83 )
84 elif ext.lower() in {'.glb', '.gltf'}:
85 cleaned_filename = utils.clean_up_glb_write_gltf(
86 filename_glb=mesh_filename,
87 overwrite_gltf=not skip_exist,
88 exists_ok=True,
89 image_ext='.png', # assume the texture maps are of png format
90 )
91 elif ext.lower() in {'off'}:
92 # off meshes do not need cleaning
93 cleaned_filename = mesh_filename
94 else:
95 warnings.warn(f'{mesh_filename} not cleaned')
96 cleaned_filename = mesh_filename

Callers 1

gather_and_clean_datasetFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected