mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-08-02 03:42:50 +08:00
avoid recalculating normals for simple move
Summary: If offset_verts_ is used to move meshes with a single vector, the normals won't change so don't need to recalculate. I am planning to allow user-specified vertex normals. This change means that user-specified vertex normals won't get overwritten when they don't need to be. Reviewed By: nikhilaravi Differential Revision: D27765256 fbshipit-source-id: f6e4d308ac9ac023030325cb75a18d39b966cf88
This commit is contained in:
parent
17633808d8
commit
502f15aca7
@ -1263,7 +1263,10 @@ class Meshes(object):
|
||||
"""
|
||||
verts_packed = self.verts_packed()
|
||||
if vert_offsets_packed.shape == (3,):
|
||||
update_normals = False
|
||||
vert_offsets_packed = vert_offsets_packed.expand_as(verts_packed)
|
||||
else:
|
||||
update_normals = True
|
||||
if vert_offsets_packed.shape != verts_packed.shape:
|
||||
raise ValueError("Verts offsets must have dimension (all_v, 3).")
|
||||
# update verts packed
|
||||
@ -1284,12 +1287,12 @@ class Meshes(object):
|
||||
|
||||
# update face areas and normals and vertex normals
|
||||
# only if the original attributes are computed
|
||||
if any(
|
||||
if update_normals and any(
|
||||
v is not None
|
||||
for v in [self._faces_areas_packed, self._faces_normals_packed]
|
||||
):
|
||||
self._compute_face_areas_normals(refresh=True)
|
||||
if self._verts_normals_packed is not None:
|
||||
if update_normals and self._verts_normals_packed is not None:
|
||||
self._compute_vertex_normals(refresh=True)
|
||||
|
||||
return self
|
||||
|
@ -486,6 +486,7 @@ class TestMeshes(TestCaseMixin, unittest.TestCase):
|
||||
self.assertClose(
|
||||
new_mesh.verts_normals_list()[i],
|
||||
new_mesh_naive.verts_normals_list()[i],
|
||||
atol=1e-6,
|
||||
)
|
||||
self.assertClose(
|
||||
new_mesh.faces_normals_list()[i],
|
||||
@ -533,10 +534,14 @@ class TestMeshes(TestCaseMixin, unittest.TestCase):
|
||||
|
||||
# check face areas, normals and vertex normals
|
||||
self.assertClose(
|
||||
new_mesh.verts_normals_packed(), new_mesh_naive.verts_normals_packed()
|
||||
new_mesh.verts_normals_packed(),
|
||||
new_mesh_naive.verts_normals_packed(),
|
||||
atol=1e-6,
|
||||
)
|
||||
self.assertClose(
|
||||
new_mesh.verts_normals_padded(), new_mesh_naive.verts_normals_padded()
|
||||
new_mesh.verts_normals_padded(),
|
||||
new_mesh_naive.verts_normals_padded(),
|
||||
atol=1e-6,
|
||||
)
|
||||
self.assertClose(
|
||||
new_mesh.faces_normals_packed(), new_mesh_naive.faces_normals_packed()
|
||||
|
Loading…
x
Reference in New Issue
Block a user