Skip to content

Commit a65928d

Browse files
Krzysztof Chalupkafacebook-github-bot
Krzysztof Chalupka
authored andcommitted
Remove spurious compute in _compute_vertex_normals
Summary: #736 Reviewed By: bottler Differential Revision: D38881935 fbshipit-source-id: 62aa3575513ab752a5afda4a257a985032bc7f6d
1 parent 898ba5c commit a65928d

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

pytorch3d/structures/meshes.py

+9-21
Original file line numberDiff line numberDiff line change
@@ -890,34 +890,22 @@ def _compute_vertex_normals(self, refresh: bool = False):
890890
verts_normals = torch.zeros_like(verts_packed)
891891
vertices_faces = verts_packed[faces_packed]
892892

893+
faces_normals = torch.cross(
894+
vertices_faces[:, 2] - vertices_faces[:, 1],
895+
vertices_faces[:, 0] - vertices_faces[:, 1],
896+
dim=1,
897+
)
898+
893899
# NOTE: this is already applying the area weighting as the magnitude
894900
# of the cross product is 2 x area of the triangle.
895901
verts_normals = verts_normals.index_add(
896-
0,
897-
faces_packed[:, 1],
898-
torch.cross(
899-
vertices_faces[:, 2] - vertices_faces[:, 1],
900-
vertices_faces[:, 0] - vertices_faces[:, 1],
901-
dim=1,
902-
),
902+
0, faces_packed[:, 0], faces_normals
903903
)
904904
verts_normals = verts_normals.index_add(
905-
0,
906-
faces_packed[:, 2],
907-
torch.cross(
908-
vertices_faces[:, 0] - vertices_faces[:, 2],
909-
vertices_faces[:, 1] - vertices_faces[:, 2],
910-
dim=1,
911-
),
905+
0, faces_packed[:, 1], faces_normals
912906
)
913907
verts_normals = verts_normals.index_add(
914-
0,
915-
faces_packed[:, 0],
916-
torch.cross(
917-
vertices_faces[:, 1] - vertices_faces[:, 0],
918-
vertices_faces[:, 2] - vertices_faces[:, 0],
919-
dim=1,
920-
),
908+
0, faces_packed[:, 2], faces_normals
921909
)
922910

923911
self._verts_normals_packed = torch.nn.functional.normalize(

0 commit comments

Comments
 (0)