blenderproc.python.utility.CollisionUtility module
This module provides a collection of functions to check if objects collide.
- class blenderproc.python.utility.CollisionUtility.CollisionUtility[source]
Bases:
object
This class provides utility functions to check if two objects intersect with each other.
- static check_bb_intersection(obj1, obj2)[source]
Checks if there is a bounding box collision, these don’t have to be axis-aligned, but if they are not: The surrounding/including axis-aligned bounding box is calculated and used to check the intersection.
- Parameters:
obj1 (
MeshObject
) – object 1 to check for intersection, must be a meshobj2 (
MeshObject
) – object 2 to check for intersection, must be a mesh
- Returns:
True if the two bounding boxes intersect with each other
- static check_bb_intersection_on_values(min_b1, max_b1, min_b2, max_b2, used_check=<function CollisionUtility.<lambda>>)[source]
Checks if there is an intersection of the given bounding box values. Here we use two different bounding boxes, namely b1 and b2. Each of them has a corresponding set of min and max values, this works for 2 and 3 dimensional problems.
- Parameters:
min_b1 (
List
[float
]) – List of minimum bounding box points for b1.max_b1 (
List
[float
]) – List of maximum bounding box points for b1.min_b2 (
List
[float
]) – List of minimum bounding box points for b2.max_b2 (
List
[float
]) – List of maximum bounding box points for b2.used_check (
Callable
[[float
,float
],bool
]) – The operation used inside the is_overlapping1D. With that it possible to change the collision check from volume and surface check to pure surface or volume checks.
- Returns:
True if the two bounding boxes intersect with each other
- static check_intersections(obj, bvh_cache, objects_to_check_against, list_of_objects_with_no_inside_check)[source]
Checks if an object intersects with any object given in the list.
The bvh_cache adds all current objects to the bvh tree, which increases the speed.
If an object is already in the cache it is removed, before performing the check.
- Parameters:
obj (
MeshObject
) – Object which should be checked. Type:bpy.types.Object
bvh_cache (
Optional
[Dict
[str
,BVHTree
]]) – Dict of all the bvh trees, removes the obj from the cache before adding it again. Type:dict
objects_to_check_against (
List
[MeshObject
]) – List of objects which the object is checked again Type:list
list_of_objects_with_no_inside_check (
List
[MeshObject
]) – List of objects on which no inside check is performed. This check is only done for the objects in objects_to_check_against. Type:list
- Returns:
Type:
bool
, True if no collision was found, false if at least one collision was found
- static check_mesh_intersection(obj1, obj2, skip_inside_check=False, bvh_cache=None)[source]
Checks if the two objects are intersecting.
This will use BVH trees to check whether the objects are overlapping.
It is further also checked if one object is completely inside the other. This check requires that both objects are watertight, have correct normals and are coherent. If this is not the case it can be disabled via the parameter skip_inside_check.
- Parameters:
obj1 (
MeshObject
) – object 1 to check for intersection, must be a meshobj2 (
MeshObject
) – object 2 to check for intersection, must be a meshskip_inside_check (
bool
) – Disables checking whether one object is completely inside the other.bvh_cache (
Optional
[Dict
[str
,BVHTree
]]) – Dict of all the bvh trees, removes the obj from the cache before adding it again.
- Return type:
Tuple
[bool
,Dict
[str
,BVHTree
]]- Returns:
True, if they are intersecting
- static is_point_inside_object(obj, obj_bvh_tree, point)[source]
Checks whether the given point is inside the given object.
This only works if the given object is watertight and has correct normals
- Parameters:
obj (
MeshObject
) – The objectobj_bvh_tree (
BVHTree
) – A bvh tree of the objectpoint (
Union
[Vector
,ndarray
]) – The point to check
- Return type:
bool
- Returns:
True, if the point is inside the object