def compute_uvs(vertices, indices, print_progress = True): """ Args: vertices -- N x 3 float tensor indices -- M x 3 int tensor Return: uvs & uvs_indices """ vertices = vertices.cpu() indices = indices.cpu() uv_trimesh = redner.UVTriMesh(redner.float_ptr(vertices.data_ptr()), redner.int_ptr(indices.data_ptr()), redner.float_ptr(0), redner.int_ptr(0), int(vertices.shape[0]), 0, int(indices.shape[0])) atlas = redner.TextureAtlas() num_uv_vertices = redner.automatic_uv_map([uv_trimesh], atlas, print_progress)[0] uvs = torch.zeros(num_uv_vertices, 2, dtype=torch.float32) uv_indices = torch.zeros_like(indices) uv_trimesh.uvs = redner.float_ptr(uvs.data_ptr()) uv_trimesh.uv_indices = redner.int_ptr(uv_indices.data_ptr()) uv_trimesh.num_uv_vertices = num_uv_vertices redner.copy_texture_atlas(atlas, [uv_trimesh]) if pyredner.get_use_gpu(): vertices = vertices.cuda(device = pyredner.get_device()) indices = indices.cuda(device = pyredner.get_device()) uvs = uvs.cuda(device = pyredner.get_device()) uv_indices = uv_indices.cuda(device = pyredner.get_device()) return uvs, uv_indices
def compute_uvs(vertices, indices, print_progress = True): """ Compute UV coordinates of a given mesh using a charting algorithm with least square conformal mapping. This calls the `xatlas <https://github.com/jpcy/xatlas>`_ library. Args ==== vertices: tf.Tensor 3D position of vertices float32 tensor with size num_vertices x 3 indices: tf.Tensor vertex indices of triangle faces. int32 tensor with size num_triangles x 3 Returns ======= tf.Tensor uv vertices pool, float32 Tensor with size num_uv_vertices x 3 tf.Tensor uv indices, int32 Tensor with size num_triangles x 3 """ with tf.device('/device:cpu:' + str(pyredner.get_cpu_device_id())): vertices = tf.identity(vertices) indices = tf.identity(indices) uv_trimesh = redner.UVTriMesh(redner.float_ptr(pyredner.data_ptr(vertices)), redner.int_ptr(pyredner.data_ptr(indices)), redner.float_ptr(0), redner.int_ptr(0), int(vertices.shape[0]), 0, int(indices.shape[0])) atlas = redner.TextureAtlas() num_uv_vertices = redner.automatic_uv_map([uv_trimesh], atlas, print_progress)[0] uvs = tf.zeros([num_uv_vertices, 2], dtype=tf.float32) uv_indices = tf.zeros_like(indices) uv_trimesh.uvs = redner.float_ptr(pyredner.data_ptr(uvs)) uv_trimesh.uv_indices = redner.int_ptr(pyredner.data_ptr(uv_indices)) uv_trimesh.num_uv_vertices = num_uv_vertices redner.copy_texture_atlas(atlas, [uv_trimesh]) with tf.device(pyredner.get_device_name()): vertices = tf.identity(vertices) indices = tf.identity(indices) uvs = tf.identity(uvs) uv_indices = tf.identity(uv_indices) return uvs, uv_indices
def compute_uvs(vertices, indices, print_progress=True): """ Compute UV coordinates of a given mesh using a charting algorithm with least square conformal mapping. This calls the `xatlas <https://github.com/jpcy/xatlas>`_ library. Args ==== vertices: torch.Tensor 3D position of vertices float32 tensor with size num_vertices x 3 indices: torch.Tensor vertex indices of triangle faces. int32 tensor with size num_triangles x 3 Returns ======= torch.Tensor uv vertices pool, float32 Tensor with size num_uv_vertices x 3 torch.Tensor uv indices, int32 Tensor with size num_triangles x 3 """ device = vertices.device vertices = vertices.cpu() indices = indices.cpu() uv_trimesh = redner.UVTriMesh(redner.float_ptr(vertices.data_ptr()), redner.int_ptr(indices.data_ptr()), redner.float_ptr(0), redner.int_ptr(0), int(vertices.shape[0]), 0, int(indices.shape[0])) atlas = redner.TextureAtlas() num_uv_vertices = redner.automatic_uv_map([uv_trimesh], atlas, print_progress)[0] uvs = torch.zeros(num_uv_vertices, 2, dtype=torch.float32) uv_indices = torch.zeros_like(indices) uv_trimesh.uvs = redner.float_ptr(uvs.data_ptr()) uv_trimesh.uv_indices = redner.int_ptr(uv_indices.data_ptr()) uv_trimesh.num_uv_vertices = num_uv_vertices redner.copy_texture_atlas(atlas, [uv_trimesh]) vertices = vertices.to(device) indices = indices.to(device) uvs = uvs.to(device) uv_indices = uv_indices.to(device) return uvs, uv_indices