blenderproc.python.object.ObjectReplacer module

Replaces mesh objects with other meshes objects, while checking for collisions

class blenderproc.python.object.ObjectReplacer._ObjectReplacer[source]

Bases: object

Replaces mesh objects with another mesh objects and scales them accordingly, the replaced objects and the objects to replace with, can be selected over Selectors (getter.Entity).

static bb_ratio(bb1, bb2)[source]

Rough estimation of the ratios between two bounding boxes sides, not axis aligned

Parameters:
  • bb1 (ndarray) – bounding box 1. Type: float multi-dimensional array of 8 * 3.

  • bb2 (ndarray) – bounding box 2. Type: float multi-dimensional array of 8 * 3.

Return type:

list

Returns:

the ratio between each side of the bounding box. Type: a list of floats.

static replace(obj_to_remove, obj_to_add, check_collision_with=None, scale=True, relative_pose_sampler=None)[source]

Scale, translate, rotate obj_to_add to match obj_to_remove and check if there is a bounding box collision returns a boolean.

Parameters:
  • obj_to_remove (MeshObject) – An object to remove from the scene.

  • obj_to_add (MeshObject) – An object to put in the scene instead of obj_to_remove.

  • check_collision_with (Optional[List[MeshObject]]) – A list of objects, which are not checked for collisions with.

  • scale (bool) – Scales obj_to_add to match obj_to_remove dimensions.

  • relative_pose_sampler (Optional[Callable[[MeshObject], None]]) – A function that randomly perturbs the pose of the object to replace with (after it has been aligned to the object to replace).

blenderproc.python.object.ObjectReplacer.replace_objects(objects_to_be_replaced, objects_to_replace_with, ignore_collision_with=None, replace_ratio=1, copy_properties=True, max_tries=100, relative_pose_sampler=None)[source]

Replaces mesh objects with another mesh objects and scales them accordingly, the replaced objects and the objects to replace with in following steps:

  1. Randomly select a subset of objects_to_be_replaced.

  2. For each of these objects, sample other objects from objects_to_replace_with and try to replace them.

  3. In each try, the poses of the objects are aligned and a check for collisions with other objects is done.

  4. An object is skipped if max_tries is reached.

Parameters:
  • objects_to_be_replaced (List[MeshObject]) – Objects, which should be removed from the scene.

  • objects_to_replace_with (List[MeshObject]) – Objects, which will be tried to be added to the scene.

  • ignore_collision_with (Optional[List[MeshObject]]) – Objects, which are not checked for collisions with.

  • replace_ratio (float) – Ratio of objects in the original scene, which will be replaced.

  • copy_properties (bool) – Copies the custom properties of the objects_to_be_replaced to the objects_to_replace_with.

  • max_tries (int) – Maximum number of tries to replace one object.

  • relative_pose_sampler (Optional[Callable[[MeshObject], None]]) – A function that randomly perturbs the pose of the object to replace with (after it has been aligned to the object to replace).