soft_body_settings
A few settings are shared by every soft-body of the world. They are part of the integration
parametersintegration_parameters.soft_bodies field of the
RapierContextSimulation component)softBodies field of R3IntegrationParameters)soft_bodies property of IntegrationParameters, a SoftBodiesSettings)
- The re-sweep strain
(
resweep_strainsoftBodiesResweepStrainr3SoftBodiesSetResweepStrain ) is the strain beyond which a constraint is solved once more after the contacts of every substep. This is what keeps a light body buried under heavier ones from being torn apart by them.resweep_strain - The maximum number of extra substeps
(
max_extra_substepssoftBodiesMaxExtraSubstepsr3SoftBodiesSetMaxExtraSubsteps ) is the number of substeps a soft-body is allowed to ask for while it is hit fast. Those substeps bound the motion of its particles, and the motion of the rigid-bodies approaching them, by about one particle radius per substep. Giving zero disables them.max_extra_substeps - The contact stiffening
(
contact_stiffeningsoftBodiesContactStiffeningr3SoftBodiesSetContactStiffening ) multiplies the natural frequencies of the contacts involving a soft-body. Those contacts run stiffer than the rigid ones because the mass behind one contact is the mass of a few particles, and not the mass of the whole body.contact_stiffening
In addition, the detection of the penetrations and of the tangles, as well as the way the bodies recover from them, are
configured by the recovery settings (recovery, a SoftRecoverySettingssoftBodiesRecovery,
a SoftRecoverySettingsrecovery, an R3SoftRecoverySettingsrecovery, a SoftRecoverySettingsfem, a
SoftFemParameterssoftBodiesFem* parametersfem, an R3SoftFemParametersfem, a SoftFemParameters
- Example 2D
- Example 3D
// Settings shared by every soft body of the world.
let settings = &mut world.integration_parameters.soft_bodies;
// Strain beyond which a constraint is re-solved after the contacts of every substep.
// Default: 0.75
settings.resweep_strain = 0.75;
// Extra substeps a soft body requests while it is hit fast; 0 disables them.
// Default: 4
settings.max_extra_substeps = 4;
// Stiffening of the soft-body contacts relative to the rigid ones.
// Default: 4.0
settings.contact_stiffening = 4.0;
// The tangle detection and recovery stack can be switched off mechanism by mechanism.
settings.recovery.crossing_repulsion = true;
// Settings shared by every soft body of the world.
let settings = &mut world.integration_parameters.soft_bodies;
// Strain beyond which a constraint is re-solved after the contacts of every substep.
// Default: 0.75
settings.resweep_strain = 0.75;
// Extra substeps a soft body requests while it is hit fast; 0 disables them.
// Default: 4
settings.max_extra_substeps = 4;
// Stiffening of the soft-body contacts relative to the rigid ones.
// Default: 4.0
settings.contact_stiffening = 4.0;
// The tangle detection and recovery stack can be switched off mechanism by mechanism.
settings.recovery.crossing_repulsion = true;
Those settings are plain fields of the integration parameters of the world. Note that softBodiesRecovery gives back a
copy of the recovery settings, which is assigned back to the integration parameters to apply it:
- Example 2D
- Example 3D
// Settings shared by every soft body of the world.
// Strain beyond which a constraint is re-solved after the contacts of every substep.
// Default: 0.75
world.integrationParameters.softBodiesResweepStrain = 0.75;
// Extra substeps a soft body requests while it is hit fast; 0 disables them.
// Default: 4
world.integrationParameters.softBodiesMaxExtraSubsteps = 4;
// Stiffening of the soft-body contacts relative to the rigid ones.
// Default: 4.0
world.integrationParameters.softBodiesContactStiffening = 4.0;
// The tangle detection and recovery stack can be switched off mechanism by mechanism; the
// getter gives back a copy, so the settings are assigned back after being changed.
let recovery = world.integrationParameters.softBodiesRecovery;
recovery.crossingRepulsion = true;
world.integrationParameters.softBodiesRecovery = recovery;
// Settings shared by every soft body of the world.
// Strain beyond which a constraint is re-solved after the contacts of every substep.
// Default: 0.75
world.integrationParameters.softBodiesResweepStrain = 0.75;
// Extra substeps a soft body requests while it is hit fast; 0 disables them.
// Default: 4
world.integrationParameters.softBodiesMaxExtraSubsteps = 4;
// Stiffening of the soft-body contacts relative to the rigid ones.
// Default: 4.0
world.integrationParameters.softBodiesContactStiffening = 4.0;
// The tangle detection and recovery stack can be switched off mechanism by mechanism; the
// getter gives back a copy, so the settings are assigned back after being changed.
let recovery = world.integrationParameters.softBodiesRecovery;
recovery.crossingRepulsion = true;
world.integrationParameters.softBodiesRecovery = recovery;
- Example 2D
- Example 3D
fn configure_soft_bodies(
mut simulation: Single<&mut RapierContextSimulation, With<DefaultRapierContext>>,
) {
// Settings shared by every soft-body of the physics context.
let settings = &mut simulation.integration_parameters.soft_bodies;
// Strain beyond which a constraint is re-solved after the contacts of every substep.
// Default: 0.75
settings.resweep_strain = 0.75;
// Extra substeps a soft-body requests while it is hit fast; 0 disables them.
// Default: 4
settings.max_extra_substeps = 4;
// Stiffening of the soft-body contacts relative to the rigid ones.
// Default: 4.0
settings.contact_stiffening = 4.0;
// The tangle detection and recovery stack can be switched off mechanism by mechanism.
settings.recovery.crossing_repulsion = true;
}
fn configure_soft_bodies(
mut simulation: Single<&mut RapierContextSimulation, With<DefaultRapierContext>>,
) {
// Settings shared by every soft-body of the physics context.
let settings = &mut simulation.integration_parameters.soft_bodies;
// Strain beyond which a constraint is re-solved after the contacts of every substep.
// Default: 0.75
settings.resweep_strain = 0.75;
// Extra substeps a soft-body requests while it is hit fast; 0 disables them.
// Default: 4
settings.max_extra_substeps = 4;
// Stiffening of the soft-body contacts relative to the rigid ones.
// Default: 4.0
settings.contact_stiffening = 4.0;
// The tangle detection and recovery stack can be switched off mechanism by mechanism.
settings.recovery.crossing_repulsion = true;
}
Each of these settings has its own getter and setter, named after its field: e.g., r3SoftBodiesResweepStrain and
r3SoftBodiesSetResweepStrain, r3RecoveryCrossingRepulsion and r3RecoverySetCrossingRepulsion, or
r3FemLinearTolerance and r3FemSetLinearTolerance. All of them can also be read at once with
r3IntegrationParameters, which returns a copy of the integration parameters of the world: that copy is modified, then
written back with r3SetIntegrationParameters. Note that the fem field, as well as the r3Fem* functions, only
exist when the library is built with the fem feature:
- Example 2D
- Example 3D
// Settings shared by every soft-body of the world.
// Strain beyond which a constraint is re-solved after the contacts of every substep.
// Default: 0.75
r2SoftBodiesSetResweepStrain(world, 0.75);
// Extra substeps a soft-body requests while it is hit fast; 0 disables them.
// Default: 4
r2SoftBodiesSetMaxExtraSubsteps(world, 4);
// Stiffening of the soft-body contacts relative to the rigid ones.
// Default: 4.0
r2SoftBodiesSetContactStiffening(world, 4.0);
// The tangle detection and recovery stack can be switched off mechanism by mechanism.
r2RecoverySetCrossingRepulsion(world, 1);
// The settings can also be read all at once (as a copy), modified, and written back.
R2IntegrationParameters params = r2IntegrationParameters(world);
params.softBodies.recovery.selfStandDown = 1;
r2SetIntegrationParameters(world, ¶ms);
// Settings shared by every soft-body of the world.
// Strain beyond which a constraint is re-solved after the contacts of every substep.
// Default: 0.75
r3SoftBodiesSetResweepStrain(world, 0.75);
// Extra substeps a soft-body requests while it is hit fast; 0 disables them.
// Default: 4
r3SoftBodiesSetMaxExtraSubsteps(world, 4);
// Stiffening of the soft-body contacts relative to the rigid ones.
// Default: 4.0
r3SoftBodiesSetContactStiffening(world, 4.0);
// The tangle detection and recovery stack can be switched off mechanism by mechanism.
r3RecoverySetCrossingRepulsion(world, 1);
// The settings can also be read all at once (as a copy), modified, and written back.
R3IntegrationParameters params = r3IntegrationParameters(world);
params.softBodies.recovery.selfStandDown = 1;
r3SetIntegrationParameters(world, ¶ms);
The soft_bodies property of the integration parameters of the world is a live view of the settings, and so are its
recovery and fem properties: setting one of their fields changes the world directly. Assigning a whole
SoftBodiesSettings replaces them all, and their copy method gives a detached copy, e.g., to keep them aside before
an experiment:
# Settings shared by every soft body of the world (a live view of the integration parameters).
settings = world.integration_parameters.soft_bodies
# Strain beyond which a constraint is re-solved after the contacts of every substep.
# Default: 0.75
settings.resweep_strain = 0.75
# Extra substeps a soft body requests while it is hit fast; 0 disables them.
# Default: 4
settings.max_extra_substeps = 4
# Stiffening of the soft-body contacts relative to the rigid ones.
# Default: 4.0
settings.contact_stiffening = 4.0
# The tangle detection and recovery stack can be switched off mechanism by mechanism.
settings.recovery.crossing_repulsion = True