mode: normal, phong, texture
(self, verts, faces, R=None, T=None, colors=None, mode='npat')
| 343 | self.renderer = MeshRenderer(rasterizer=self.rasterizer, shader=self.shader) |
| 344 | |
| 345 | def render_mesh_recon(self, verts, faces, R=None, T=None, colors=None, mode='npat'): |
| 346 | ''' |
| 347 | mode: normal, phong, texture |
| 348 | ''' |
| 349 | with torch.no_grad(): |
| 350 | |
| 351 | mesh = Meshes(verts, faces) |
| 352 | |
| 353 | normals = torch.stack(mesh.verts_normals_list()) |
| 354 | front_light = -torch.tensor([0,0,-1]).float().to(verts.device) |
| 355 | shades = (normals * front_light.view(1,1,3)).sum(-1).clamp(min=0).unsqueeze(-1).expand(-1,-1,3) |
| 356 | results = [] |
| 357 | # shading |
| 358 | if 'p' in mode: |
| 359 | mesh_shading = Meshes(verts, faces, textures=Textures(verts_rgb=shades)) |
| 360 | image_phong = self.renderer(mesh_shading) |
| 361 | results.append(image_phong) |
| 362 | # normal |
| 363 | if 'n' in mode: |
| 364 | normals_vis = normals* 0.5 + 0.5 |
| 365 | normals_vis = normals_vis[:,:,[2,1,0]] |
| 366 | mesh_normal = Meshes(verts, faces, textures=Textures(verts_rgb=normals_vis)) |
| 367 | image_normal = self.renderer(mesh_normal) |
| 368 | results.append(image_normal) |
| 369 | return torch.cat(results, axis=1) |
| 370 |