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

Render object without texture #51

Closed
zhjscut opened this issue Feb 12, 2020 · 4 comments
Closed

Render object without texture #51

zhjscut opened this issue Feb 12, 2020 · 4 comments

Comments

@zhjscut
Copy link

zhjscut commented Feb 12, 2020

Hi, I want to ask how can I render objects that have no texture information? Such as ShapeNetSem dataset, whose .obj file contain no line start with "vt ".
And there is the content of a corresponding .mtl file below:
# Blender MTL File: 'None'
# Material Count: 1
newmtl None
Ns 0
Ka 0.000000 0.000000 0.000000
Kd 0.8 0.8 0.8
Ks 0.8 0.8 0.8
d 1
illum 2

As far as I know, MeshRenderer class need a shader, and the shader need texture information to work regularly. When I execute this line: verts, faces, aux = load_obj(shapenetsem_obj_filename), I get an empty aux. And then I create a mesh instance without texture: mesh = Meshes(verts=[verts], faces=[faces_idx], textures=None), and when I render mesh like the tutorial, it occurs "ValueError: Expected meshes.textures to be an instance of Textures; got <class 'NoneType'>"
How can I solve this problem? Thank you for your help!

@Chr1k0
Copy link
Contributor

Chr1k0 commented Feb 12, 2020

Here you find an example: https://github.com/facebookresearch/pytorch3d/blob/master/docs/tutorials/camera_position_optimization_with_differentiable_rendering.ipynb

-Load the obj and ignore the textures and materials.
verts, faces_idx, _ = load_obj("./data/teapot.obj")
faces = faces_idx.verts_idx

-Initialize each vertex to be white in color.
verts_rgb = torch.ones_like(verts)[None] # (1, V, 3)
textures = Textures(verts_rgb=verts_rgb.to(device))

-Create a Meshes object for the teapot. Here we have only one mesh in the batch.
teapot_mesh = Meshes(
verts=[verts.to(device)],
faces=[faces.to(device)],
textures=textures
)

@nikhilaravi
Copy link
Contributor

nikhilaravi commented Feb 12, 2020

@Chr1k0 thanks for stepping in to help!

To clarify your points:

  1. texture is not required as an input to Meshes - so you don't need to pass in textures=None.
  2. Not all shaders require texture. The shaders are meant to be entirely customizable so if you do not require texturing you can simply create a new Shader class with a forward method which does not have a texturing step. If you do want a plain color texture, you can initialize a color per vertex as explained by @Chr1k0.

@zhjscut
Copy link
Author

zhjscut commented Feb 13, 2020

@Chr1k0 @nikhilaravi Thanks! You solve my problem~

@albertotono
Copy link
Contributor

verts_rgb = torch.ones_like(verts)[None] # (1, V, 3)
textures = Textures(verts_rgb=verts_rgb.to(device))

I think now it is

verts_rgb = torch.ones_like(verts)[None]  # (1, V, 3)
textures = TexturesVertex(verts_features=verts_rgb.to(device))

FYI https://github.com/facebookresearch/pytorch3d/blob/main/docs/tutorials/camera_position_optimization_with_differentiable_rendering.ipynb

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

No branches or pull requests

4 participants