MCPcopy Create free account
hub / github.com/Sin3DM/Sin3DM / xatlas_uvmap

Function xatlas_uvmap

src/encoding/utils3d.py:228–251  ·  view source on GitHub ↗
(mesh_v, mesh_f, resolution)

Source from the content-addressed store, hash-verified

226
227
228def xatlas_uvmap(mesh_v, mesh_f, resolution):
229 ctx = dr.RasterizeGLContext(device=mesh_v.device)
230 vmapping, indices, uvs = xatlas.parametrize(mesh_v.detach().cpu().numpy(), mesh_f.detach().cpu().numpy())
231 vmapping = torch.tensor(vmapping.astype(np.int64), dtype=torch.int64, device=mesh_v.device)
232 # mesh_v = mesh_v[vmapping]
233
234 # Convert to tensors
235 indices_int64 = indices.astype(np.uint64, casting='same_kind').view(np.int64)
236
237 uvs = torch.tensor(uvs, dtype=torch.float32, device=mesh_v.device)
238 mesh_tex_idx = torch.tensor(indices_int64, dtype=torch.int64, device=mesh_v.device)
239 # mesh_v_tex. ture
240 uv_clip = uvs[None, ...] * 2.0 - 1.0
241
242 # pad to four component coordinate
243 uv_clip4 = torch.cat((uv_clip, torch.zeros_like(uv_clip[..., 0:1]), torch.ones_like(uv_clip[..., 0:1])), dim=-1)
244
245 # rasterize
246 rast, _ = dr.rasterize(ctx, uv_clip4, mesh_tex_idx.int(), (resolution, resolution))
247
248 # Interpolate world space position
249 gb_pos, _ = interpolate(mesh_v[None, ...], rast, mesh_f.int())
250 mask = rast[..., 3:4] > 0
251 return uvs, mesh_tex_idx, gb_pos, mask

Callers 1

decode_texmeshMethod · 0.85

Calls 1

interpolateFunction · 0.85

Tested by

no test coverage detected