Skip to content

Conversation

Eideren
Copy link
Collaborator

@Eideren Eideren commented Sep 19, 2025

PR Details

Made IContactEventHandler obsolete and replacing it by IContactHandler for two major reason:

  • Those methods aren't easily extensible, if we want to add support for more things when providing contacts, we can't change the method's signature as ...
    • They have a default implementation, if the user does not implement the method using an explicit signature, the method they implemented would not be called anymore, silently failing.
    • If the user has an explicit signature, we still have no choice but change the signature to add more parameters, creating a syntax error in user projects ...
  • We only have a handful of methods that are useful, the others are extremely niche, introducing a non-negligible performance deficit if we want to keep supporting them.
    • OnPairCreated, OnPairUpdated, OnPairEnded are called even when the object is not in contact, after playing around with bepu for a while, I can't think of any reason why this would be useful to me or other users. It is also somewhat ambiguous, as user may mistake this method as the one to use to detect contacts.
    • OnContactAdded and OnContactRemoved are definitely more useful, but still fairly niche and would be better off implemented on the users' side to ensure that we don't pay the cost of this feature for every single IContactEventHandler, but only those that the user actually cares about.

Improvements made to the event interface:

Contacts have been made more user friendly, users can now foreach through each contacts instead of manually inspecting the somewhat obtuse manifold:

void OnStartedTouching<TManifold>(Contacts<TManifold> contacts) where TManifold : unmanaged, IContactManifold<TManifold>
{
   foreach (var contact in contacts)
   {
       contact.Normal ...
   }
}

Surfaced a couple of new information one might need when receiving a collision:

  • Linear and Angular velocity for both collidables prior to collision to compute impact forces for example.
  • A function to evaluate the impact force for a given contact.
  • ChildIndex for both collidables to figure out which child of a compound was hit.

Breaking Changes

IContactEventHandler should be replaced with IContactHandler , references in yaml are safe as the former inherits from the later. I marked methods that are now unsupported as errors to let users know that those won't be called anymore.

Related Issue

Fixes #2884

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

Todo

  • Update samples
  • Update documentation

@Eideren Eideren marked this pull request as draft September 23, 2025 13:21
@Eideren Eideren marked this pull request as ready for review September 25, 2025 09:44
@Eideren Eideren marked this pull request as draft September 25, 2025 18:22
@Eideren Eideren marked this pull request as ready for review September 27, 2025 10:10
@Eideren Eideren changed the title fix: Refactor bepu contact management, support compound shape child index lookup fix: Refactor bepu contact management, support compound shape child index lookup and provide Impact Force evaluation to users Sep 27, 2025
@Eideren Eideren added the breaking-change Makes the pull request appear in "Breaking Changes" section of the next release note label Sep 27, 2025
@Eideren Eideren merged commit e162677 into stride3d:master Oct 1, 2025
7 checks passed
@Eideren Eideren deleted the contact_child_index branch October 1, 2025 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Physics breaking-change Makes the pull request appear in "Breaking Changes" section of the next release note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BepuPhysics: NullReferenceExeption in RunManifoldEvent

1 participant