compas-dev / compas_fab

Robotic fabrication package for the COMPAS Framework.
https://compas.dev/compas_fab/
MIT License
108 stars 32 forks source link

PybulletClient cannot load two different collision meshes into the scene #305

Closed yijiangh closed 3 years ago

yijiangh commented 3 years ago

Describe the bug PybulletClient cannot load two different collision meshes into the scene. The client can only load the mesh that's loaded first.

I have the following script (full working example below):

with PyBulletClient(connection_type="gui", verbose=False) as client:
    base_plate_cm = parse_collision_mesh_from_path(data_dir, "base_plate.obj", scale=1)
    column_obstacle_cm = parse_collision_mesh_from_path(data_dir, "column_obstacle.obj", scale=1)
    client.add_collision_mesh(base_plate_cm)
    client.add_collision_mesh(column_obstacle_cm)

I expect that there are two different collision meshes in the scene: image

But this is what PybulletClient gives me: image

To Reproduce Minimal working example:

import os
import pybullet as p
from compas.datastructures import Mesh
from compas_fab.robots import CollisionMesh
from compas_fab.backends import PyBulletClient

HERE = os.path.dirname(__file__)

def parse_collision_mesh_from_path(dir_path, filename, scale=1e-3):
    file_path = os.path.join(dir_path, filename)
    obj_name = filename.split('.')[0]
    if filename.endswith('.obj'):
        mesh = Mesh.from_obj(file_path)
    elif filename.endswith('.stl'):
        mesh = Mesh.from_stl(file_path)
    else:
        return None
    cm = CollisionMesh(mesh, obj_name)
    cm.scale(scale)
    return cm

with PyBulletClient(connection_type="gui", verbose=False) as client:
    data_dir = HERE
    base_plate_cm = parse_collision_mesh_from_path(data_dir, "base_plate.obj", scale=1)
    column_obstacle_cm = parse_collision_mesh_from_path(data_dir, "column_obstacle.obj", scale=1)

    client.add_collision_mesh(base_plate_cm)
    client.add_collision_mesh(column_obstacle_cm)

    input()

Zip file with data

Desktop (please complete the following information):

Comments:

In compas_fab 0.16.0, we used to use tempdir when creating the temporary mesh to be loaded by pybullet: https://github.com/compas-dev/compas_fab/blob/78efe1f87621b2bf7c83d3f8466a7e6e181553df/src/compas_fab/backends/pybullet/client.py#L429-L442

But I saw that this is removed in 0.17.0, @gonzalocasas @beverlylytle is there a reason for this? https://github.com/compas-dev/compas_fab/blob/811b9ac8d15570d321966c38183bb9c617983d11/src/compas_fab/backends/pybullet/client.py#L625-L629

I revert the convert_mesh_to_body to the version used in 0.16.0 and the problem is fixed.