trimesh icon indicating copy to clipboard operation
trimesh copied to clipboard

load a obj file with vertex color

Open Holmes-Alan opened this issue 2 years ago • 2 comments

I have a question about how to read and write an obj file with vertex colors? using trimesh.load('result.obj') can only return the vertex without color. How can I read the color as well and after I apply some transformation, how can I save the obj with color too?

Holmes-Alan avatar Jun 29 '22 06:06 Holmes-Alan

Hello @Holmes-Alan, Trimesh loads the visual information (vertex colors, material properties, textures) in a Visuals object accessible via your_mesh.visual, see https://trimsh.org/trimesh.visual.html.

If your obj has vertex colors (but no textures), your_mesh.visual should be of type ColorVisuals and your_mesh.visual.vertex_colors should be an array (n, 4) uint8 representing the color of each vertex.

Kiord avatar Jun 30 '22 17:06 Kiord

Hi @Kiord , I'm trying to load colors from a COFF file and an example row in it is: 0.0487114 -0.456213 0.216446 89 71 57 255 . The first three are xyz and I believe the last four elements are the color for the vertex. I also used open3d and it returns true with the has_vertex_colors method. But when I load the color with trimesh.visual.vertex_colors, it always give me an array with [102 102 102 255] in all rows. I'm wondering how can I get it's vertex colors using Trimesh?

Thank you!

zhaoyuanyuan2011 avatar Jul 20 '22 08:07 zhaoyuanyuan2011

https://trimsh.org/trimesh.visual.html

Hi! Could you please explain how do you load a mesh (i.e., an .obj file) into Visuals object using trimesh?

XinYu-Andy avatar Dec 01 '22 06:12 XinYu-Andy