MCPcopy Create free account
hub / github.com/Meshcapade/difflocks / tbn_space_to_world

Function tbn_space_to_world

data_loader/mesh_utils.py:295–389  ·  view source on GitHub ↗
(root_uv, strands_positions, scalp_mesh_data)

Source from the content-addressed store, hash-verified

293
294
295def tbn_space_to_world(root_uv, strands_positions, scalp_mesh_data):
296
297 scalp_index_map=scalp_mesh_data["index_map"]
298 scalp_vertex_idxs_map=scalp_mesh_data["vertex_idxs_map"]
299 scalp_bary_map=scalp_mesh_data["bary_map"]
300 mesh_v_tangents=scalp_mesh_data["v_tangents"]
301 mesh_v_bitangents=scalp_mesh_data["v_bitangents"]
302 mesh_v_normals=scalp_mesh_data["v_normals"]
303 scalp_v=scalp_mesh_data["verts"]
304 scalp_f=scalp_mesh_data["faces"]
305 # binary_uv_map = binary_uv_map.detach().cpu().numpy()[..., 0]
306 # # binary_uv_map[binary_uv_map < 0.01] = 0
307 # binary_uv_map[binary_uv_map < 0.5] = 0
308 # binary_uv_map[binary_uv_map >= 0.5] = 1
309 # if np.sum(binary_uv_map) < 1:
310 # return
311 # index = np.nonzero(binary_uv_map)
312 # index = np.concatenate([index[0][..., None], index[1][..., None]], 1)
313
314 # face_idxs = self.scalp_index_map[index[:, 0], index[:, 1]]
315 # barys = self.scalp_bary_map[index[:, 0], index[:, 1], :]
316
317 # strands, tbn_strands = self.world_strands_from_scalptexture(uv_map, binary_uv_map, face_idxs, barys)
318 # strands = strands.detach().cpu().numpy()
319 # return strands,tbn_strands
320
321 # assert strands_tbn.dim() == 3
322 # assert strands_positions.dim() == 3
323
324 #given the uv, we get pixel indices
325 # print("scalp_vertex_idxs_map",scalp_vertex_idxs_map.shape)
326 tex_size = scalp_vertex_idxs_map.shape[0]
327 # print("tex size", tex_size)
328 pixel_indices = (root_uv*tex_size).floor().int()
329 # print("pixel_indices",pixel_indices.shape)
330 # print("pixel_indices",pixel_indices)
331
332 #sample from the vertex idxs map and bary map
333 face_idxs = scalp_index_map[pixel_indices[:, 0], pixel_indices[:, 1]]
334 vertex_idxs = scalp_vertex_idxs_map[pixel_indices[:, 0], pixel_indices[:, 1], :]
335 barys = scalp_bary_map[pixel_indices[:, 0], pixel_indices[:, 1], :]
336
337 # print("vertex_idxs",vertex_idxs.shape)
338 # print("barys",barys.shape)
339 # print("barys",barys)
340 # print("vertex_idxs",vertex_idxs.shape)
341 # print("vertex_idxs",vertex_idxs)
342 # vertex_idxs= scalp_f[face_idxs]
343 # print("vertex_idxs",vertex_idxs)
344
345 #interpolate
346 root_tangent, root_bitangent, root_normal = interpolate_tbn(barys, vertex_idxs, mesh_v_tangents, mesh_v_bitangents, mesh_v_normals)
347 strands_tbn = np.stack((root_tangent,root_bitangent,root_normal),axis=2)
348 strands_tbn = torch.from_numpy(strands_tbn).cuda()
349 # print("strands_tbn",strands_tbn.shape)
350
351 # #we want to map tangent to X, bitangent to Z and normal to Y, so we swap B and N
352 indices_tbn=torch.tensor([0,2,1], device="cuda")

Callers

nothing calls this directly

Calls 1

interpolate_tbnFunction · 0.85

Tested by

no test coverage detected