Modify contacts outside of onContactModify()

Is it at all possible to modify contact points outside of the scope of onContactModify()?

Ideally, I’d like to retrieve all the contact points after fetchCollision(true), modify each one, and then proceed to call advance().

Which version of PhysX are you talking about? I can find no reference to a method called fetchCollision in the 3.3.4 source or documentation. In any case that’s the only hook I’m aware of that PhysX provides for contact modification but they do provide the source so I imagine you could add your own hook in a different location if you really needed it. I suspect that some information about the collisions would be lost (relative to onContactModify) if you were to try and modify the constraint table directly after all the contacts had been added but that’s just a guess.

I’m using 3.4 (beta).

Yes, it’s not obvious how (or whether it is even possible) to modify the contact points outside of the callback. The onContactModify function is called from deep within the narrow phase and it is called from multiple threads. Also, immediately after the onContactModify function is called, the patches are recomputed. This is all done inside one function in the narrow phase.

There isn’t currently a way to modify the contacts outside of the contact modification callbacks. There are a few differences to the format in which modifiable contacts are written out to memory compared to if they’re regular (non-modifiable) pairs so it’s not really feasible to modify pairs that were not flagged to do so. In addition, 3.4 now supports GPU rigid bodies. GPU sim still supports contact modification but any pairs requesting modification have to be processed on the CPU with the results DMAd to the GPU after modification. If you didn’t tell it that you wanted to modify a pair, the contacts for that pair will not be available for the CPU to access until fetchResults.

Also, there is a small nuance that some contact gen can occur after fetchCollision() during advance(). This is because application code can apply forces/impulses, set velocities or kinematic targets etc. right up to calling advance() and these will be reflected in the simulation. These operations can activate actors, which would then potentially require some contact generation to be performed outside of the collision stage of the simulation to ensure correct behavior.

Is there a particular problem you’re trying to overcome by modifying contacts in fetchCollision()?

Thank you for the detailed explanation.

The reason I ask is that we support a number of different physics engines. For each physics engine we write a wrapper than implements a set of interfaces and abides by a behavioural specification (e.g. that specifies the local axis of freedom for joints). I was hoping that I would not need to change this interface, but it looks like I will need to do so.

Thanks again.