cremebrule / digital-cousins

Codebase for Automated Creation of Digital Cousins for Robust Policy Learning
https://digital-cousins.github.io
Apache License 2.0
147 stars 16 forks source link

Extraction of Generated Cousins? #15

Closed xiahongchi closed 1 week ago

xiahongchi commented 3 weeks ago

Hi, thanks for your great work!

I just run this code and it works smoothly. I might want to extract the scene into Mesh representation. Is it possible?

Thanks!

cremebrule commented 3 weeks ago

Hi @xiahongchi ,

Great question! Yes, you can technically extract all the ground-truth meshes from all the objects. The code should be something like this:


# Assumes extracted digital cousin scene has already been loaded using `SimulatedSceneGenerator.load_cousin_scene`

import omnigibson as og
from omnigibson.utils.usd_utils import mesh_prim_to_trimesh_mesh

# We traverse over all objects in the scene, and iterate over all their meshes (can be collision or visual) and extract their trimesh mesh representations
meshes = []

for obj in scene.objects:
    for link_name, link in obj.links.items():
        # Choose either of the following, using visual meshes for now
        # for mesh_name, mesh in link.collision_meshes.items():
        for mesh_name, mesh in link.visual_meshes.items():
            print(f"Extracting mesh for {obj.name} : {link_name} : {mesh_name}")
            tm_mesh = mesh_prim_to_trimesh_mesh(mesh.prim, world_frame=True)
            meshes.append(tm_mesh)

# Then your output is in `meshes`
cremebrule commented 1 week ago

Closing this issue for now as there's been no response for a few weeks. Feel free to re-open if you continue to run into issues!