Feat: implement a "small-steps" velocity-based constraints solver + joint improvements #579
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a complete rework of Rapier’s constraints solver. This has been cooking for quite a while now and I think it is time to be published, even though the parallel version has not been fully done yet (it will work, but with only island-based parallelism).
The idea is to combine the substep approach to solving constraints, similar to the latest known improvements of XPBD, but applied to Rapier’s velocity-based constraints formulation. In other words, it does not use the PBD formalism, but will solve Rapier’s pre-existing velocity-based constraints by subdividing the timestep into
n
substeps with 1 force calculation iteration per substep, instead of runningn
force calculation iteration for the full timestep. This result in a significantly improved convergence of joints, especially in case of large mass ratios due to the more non-linear handling of constraints.Other changes include:
RigidBodyBuilder::additional_solver_iterations
,RigidBody::set_additional_solver_iterations
). This allows increasing simulation accuracy on a subset of objects instead of having increase the global solver iteration count, increasing computational cost on unrelated objects.SpringJoint
has been added. More generally, motors on joints with coupled linear axes are now supported.The following video shows the stability improvements on a high-mass-ratio pendulum scenario. The large ball is 1000x heavier than the small ones:
chain-large-mass-ratio-new-solver-20-iterations.mp4
chain-large-mass-ratio-old-solver-4000-iterations.mp4
Here is a video of the new spring joint. The springs, with various damping coefficients, are attached to the balls. The cubes are just object falling freely on top of the balls:
spring-joints.mp4
Fix #241