Skip to content

[BUG] First contact point tid is lost in handle_contact_pairs #623

@JonathanKuelz

Description

@JonathanKuelz

Bug Description

The kernel handle_contact_pairs [src] identifies and stores contact points between shapes of rigid bodies being in collision. One of the the kernel outputs is the array contact_tids. This kernel is necessary to identify which element in the other output arrays (contact_point0 etc) was written in which thread and thus, corresponds to which contact point of the corresponding shape.

For instance, if I want to figure out which mesh vertex is represented by contact_point0[x], I am able to figure it out using where(contact_tids) == x.

The kernel starts writing to the output tensors at index 0 (even though the variable name next_count here suggests something else, wp.atomic_add returns the old value). At the same time, contact_tids is initialized as a zero array. This makes it impossible to find the tid at which the very first element of the arrays has been written, because where(contact_tids) == x evaluates to true for this tid, but also all where no contact was detected.

We can see the effect, e.g. by doing:

tids = torch.tensor(model.rigid_contact_tids)
count = torch.tensor(model.rigid_contact_count)
print(f"Count: {count.item()}, Nonzero entries in tid: {(tids != 0).sum().item()}")

==> Count: 102, Nonzero entries in tid: 101

As far as I see, an easy fix would be initializing contact_tids with -1, as done for the contact shapes.

System Information

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions