pytorch3d icon indicating copy to clipboard operation
pytorch3d copied to clipboard

Seems `load_obj` can not load `vertices` with `vertex-color`

Open Matt-V50 opened this issue 2 years ago • 3 comments

I have an obj file that includes vertex-color.

It looks like

vn 0.228076 -5.246246 2.607272
v -0.053804 0.709615 -0.144573 0.235294 0.992157 0.125490
vn -0.542669 -4.832255 3.054440
v -0.056966 0.711699 -0.141544 0.235294 0.992157 0.125490
...

How did this file come from

  • Download the ply file
  • Open it in MeshLab
  • Export it to the obj file

I checked the key method _parse_obj, as you can see below

https://github.com/facebookresearch/pytorch3d/blob/7978ffd1e4819d24803b01a1147a2c33ad97c142/pytorch3d/io/obj_io.py#L459-L464

And it seems can not load vertex-color, cause the code use token[1:4] only

Matt-V50 avatar Jul 26 '22 08:07 Matt-V50

You are right that we do not support vertex color in obj files. Let us know if you would like to contribute such support.

Just to respond to the title: the vertices are loaded but their colors are not.

bottler avatar Jul 26 '22 09:07 bottler

I opened a related issue about supporting loading obj with vertex color. But in my case, the vertex color range is [0,255], here is [0,1]. If someone contribute this feature, please consider these two cases ~ (I am new to pytorch3d, i think it is hard for me to contribute this feature correctly now)

wwdok avatar Jul 26 '22 10:07 wwdok

Use trimesh as a temporary alternative.

import trimesh
trimesh.load(obj_file)
colors = torch.Tensor(tri_mesh.visual.vertex_colors)  # [N, C], Channel = 4 for default.

Btw, pytorch3d can not load files by specific encoding.

Matt-V50 avatar Jul 26 '22 11:07 Matt-V50