Skip to content

Commit

Permalink
Remove spurious compute in _compute_vertex_normals
Browse files Browse the repository at this point in the history
Summary: #736

Reviewed By: bottler

Differential Revision: D38881935

fbshipit-source-id: 62aa3575513ab752a5afda4a257a985032bc7f6d
  • Loading branch information
Krzysztof Chalupka authored and facebook-github-bot committed Aug 23, 2022
1 parent 898ba5c commit a65928d
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions pytorch3d/structures/meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,34 +890,22 @@ def _compute_vertex_normals(self, refresh: bool = False):
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(
Expand Down

0 comments on commit a65928d

Please sign in to comment.