blenderproc.python.object.OnSurfaceSampler module

Sampling objects on a surface.

class blenderproc.python.object.OnSurfaceSampler._OnSurfaceSampler[source]

Bases: object

static check_above_surface(obj, surface, up_direction, check_all_bb_corners_over_surface=True)[source]

Check if all corners of the bounding box are “above” the surface

Parameters:
  • obj (MeshObject) – Object for which the check is carried out. Type: blender object.

  • surface (MeshObject) – The surface object.

  • up_direction (ndarray) – The direction that indicates “above” direction.

  • check_all_bb_corners_over_surface (bool) – If this is True all bounding box corners have to be above the surface, else only the center of the object has to be above the surface

Return type:

bool

Returns:

True if the bounding box is above the surface, False - if not.

static check_spacing(obj, placed_objects, min_distance, max_distance)[source]

Check if object is not too close or too far from previous objects.

Parameters:
  • obj (MeshObject) – Object for which the check is carried out.

  • placed_objects (List[MeshObject]) – A list of already placed objects that should be used for checking spacing.

  • min_distance (float) – Minimum distance to the closest other object from placed_objects. Center to center.

  • max_distance (float) – Maximum distance to the closest other object from placed_objects. Center to center.

Return type:

bool

Returns:

True, if the spacing is correct

static drop(obj, up_direction, surface_height)[source]
Moves object “down” until its bounding box touches the bounding box of the surface. This uses bounding boxes

which are not aligned optimally, this will cause objects to be placed slightly to high.

Parameters:
  • obj (MeshObject) – Object to move. Type: blender object.

  • up_direction (ndarray) – Vector which points into the opposite drop direction.

  • surface_height (float) – Height of the surface above its origin.

blenderproc.python.object.OnSurfaceSampler.sample_poses_on_surface(objects_to_sample, surface, sample_pose_func, max_tries=100, min_distance=0.25, max_distance=0.6, up_direction=None, check_all_bb_corners_over_surface=True)[source]

Samples objects poses on a surface.

The objects are positioned slightly above the surface due to the non-axis aligned nature of used bounding boxes and possible non-alignment of the sampling surface (i.e. on the X-Y hyperplane, can be somewhat mitigated with precise “up_direction” value), which leads to the objects hovering slightly above the surface. So it is recommended to use the PhysicsPositioning module afterwards for realistically looking placements of objects on the sampling surface. If placing fails due to collisions, the object will be moved back to the intial pose and hidden from rendering.

Parameters:
  • objects_to_sample (List[MeshObject]) – A list of objects that should be sampled above the surface.

  • surface (MeshObject) – Object to place objects_to_sample on.

  • sample_pose_func (Callable[[MeshObject], None]) – The function to use for sampling the pose of a given object.

  • max_tries (int) – Amount of tries before giving up on an object (deleting it) and moving to the next one.

  • min_distance (float) – Minimum distance to the closest other object from objects_to_sample. Center to center.

  • max_distance (float) – Maximum distance to the closest other object from objects_to_sample. Center to center.

  • up_direction (Optional[ndarray]) – Normal vector of the side of surface the objects should be placed on.

  • check_all_bb_corners_over_surface (bool) – If this is True all bounding box corners have to be above the surface, else only the center of the object has to be above the surface

Return type:

List[MeshObject]

Returns:

The list of placed objects.