gimpact

Functions

initialize
terminate
trimesh_capsule_collision Determines contacts of a trimesh-capsule collision.
trimesh_plane_collision Determines contacts of a trimesh-plane collision.
trimesh_ray_closest_collision Determines closest contact of a trimesh-ray collision.
trimesh_ray_collision Determines contact of a trimesh-ray collision.
trimesh_sphere_collision Determines contacts of a trimesh-sphere collision
trimesh_trimesh_collision Determines contacts of a trimesh-trimesh collision.

Classes

AABBSet Represents a collection of axis-aligned bounding boxes (AABBs)
Contact Represents a collision contact
TriMesh Represents a triangle mesh
class gimpact.AABB

Bases: object

Represents an axis-aligned bounding boxes (AABB). If the AABB is returned by an AABBSet, the AABB still “belongs to” to that AABBSet, so modifying it will alter the AABBSet; make a copy of it if you wish to modify it seperately.

Parameters:
  • min_x (float) – minimum of x axis
  • max_x (float) – maximum of x axis
  • min_y (float) – minimum of y axis
  • max_y (float) – maximum of y axis
  • min_z (float) – minimum of z axis
  • max_z (float) – maximum of z axis
bounds

Gets and Sets Bounds of the AABB as a tuple (min_x, max_x, min_y, max_y, min_z, max_z)

clone()

clones the AABB.

Returns:AABB clone
Return type:AABB
intersection()

Finds intersection between the AABB and a given AABB. The resulting intersection will an invalid bounding box (i.e minimum will be greater than maximum in the non-overlapping axis) if both boxes do not intersect.

Parameters:aabb (AABB) – bounding box
Returns:intersection of boxes
Return type:AABB
intersects()

Checks if the AABB intersects with a given AABB.

Parameters:aabb (AABB) – bounding box
Returns:flag indicating if the boxes intersect
Return type:bool
max_x

Gets and Sets maximum x-axis value of the AABB

max_y

Gets and Sets maximum y-axis value of the AABB

max_z

Gets and Sets maximum z-axis value of the AABB

merge()

Merge the AABB with a given AABB.

Parameters:aabb (AABB) – bounding box
min_x

Gets and Sets minimum x-axis value of the AABB

min_y

Gets and Sets minimum x-axis value of the AABB

min_z

Gets and Sets minimum z-axis value of the AABB

class gimpact.AABBSet

Bases: object

Represents a collection of axis-aligned bounding boxes (AABBs)

Parameters:count (int) – number of bounding box
find_intersections()

Finds all intersections between this AABBs of this AABBSet and those of another.

Parameters:aabb_set (AABBSet) – the other AABBSet
Returns:A list of intersecting index pairs
Return type:List[Tuple[int]]
global_bounds

Gets the AABB for the entire collection

Returns:bounding box of AABBSet
Return type:AABB
class gimpact.Contact

Bases: object

Represents a collision contact

Parameters:
  • point (Array[float]) – intersection point
  • normal (Array[float]) – friction direction
  • depth (float) – peneration depth
  • feature1 (int) – index of colliding triangle in first mesh.
  • feature2 (int) – index of colliding triangle in second mesh.
class gimpact.TriMesh

Bases: object

Represents a triangle mesh

Parameters:
  • vertices (Array[float]) – array of 3D vertices
  • indices (Array[int]) – array of indices
aabb_set

Gets an AABBSet containing the AABBs of the triangles in trimesh

Returns:AABBSet of Trimesh
Return type:AABBSet
bounds

Gets an AABB bounding the trimesh

Returns:bounding box of Trimesh
Return type:AABB
clone()

clones the trimesh.

Returns:trimesh clone
Return type:Trimesh
decimate()

Simplifies mesh to a given target number of faces. Returns the same mesh if its face count is less than or equal to target_count.

Parameters:target_count (int) – target number of faces
Returns:simplified trimesh
Return type:Trimesh
transform()

Transform triangle mesh in-place with given matrix.

Parameters:matrix (Array[float]) – 4 x 4 transformation matrix
triangle()

returns vertices of the triangle with specified index

Parameters:idx (int) – triangle index
Returns:vertices of triangle with specified index
Return type:Tuple[Tuple[float, float, float]]
triangle_count

Returns the number of triangles in the TriMesh.

Returns:the number of triangles in the TriMesh
Return type:int
gimpact.trimesh_capsule_collision()

Determines contacts of a trimesh-capsule collision.

Parameters:
  • trimesh (Trimesh) – triangle mesh
  • point1 (Array[float]) – first end-point of the capsule
  • point2 (Array[float]) – second end-point of the capsule
  • radius (float) – radius of the sphere
  • first_only (bool) – flag that indicates only first contact is required
Returns:

a list of Contacts

Return type:

List[Contact]

gimpact.trimesh_plane_collision()

Determines contacts of a trimesh-plane collision.

Parameters:
  • trimesh (Trimesh) – triangle mesh
  • plane (Array[float]) – plane parameters (a, b, c, d) in form of ax + by + cz + d = 0
  • first_only (bool) – flag that indicates only first contact is required
Returns:

a list of tuples containing point and penetration depth

Return type:

List[Tuple[Array[float], float]]

gimpact.trimesh_ray_closest_collision()

Determines closest contact of a trimesh-ray collision. Collision is considered valid only when the ray collides with the front faces of the trimesh

Parameters:
  • trimesh (Trimesh) – triangle mesh
  • origin (Array[float]) – origin point of ray
  • direction (Array[float]) – direction vector of ray
  • tmax (float) – max distance param for ray.
Returns:

closest contact if ray collides else None

Return type:

Union[Contact, None]

gimpact.trimesh_ray_collision()

Determines contact of a trimesh-ray collision. Collision is considered valid only when the ray collides with the front faces of the trimesh

Parameters:
  • trimesh (Trimesh) – triangle mesh
  • origin (Array[float]) – origin point of ray
  • direction (Array[float]) – direction vector of ray
  • tmax (float) – max distance param for ray.
Returns:

random contact if ray collides else None

Return type:

Union[Contact, None]

gimpact.trimesh_sphere_collision()

Determines contacts of a trimesh-sphere collision

Parameters:
  • trimesh (Trimesh) – triangle mesh
  • center (Array[float]) – center of the sphere
  • radius (float) – radius of the sphere
  • first_only (bool) – flag that indicates only first contact is required
Returns:

a list of Contacts

Return type:

List[Contact]

gimpact.trimesh_trimesh_collision()

Determines contacts of a trimesh-trimesh collision.

Parameters:
  • trimesh1 (Trimesh) – first triangle mesh
  • trimesh2 (Trimesh) – second triangle mesh
  • first_only (bool) – flag that indicates only first contact is required
Returns:

a list of Contacts

Return type:

List[Contact]