Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exported mesh as .obj appears as solid black color by default #843

Closed
SushmaDG opened this issue May 20, 2020 · 6 comments · Fixed by #851
Closed

Exported mesh as .obj appears as solid black color by default #843

SushmaDG opened this issue May 20, 2020 · 6 comments · Fixed by #851

Comments

@SushmaDG
Copy link

Hi,

I am trying to export a mesh as .obj. The code looks like this:
export, texture = trimesh.exchange.obj.export_obj(mesh, include_color=True, include_texture=True)

with trimesh.util.TemporaryDirectory() as path:
obj_path = os.path.join('', 'file_name.obj')
with open(obj_path, 'w') as f:
f.write(export)
for k, v in texture.items():
with open(os.path.join('', k), 'wb') as f:
f.write(v)

When this obj is loaded again, the model appears in solid black color. As expected the mesh must conserve its color coordinates. I also tried to visualize it in blender API and it displays the mesh in black color by default (as seen in the below image).

mesh

I get the colored model only after changing the mode (display rendered preview in blender api). Could you please tell me how I can get the colored model by default when I load the exported mesh?

Used trimesh version: 3.6.38

Thank you!

@mikedh
Copy link
Owner

mikedh commented May 23, 2020

Gotcha so the color is exporting from trimesh, it just doesn't show up by default in blender? If that's the case it is probably best resolved from the Blender side, I don't know how much we can do about that at export time. Although if you have an example of a file that behaves as you expect happy to take a look and tweak trimesh's export format!

@SushmaDG
Copy link
Author

SushmaDG commented May 24, 2020

Hi,
Yes, I can share the obj files.

  1. This is the original file that behaves as expected.
    file.zip

  2. This is the exported .obj file.
    file2.zip

I also tried to visualize the exported mesh in MeshLab API and it appears in solid black color. The trimesh version used for exporting is 3.6.38 (older). Let me know if there are any solutions or alternatives.
Thank you.

@SushmaDG
Copy link
Author

Hi,

To resolve the issue with exported mesh, I tried a few things:

(1) Loaded an .obj file, then added to pyrender scene and tried to visualize using pyrender.Viewer()

mesh = trimesh.load('/path/to/original/file.obj')
pyrender_mesh = pyrender.Mesh.from_trimesh(mesh, smooth=False)
scene_ = pyrender.Scene()
scene_.add(pyrender_mesh)
pyrender.Viewer(scene_, use_raymond_lighting=True)

I get this:
original_obj

(2.) Now I exported the same loaded mesh,

export, texture = trimesh.exchange.obj.export_obj(mesh, include_color=True, include_texture=True)

I loaded this exported mesh and did the same as in (1). I get this in pyrender.Viewer,
new_obj

Even here I get the same solid black object model. I hope this helps.

@mikedh
Copy link
Owner

mikedh commented May 26, 2020

Hey, I think this is probably related to the MTL/images not being written. There was a pretty recent change to try to simplify this when users export to a path. You might try upgrading to the latest version of trimesh (pip install --upgrade trimesh) and then export using a file path:

mesh.export('drill.obj') 

@SushmaDG
Copy link
Author

Hi,
I tried what you suggested, but the result is still the same. Could you suggest any other solution?
(trimesh version: 3.6.42)
Thank you.

@mikedh
Copy link
Owner

mikedh commented May 26, 2020

Ah, I think this is actually the ambient color set to all zeros in the MTL file due to a dtype issue, #851 should resolve this hopefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants