Skip to content

Commit

Permalink
fix(ply): Removes incorrect custom split normals from bop/replica obj…
Browse files Browse the repository at this point in the history
…ects loaded from ply
  • Loading branch information
cornerfarmer committed Aug 29, 2024
1 parent f99fb32 commit 4cacdbe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions blenderproc/python/loader/BopLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ def load_mesh(obj_id: int, model_p: dict, bop_dataset_name: str, scale: float =
# if the object was not previously loaded - load it, if duplication is allowed - duplicate it
duplicated = model_path in _BopLoader.CACHED_OBJECTS
objs = load_obj(model_path, cached_objects=_BopLoader.CACHED_OBJECTS)
# Bop objects comes with incorrect custom normals, so remove them
for obj in objs:
obj.clear_custom_splitnormals()

assert (
len(objs) == 1
), f"Loading object from '{model_path}' returned more than one mesh"
Expand Down
3 changes: 3 additions & 0 deletions blenderproc/python/loader/ReplicaLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ def load_replica(data_path: str, data_set_name: str, use_smooth_shading: bool =
"""
file_path = os.path.join(data_path, data_set_name, 'mesh.ply')
loaded_objects = load_obj(file_path)
# Replica comes with incorrect custom normals, so remove them
for obj in loaded_objects:
obj.clear_custom_splitnormals()

if use_smooth_shading:
for obj in loaded_objects:
Expand Down
6 changes: 6 additions & 0 deletions blenderproc/python/types/MeshObjectUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,12 @@ def mesh_as_trimesh(self) -> Trimesh:

return Trimesh(vertices=verts, faces=faces)

def clear_custom_splitnormals(self) -> None:
""" Removes custom split normals which might exist after importing the object from file. """

with bpy.context.temp_override(object=self.blender_obj):
bpy.ops.mesh.customdata_custom_splitnormals_clear()

def create_from_blender_mesh(blender_mesh: bpy.types.Mesh, object_name: str = None) -> "MeshObject":
""" Creates a new Mesh object using the given blender mesh.
Expand Down

0 comments on commit 4cacdbe

Please sign in to comment.