| 14 | from pytorch3d.renderer import MeshRasterizer |
| 15 | |
| 16 | def get_camera(world_to_cam, fov_in_degrees=60, focal_length=1 / (2**0.5), cam_type='fov'): |
| 17 | # pytorch3d expects transforms as row-vectors, so flip rotation: https://github.com/facebookresearch/pytorch3d/issues/1183 |
| 18 | R = world_to_cam[:3, :3].t()[None, ...] |
| 19 | T = world_to_cam[:3, 3][None, ...] |
| 20 | if cam_type == 'fov': |
| 21 | camera = FoVPerspectiveCameras(device=world_to_cam.device, R=R, T=T, fov=fov_in_degrees, degrees=True) |
| 22 | else: |
| 23 | focal_length = 1 / focal_length |
| 24 | camera = FoVOrthographicCameras(device=world_to_cam.device, R=R, T=T, min_x=-focal_length, max_x=focal_length, min_y=-focal_length, max_y=focal_length) |
| 25 | return camera |
| 26 | |
| 27 | def render_pix2faces_py3d(meshes, cameras, H=512, W=512, blur_radius=0.0, faces_per_pixel=1): |
| 28 | """ |