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

Function preprocess_mesh

plib/mesh_utils.py:71–111  ·  view source on GitHub ↗

Clean the mesh uv and textures, normalize the mesh within [-scale, scale]. Args: mesh: input mesh scale: parameter to scaling the mesh center_w: new center in the world coordinate clean: whether to clean the mesh Returns: preprocessed mesh

(
        mesh: o3d.geometry.TriangleMesh,
        scale: T.Optional[float] = 1.,
        center_w: T.Optional[T.List[float]] = (0., 0., 0.),
        clean: bool = True,
)

Source from the content-addressed store, hash-verified

69
70
71def preprocess_mesh(
72 mesh: o3d.geometry.TriangleMesh,
73 scale: T.Optional[float] = 1.,
74 center_w: T.Optional[T.List[float]] = (0., 0., 0.),
75 clean: bool = True,
76) -> o3d.geometry.TriangleMesh:
77 """
78 Clean the mesh uv and textures, normalize the mesh within [-scale, scale].
79
80 Args:
81 mesh: input mesh
82 scale: parameter to scaling the mesh
83 center_w: new center in the world coordinate
84 clean: whether to clean the mesh
85
86 Returns:
87 preprocessed mesh
88 """
89
90 # avoid affecting input
91 mesh = copy.deepcopy(mesh)
92
93 # center the mesh to (0,0,0)
94 if center_w is not None:
95 center_w = np.array(center_w)
96 cs = mesh.get_axis_aligned_bounding_box().get_center()
97 mesh.translate(center_w - cs, relative=True)
98
99 # scale the mesh equally along xyz so that it lies within [-scale, scale]
100 if scale is not None:
101 s = np.max(mesh.get_axis_aligned_bounding_box().get_half_extent())
102 mesh.scale(scale=scale / s, center=np.zeros((3, 1)))
103
104 if clean:
105 # wrap mesh uv to [0,1], handle triangles with all vertex have same uv
106 mesh.triangle_uvs = clean_mesh_uv(mesh.triangle_uvs)
107
108 # clean non rgb textures, such as ones with alpha or gray images
109 mesh.textures = [clean_texture(img) for img in mesh.textures]
110
111 return mesh

Callers

nothing calls this directly

Calls 2

clean_mesh_uvFunction · 0.85
clean_textureFunction · 0.85

Tested by

no test coverage detected