Skip to content

Commit

Permalink
fix(bop): Adds warning if hidden objects are given to bop writer
Browse files Browse the repository at this point in the history
  • Loading branch information
cornerfarmer committed Nov 6, 2023
1 parent de6f16c commit d20eb05
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions blenderproc/python/object/OnSurfaceSampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def sample_poses_on_surface(objects_to_sample: List[MeshObject], surface: MeshOb
else only the center of the object has to be above the surface
:return: The list of placed objects.
"""
if len(set(objects_to_sample)) != len(objects_to_sample):
raise ValueError("The given list of objects to sample contains duplicates. "
"This leads to complications in the sampling process.")

if up_direction is None:
up_direction = np.array([0., 0., 1.])
else:
Expand Down
7 changes: 7 additions & 0 deletions blenderproc/python/types/MeshObjectUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ def hide(self, hide_object: bool = True):
"""
self.blender_obj.hide_render = hide_object

def is_hidden(self) -> bool:
""" Returns whether the object is hidden in rendering.
:return: True, if it is hidden.
"""
return self.blender_obj.hide_render

def disable_rigidbody(self):
""" Disables the rigidbody element of the object """
if self.has_rigidbody_enabled():
Expand Down
11 changes: 9 additions & 2 deletions blenderproc/python/writer/BopWriterUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,21 @@ def write_bop(output_dir: str, target_objects: Optional[List[MeshObject]] = None
# Select target objects or objects from the specified dataset or all objects
if target_objects is not None:
dataset_objects = target_objects
for obj in get_all_mesh_objects():
if obj.is_hidden():
print(f"WARNING: The given object {obj.get_name()} is hidden. However, the bop writer will still add "
"coco annotations for it. If this is not desired, don't pass the object to the bop writer.")
elif dataset:
dataset_objects = []
for obj in get_all_mesh_objects():
if "bop_dataset_name" in obj.blender_obj and not obj.blender_obj.hide_render:
if "bop_dataset_name" in obj.blender_obj and not obj.is_hidden():
if obj.blender_obj["bop_dataset_name"] == dataset:
dataset_objects.append(obj)
else:
dataset_objects = get_all_mesh_objects()
dataset_objects = []
for obj in get_all_mesh_objects():
if not obj.is_hidden():
dataset_objects.append(obj)

# Check if there is any object from the specified dataset.
if not dataset_objects:
Expand Down

0 comments on commit d20eb05

Please sign in to comment.