From a65928dcb965b114f3239603106e2b8e7c52b1c0 Mon Sep 17 00:00:00 2001 From: Krzysztof Chalupka Date: Tue, 23 Aug 2022 10:08:14 -0700 Subject: [PATCH] Remove spurious compute in _compute_vertex_normals Summary: https://github.com/facebookresearch/pytorch3d/issues/736 Reviewed By: bottler Differential Revision: D38881935 fbshipit-source-id: 62aa3575513ab752a5afda4a257a985032bc7f6d --- pytorch3d/structures/meshes.py | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/pytorch3d/structures/meshes.py b/pytorch3d/structures/meshes.py index 7f68052a..19f11264 100644 --- a/pytorch3d/structures/meshes.py +++ b/pytorch3d/structures/meshes.py @@ -890,34 +890,22 @@ class Meshes: verts_normals = torch.zeros_like(verts_packed) vertices_faces = verts_packed[faces_packed] + faces_normals = torch.cross( + vertices_faces[:, 2] - vertices_faces[:, 1], + vertices_faces[:, 0] - vertices_faces[:, 1], + dim=1, + ) + # NOTE: this is already applying the area weighting as the magnitude # of the cross product is 2 x area of the triangle. verts_normals = verts_normals.index_add( - 0, - faces_packed[:, 1], - torch.cross( - vertices_faces[:, 2] - vertices_faces[:, 1], - vertices_faces[:, 0] - vertices_faces[:, 1], - dim=1, - ), + 0, faces_packed[:, 0], faces_normals ) verts_normals = verts_normals.index_add( - 0, - faces_packed[:, 2], - torch.cross( - vertices_faces[:, 0] - vertices_faces[:, 2], - vertices_faces[:, 1] - vertices_faces[:, 2], - dim=1, - ), + 0, faces_packed[:, 1], faces_normals ) verts_normals = verts_normals.index_add( - 0, - faces_packed[:, 0], - torch.cross( - vertices_faces[:, 1] - vertices_faces[:, 0], - vertices_faces[:, 2] - vertices_faces[:, 0], - dim=1, - ), + 0, faces_packed[:, 2], faces_normals ) self._verts_normals_packed = torch.nn.functional.normalize(