11use crate :: math:: Real ;
22use bevy:: reflect:: reflect_remote;
3+ use rapier:: { dynamics:: IntegrationParameters , prelude:: SpringCoefficients } ;
4+
35#[ cfg( feature = "dim3" ) ]
46use rapier:: dynamics:: FrictionModel ;
5- use rapier:: dynamics:: IntegrationParameters ;
67
78/// Friction models used for all contact constraints between two rigid-bodies.
89///
@@ -27,6 +28,21 @@ pub enum FrictionModelWrapper {
2728 Coulomb ,
2829}
2930
31+ #[ reflect_remote( SpringCoefficients <Real >) ]
32+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
33+ /// Coefficients for a spring, typically used for configuring constraint softness for contacts and
34+ /// joints.
35+ pub struct SpringCoefficientsWrapper {
36+ /// Sets the natural frequency (Hz) of the spring-like constraint.
37+ ///
38+ /// Higher values make the constraint stiffer and resolve constraint violations more quickly.
39+ pub natural_frequency : Real ,
40+ /// Sets the damping ratio for the spring-like constraint.
41+ ///
42+ /// Larger values make the joint more compliant (allowing more drift before stabilization).
43+ pub damping_ratio : Real ,
44+ }
45+
3046#[ cfg( not( feature = "dim3" ) ) ]
3147#[ reflect_remote( IntegrationParameters ) ]
3248#[ derive( Copy , Clone , Debug , PartialEq ) ]
@@ -46,34 +62,9 @@ pub struct IntegrationParametersWrapper {
4662 /// to numerical instabilities.
4763 pub min_ccd_dt : Real ,
4864
49- /// > 0: the damping ratio used by the springs for contact constraint stabilization.
50- ///
51- /// Larger values make the constraints more compliant (allowing more visible
52- /// penetrations before stabilization).
53- /// (default `5.0`).
54- pub contact_damping_ratio : Real ,
55-
56- /// > 0: the natural frequency used by the springs for contact constraint regularization.
57- ///
58- /// Increasing this value will make it so that penetrations get fixed more quickly at the
59- /// expense of potential jitter effects due to overshooting. In order to make the simulation
60- /// look stiffer, it is recommended to increase the [`Self::contact_damping_ratio`] instead of this
61- /// value.
62- /// (default: `30.0`).
63- pub contact_natural_frequency : Real ,
64-
65- /// > 0: the natural frequency used by the springs for joint constraint regularization.
66- ///
67- /// Increasing this value will make it so that penetrations get fixed more quickly.
68- /// (default: `1.0e6`).
69- pub joint_natural_frequency : Real ,
70-
71- /// The fraction of critical damping applied to the joint for constraints regularization.
72- ///
73- /// Larger values make the constraints more compliant (allowing more joint
74- /// drift before stabilization).
75- /// (default `1.0`).
76- pub joint_damping_ratio : Real ,
65+ /// Softness coefficients for contact constraints.
66+ #[ reflect( remote = SpringCoefficientsWrapper ) ]
67+ pub contact_softness : SpringCoefficients < Real > ,
7768
7869 /// The coefficient in `[0, 1]` applied to warmstart impulses, i.e., impulses that are used as the
7970 /// initial solution (instead of 0) at the next simulation step.
@@ -114,7 +105,7 @@ pub struct IntegrationParametersWrapper {
114105 pub num_solver_iterations : usize ,
115106 /// Number of internal Project Gauss Seidel (PGS) iterations run at each solver iteration (default: `1`).
116107 pub num_internal_pgs_iterations : usize ,
117- /// The number of stabilization iterations run at each solver iterations (default: `2 `).
108+ /// The number of stabilization iterations run at each solver iterations (default: `1 `).
118109 pub num_internal_stabilization_iterations : usize ,
119110 /// Minimum number of dynamic bodies in each active island (default: `128`).
120111 pub min_island_size : usize ,
@@ -142,34 +133,9 @@ pub struct IntegrationParametersWrapper {
142133 /// to numerical instabilities.
143134 pub min_ccd_dt : Real ,
144135
145- /// > 0: the damping ratio used by the springs for contact constraint stabilization.
146- ///
147- /// Larger values make the constraints more compliant (allowing more visible
148- /// penetrations before stabilization).
149- /// (default `5.0`).
150- pub contact_damping_ratio : Real ,
151-
152- /// > 0: the natural frequency used by the springs for contact constraint regularization.
153- ///
154- /// Increasing this value will make it so that penetrations get fixed more quickly at the
155- /// expense of potential jitter effects due to overshooting. In order to make the simulation
156- /// look stiffer, it is recommended to increase the [`Self::contact_damping_ratio`] instead of this
157- /// value.
158- /// (default: `30.0`).
159- pub contact_natural_frequency : Real ,
160-
161- /// > 0: the natural frequency used by the springs for joint constraint regularization.
162- ///
163- /// Increasing this value will make it so that penetrations get fixed more quickly.
164- /// (default: `1.0e6`).
165- pub joint_natural_frequency : Real ,
166-
167- /// The fraction of critical damping applied to the joint for constraints regularization.
168- ///
169- /// Larger values make the constraints more compliant (allowing more joint
170- /// drift before stabilization).
171- /// (default `1.0`).
172- pub joint_damping_ratio : Real ,
136+ /// Softness coefficients for contact constraints.
137+ #[ reflect( remote = SpringCoefficientsWrapper ) ]
138+ pub contact_softness : SpringCoefficients < Real > ,
173139
174140 /// The coefficient in `[0, 1]` applied to warmstart impulses, i.e., impulses that are used as the
175141 /// initial solution (instead of 0) at the next simulation step.
@@ -210,7 +176,7 @@ pub struct IntegrationParametersWrapper {
210176 pub num_solver_iterations : usize ,
211177 /// Number of internal Project Gauss Seidel (PGS) iterations run at each solver iteration (default: `1`).
212178 pub num_internal_pgs_iterations : usize ,
213- /// The number of stabilization iterations run at each solver iterations (default: `2 `).
179+ /// The number of stabilization iterations run at each solver iterations (default: `1 `).
214180 pub num_internal_stabilization_iterations : usize ,
215181 /// Minimum number of dynamic bodies in each active island (default: `128`).
216182 pub min_island_size : usize ,
0 commit comments