Closed
Description
❓ Questions on how to use PyTorch3D
basically the same question asked in #280, but asking for a concrete example
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
is missing in the pipeline. As in this comment, faces.materials_idx
indexes into the material properties for each face, but I couldn't find a place to pass it to the renderer.
here is how I create materials
ambient_color = []
diffuse_color = []
specular_color = []
shininess = []
for colors in aux.material_colors.values():
ambient_color.append(colors['ambient_color'])
diffuse_color.append(colors['diffuse_color'])
specular_color.append(colors['specular_color'])
shininess.append(colors['shininess'])
ambient_color = torch.stack(ambient_color)
diffuse_color = torch.stack(diffuse_color)
specular_color = torch.stack(specular_color)
shininess = torch.stack(shininess)
print(ambient_color.shape, diffuse_color.shape, specular_color.shape, shininess.shape)
mat = Materials(ambient_color, diffuse_color, specular_color, shininess.squeeze(), device=device)
here is how I render an image
renderer = MeshRenderer(
rasterizer=MeshRasterizer(
cameras=cameras,
raster_settings=raster_settings
),
shader=SoftPhongShader(
device=device,
cameras=cameras,
lights=lights,
materials=mat
)
)
images = renderer(mesh, lights=lights, cameras=cameras)
and here is the RuntimeError
RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.