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
How can I solve this problem? Thank you for your help!
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
)
@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.
@Chr1k0 @nikhilaravi Thanks! You solve my problem~
Most helpful comment
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
)