Skip to content

How render image with some constant colors that described in OBJ-file #280

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

Closed
attashe opened this issue Jul 21, 2020 · 3 comments
Closed
Assignees
Labels
how to How to use PyTorch3D in my project

Comments

@attashe
Copy link

attashe commented Jul 21, 2020

In this question was explained how render image without texture
#51

But in my case in MTL-file contain material with constatnt color and in OBJ-file described what vertex have this color

newmtl Color_003
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.666667 0.666667 0.666667
Ks 0.330000 0.330000 0.330000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
usemtl Color_003
f 1/1 2/2 3/3
...
f 7/19 5/18 6/21
v 0.412338662557 0.0913135972693 0.18293131387
...
v 0.35328764703 0.107066507113 0.170653379949
vt -5.0965 1.0390
...
vt 5.0965 1.0390

Can I generate texture using commands from OBJ-file: usemtl Color_003?

@nikhilaravi nikhilaravi self-assigned this Jul 22, 2020
@nikhilaravi nikhilaravi added the how to How to use PyTorch3D in my project label Aug 5, 2020
@nikhilaravi
Copy link
Contributor

In the load_obj function we load the Ns, Ka, Kd, Ks properties from the .mtl file. You can retrieve them from the aux tuple that is return from load_obj e.g.

verts, faces, aux = load_obj("path_to_mesh.obj")

per_face_material_idx = faces.materials_idx
material_properties = aux.material_colors

The materials_idx indexes into the material_properties. We also have a Materials class which can be used to store the materials for rendering.

Here is a full description of the outputs from load_obj: https://github.com/facebookresearch/pytorch3d/blob/master/pytorch3d/io/obj_io.py#L185-L199

The shaders in the renderer accept the Materials class as an input: https://github.com/facebookresearch/pytorch3d/blob/master/pytorch3d/renderer/mesh/shader.py#L43

@gkioxari
Copy link
Contributor

@attashe hopefully the response above solved your question. Closing this. Feel free to reopen if you have further questions.

@Nan2018
Copy link

Nan2018 commented Mar 4, 2022

is there a concrete example somewhere?

I was able to create the Materials object from aux.material_colors. But passing it to shader causes a RuntimeError when rendering. (Same error with renderer(materials=materials)). My feeling is faces.materials_idx missing in the pipeline. As @nikhilaravi said, faces.materials_idx indexes into the material properties for each face, but I couldn't find a place to pass it to the renderer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
how to How to use PyTorch3D in my project
Projects
None yet
Development

No branches or pull requests

4 participants