Skip to content

Commit

Permalink
save normals from Meshes, Pointclouds to PLY
Browse files Browse the repository at this point in the history
Summary: Save existing vertex normals when a mesh is saved to PLY, and existing normals when a point cloud is saved to PLY.

Reviewed By: theschnitz

Differential Revision: D27765257

fbshipit-source-id: fa0aae4c0f100f7e5eb742f48fc3dfc87435deba
  • Loading branch information
bottler authored and facebook-github-bot committed May 4, 2021
1 parent 66b97a0 commit b314bee
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pytorch3d/io/ply_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,10 +1238,14 @@ def save(
if not endswith(path, self.known_suffixes):
return False

# TODO: normals are not saved. We only want to save them if they already exist.
verts = data.verts_list()[0]
faces = data.faces_list()[0]

if data.has_verts_normals():
verts_normals = data.verts_normals_list()[0]
else:
verts_normals = None

if isinstance(data.textures, TexturesVertex):
mesh_verts_colors = data.textures.verts_features_list()[0]
n_colors = mesh_verts_colors.shape[1]
Expand All @@ -1261,7 +1265,7 @@ def save(
verts=verts,
faces=faces,
verts_colors=verts_colors,
verts_normals=None,
verts_normals=verts_normals,
ascii=binary is False,
decimal_places=decimal_places,
)
Expand Down Expand Up @@ -1304,13 +1308,14 @@ def save(

points = data.points_list()[0]
features = data.features_packed()
normals = data.normals_packed()

with _open_file(path, path_manager, "wb") as f:
_save_ply(
f=f,
verts=points,
verts_colors=features,
verts_normals=None,
verts_normals=normals,
faces=None,
ascii=binary is False,
decimal_places=decimal_places,
Expand Down

0 comments on commit b314bee

Please sign in to comment.