mikedh / trimesh

Python library for loading and using triangular meshes.

Home Page:https://trimesh.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Collision Detection Inaccuracy

Box-Inside-Box opened this issue · comments

I used trimesh's Collision Manager to find collisions in a scene. If an object is present inside another object, then I do not call it as collision.

Code:

    def create_collision_graph(self):
        collision_manager = CollisionManager()

        for obj_name, mesh in self.trimesh_objects.items():
            if not mesh.is_empty:
                collision_manager.add_object(obj_name, mesh)

        is_collision, names = collision_manager.in_collision_internal(return_names=True, return_data=False)

        if is_collision:
            for name1, name2 in names:
                self.collision_dict.setdefault(name1, set()).add(name2)
                self.collision_dict.setdefault(name2, set()).add(name1)

trimesh_objects is a dict with names and trimesh objects stored beforehand.

I'm getting weird results.
Ideally, there are no collisions in my file broadphase_failure_3.glb

there are 3 objects: Cone, Sphere, Cube. Cube is inside the Sphere, and Sphere is inside the Cone. So no collisions technically.
But the code suggests a collision between Sphere and Cube, and no other.

also, if you instead check this file: broadphase_failure_2.glb

here the cone is straight (unlike the inverted in the previous file). And code outputs collision between all the three objects.

How do I change the code to detect collisions only, and none of the containments?