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

Function clean_mesh_uv

plib/mesh_utils.py:13–36  ·  view source on GitHub ↗

Ensure mesh uv is wrapped between 0 and 1, and triangles with identical uv in vertices are properly handled. Args: triangle_uvs: input uv vectors Returns: cleaned uv vectors

(triangle_uvs: o3d.utility.Vector2dVector)

Source from the content-addressed store, hash-verified

11
12
13def clean_mesh_uv(triangle_uvs: o3d.utility.Vector2dVector) -> o3d.utility.Vector2dVector:
14 """
15 Ensure mesh uv is wrapped between 0 and 1, and triangles with identical uv in vertices are properly handled.
16
17 Args:
18 triangle_uvs: input uv vectors
19
20 Returns:
21 cleaned uv vectors
22 """
23
24 uvs = np.asarray(triangle_uvs)
25 uvs_mod = np.reshape(uvs, [int(uvs.shape[0] / 3), 3, uvs.shape[1]])
26 single_uvs = np.logical_and(uvs_mod[:, 0, :] == uvs_mod[:, 1, :], uvs_mod[:, 0, :] == uvs_mod[:, 2, :])
27 single_uvs = np.logical_and(single_uvs[:, 0], single_uvs[:, 1])
28 # for identical uvs, change uvs to center of texture maps
29 uvs_mod[single_uvs, 0, :] = np.array([0.5, 0.5])
30 uvs_mod[single_uvs, 1, :] = np.array([0.5, 0.51])
31 uvs_mod[single_uvs, 2, :] = np.array([0.51, 0.5])
32 uvs_mod = np.reshape(uvs_mod, uvs.shape)
33
34 # wrap uv, note that this would remove repetitive textures
35 uvs_mod = uvs_mod - np.floor(uvs_mod)
36 return o3d.utility.Vector2dVector(uvs_mod)
37
38
39def clean_texture(img: T.Union[o3d.geometry.Image, np.ndarray]) -> T.Union[o3d.geometry.Image, np.ndarray]:

Callers 1

preprocess_meshFunction · 0.85

Calls 1

reshapeMethod · 0.45

Tested by

no test coverage detected