Skip to content

Per-manifold material properties and tangent velocity #660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 1, 2025

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Feb 25, 2025

Objective

Follow-up to #610.

Now that we have contact modification hooks, we should add support for modifying the surface properties of contacts. This can enable use cases like conveyor belts or non-uniform friction and restitution for different parts of a mesh.

Solution

Add friction, restitution, and tangent_speed/tangent_velocity properties to ContactManifold. These are copied over for each ContactConstraint.

Note

Why not have a hook for modifying ContactConstraint directly instead?

While we could technically do this right now, once we have wide SIMD constraints, ContactConstraint will also have its own SIMD version that is not as user-friendly and depends on feature flags. Providing hooks for modifying that is not very viable, and it would not be good for UX. Splitting contact modification into two hooks for different types of contact types could also be confusing for users.

The new tangent velocity is a way to emulate relative movement of contact surfaces, which is often used for conveyor belts. A new conveyor_belt example has been added to demonstrate this.

conveyor_belt.mp4

Engines like Rapier, Jolt, and Box2D also have tangent velocity and other material properties, but the capabilities for contact modification are different.

  • Rapier: Friction, restitution, and tangent velocity can be set for each solver contact point.
  • Jolt: Friction, restitution, and tangent velocity can be set for each contact manifold.
  • Box2D: Friction, restitution, and tangent velocity cannot be modified in pre-solve hooks, but friction and restitution have their own optional callbacks for basic mixing logic (I believe Jolt also has this), and chain shapes support per-segment materials. So, surface properties can only be set per shape (pair), but it is still decently flexible for 2D.

I opted for Jolt's approach of per-manifold configuration for now. It lets you have different material properties for e.g. different triangles of a trimesh, while keeping memory usage fairly minimal by not storing the properties for each individual contact point. I think this is a good balance of flexibility and cost.

If important use cases that require per-point surface properties arise, we could switch to that, but I'd prefer to keep things more simple and minimal for now.

@Jondolf Jondolf added C-Enhancement New feature or request A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on labels Feb 25, 2025
@Jondolf Jondolf added this to the 0.3 milestone Feb 25, 2025
@Jondolf Jondolf enabled auto-merge (squash) March 1, 2025 13:34
@Jondolf Jondolf merged commit 0474c72 into main Mar 1, 2025
5 checks passed
@Jondolf Jondolf deleted the manifold-surface-properties branch March 1, 2025 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on C-Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant