Closed raoshashank closed 5 months ago
Based on the images, it looks like all meshes are referencing the same set of vertices. Have you offset the vertex indices in the meshes' triangles to account for their different starting points in the vertex array?
do you mean I should be adding a constant to all the mesh indices for all the batches after the first one based on their position? for example, for the mesh indices for batch 3, I should add N_1_3 = number of triangles in mesh 1 + number of triangles in mesh 2?
Yes, the triangles should reference the actual indices of the vertices in the position array.
Can confirm, this works. For future reference, the batch mesh render function is to be updated as follows:
def batch_mesh_forward(meshes,object_names):
props = ['pos','pos_idx','uv','uv_idx']
mesh_result = {}
count = {}
start_index= {}
meshes = {o: meshes[o]() for o in list(set(object_names))}
for p in props:
count[p] = []
mesh_result[p] = []
for i,n in enumerate(object_names):
mesh_result[p].append(meshes[n][p])
count[p].append(meshes[n][p].shape[0])
mesh_result[p] = torch.concat(mesh_result[p],dim=0).cuda()
count[p] = torch.tensor(count[p])
start_index[p] = torch.roll(torch.cumsum(count[p],0),shifts=1,dims=0)
start_index[p][0]=0
mesh_result['tex'] = torch.stack([meshes[n]['tex'] for n in object_names])
mesh_result['ranges'] = torch.vstack((start_index['pos_idx'],count['pos_idx'])).T #shape = num of trianges x 2
for i in range(len(object_names)):
s = start_index['pos_idx'][i]
e = s + count['pos_idx'][i]
c = start_index['pos'][i]
mesh_result['pos_idx'][s:e,:]+=c
return mesh_result,count,start_index
This is based on the use case in https://github.com/NVlabs/diff-dope/issues/3. I'm trying to render RGBD images of YCB objects with different meshes in each minibatch index using the range mode. However, I'm finding that only the first minibatch index is correctly rendered. As instructed in the documentation, I am providing the start index and the number of triangles per batch index as a tensor of Bx2 shape and providing the triangle indices and the point cloud as Nx4 and Mx3 tensors respectively. I suspect that the triangle indices are not being used correctly in the range mode. It would be super helpful if a range mode example is provided in the repo itself.. MWE (uses YCB object meshes):
results:![image](https://github.com/NVlabs/nvdiffrast/assets/19906907/1be0f47b-caa7-4b4b-85eb-41fd353fc5d9)