Skip to content

Commit b314bee

Browse files
bottlerfacebook-github-bot
authored andcommitted
save normals from Meshes, Pointclouds to PLY
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
1 parent 66b97a0 commit b314bee

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pytorch3d/io/ply_io.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,10 +1238,14 @@ def save(
12381238
if not endswith(path, self.known_suffixes):
12391239
return False
12401240

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

1244+
if data.has_verts_normals():
1245+
verts_normals = data.verts_normals_list()[0]
1246+
else:
1247+
verts_normals = None
1248+
12451249
if isinstance(data.textures, TexturesVertex):
12461250
mesh_verts_colors = data.textures.verts_features_list()[0]
12471251
n_colors = mesh_verts_colors.shape[1]
@@ -1261,7 +1265,7 @@ def save(
12611265
verts=verts,
12621266
faces=faces,
12631267
verts_colors=verts_colors,
1264-
verts_normals=None,
1268+
verts_normals=verts_normals,
12651269
ascii=binary is False,
12661270
decimal_places=decimal_places,
12671271
)
@@ -1304,13 +1308,14 @@ def save(
13041308

13051309
points = data.points_list()[0]
13061310
features = data.features_packed()
1311+
normals = data.normals_packed()
13071312

13081313
with _open_file(path, path_manager, "wb") as f:
13091314
_save_ply(
13101315
f=f,
13111316
verts=points,
13121317
verts_colors=features,
1313-
verts_normals=None,
1318+
verts_normals=normals,
13141319
faces=None,
13151320
ascii=binary is False,
13161321
decimal_places=decimal_places,

0 commit comments

Comments
 (0)