pyg-team / pytorch_geometric

Graph Neural Network Library for PyTorch
https://pyg.org
MIT License
21.41k stars 3.67k forks source link

Wrong Trimesh conversion #990

Closed simofoti closed 4 years ago

simofoti commented 4 years ago

🐛 Bug

Hi,

First of all, thanks for this amazing library.

I was trying to convert a torch_geometric Data object in Trimesh, but I wasn't able to properly colour the vertices I wanted. Apparently Trimesh re-orders the vertices during the conversion.

To Reproduce

Steps to reproduce the behavior:

  1. Do the following:
    torch_geom_obj = torch_geometric.io.read_obj(PATH)
    trim_obj = torch_geometric.utils.to_trimesh(torch_geom_obj)
    torch_geom_obj_2 = torch_geometric.utils.from_trimesh(trim_obj)
  2. Comparing torch_geom_obj.pos with torch_geom_obj_2.pos you will notice that they are different.

Expected behavior

In my opinion torch_geom_obj.pos and torch_geom_obj_2.pos should be the same, this would ease the display of information on the mesh through Trimesh (e.g. it would allow to colour vertices given indices or vertex-wise colours obtained in pytorch geometric).

This behaviour is actually trvial to fix. It is just a matter of changing the returned object of the following function

https://github.com/rusty1s/pytorch_geometric/blob/35003e272c723187d2cb5be51bcf04861db12518/torch_geometric/utils/convert.py#L116-L128

with:

return trimesh.Trimesh(
          vertices=data.pos.detach().cpu().numpy(),
          faces=data.face.detach().t().cpu().numpy(), 
          process=False)
rusty1s commented 4 years ago

Awesome, I didn't know about the process flag. Fixed in master! Thank you.

simofoti commented 4 years ago

Cool, thanks to you!

lvjiujin commented 3 years ago

ImportError: Package trimesh could not be found.

rusty1s commented 3 years ago

You need to install trimesh via:

pip install trimesh