|
| 1 | +use crate::math::Real; |
| 2 | +use bevy::reflect::reflect_remote; |
| 3 | +use rapier::dynamics::IntegrationParameters; |
| 4 | +use std::num::NonZeroUsize; |
| 5 | + |
| 6 | +#[reflect_remote(IntegrationParameters)] |
| 7 | +#[derive(Copy, Clone, Debug, PartialEq)] |
| 8 | +/// Parameters for a time-step of the physics engine. |
| 9 | +pub struct IntegrationParametersWrapper { |
| 10 | + /// The timestep length (default: `1.0 / 60.0`). |
| 11 | + pub dt: Real, |
| 12 | + /// Minimum timestep size when using CCD with multiple substeps (default: `1.0 / 60.0 / 100.0`). |
| 13 | + /// |
| 14 | + /// When CCD with multiple substeps is enabled, the timestep is subdivided |
| 15 | + /// into smaller pieces. This timestep subdivision won't generate timestep |
| 16 | + /// lengths smaller than `min_ccd_dt`. |
| 17 | + /// |
| 18 | + /// Setting this to a large value will reduce the opportunity to performing |
| 19 | + /// CCD substepping, resulting in potentially more time dropped by the |
| 20 | + /// motion-clamping mechanism. Setting this to an very small value may lead |
| 21 | + /// to numerical instabilities. |
| 22 | + pub min_ccd_dt: Real, |
| 23 | + |
| 24 | + /// > 0: the damping ratio used by the springs for contact constraint stabilization. |
| 25 | + /// |
| 26 | + /// Larger values make the constraints more compliant (allowing more visible |
| 27 | + /// penetrations before stabilization). |
| 28 | + /// (default `5.0`). |
| 29 | + pub contact_damping_ratio: Real, |
| 30 | + |
| 31 | + /// > 0: the natural frequency used by the springs for contact constraint regularization. |
| 32 | + /// |
| 33 | + /// Increasing this value will make it so that penetrations get fixed more quickly at the |
| 34 | + /// expense of potential jitter effects due to overshooting. In order to make the simulation |
| 35 | + /// look stiffer, it is recommended to increase the [`Self::contact_damping_ratio`] instead of this |
| 36 | + /// value. |
| 37 | + /// (default: `30.0`). |
| 38 | + pub contact_natural_frequency: Real, |
| 39 | + |
| 40 | + /// > 0: the natural frequency used by the springs for joint constraint regularization. |
| 41 | + /// |
| 42 | + /// Increasing this value will make it so that penetrations get fixed more quickly. |
| 43 | + /// (default: `1.0e6`). |
| 44 | + pub joint_natural_frequency: Real, |
| 45 | + |
| 46 | + /// The fraction of critical damping applied to the joint for constraints regularization. |
| 47 | + /// |
| 48 | + /// Larger values make the constraints more compliant (allowing more joint |
| 49 | + /// drift before stabilization). |
| 50 | + /// (default `1.0`). |
| 51 | + pub joint_damping_ratio: Real, |
| 52 | + |
| 53 | + /// The coefficient in `[0, 1]` applied to warmstart impulses, i.e., impulses that are used as the |
| 54 | + /// initial solution (instead of 0) at the next simulation step. |
| 55 | + /// |
| 56 | + /// This should generally be set to 1. |
| 57 | + /// |
| 58 | + /// (default `1.0`). |
| 59 | + pub warmstart_coefficient: Real, |
| 60 | + |
| 61 | + /// The approximate size of most dynamic objects in the scene. |
| 62 | + /// |
| 63 | + /// This value is used internally to estimate some length-based tolerance. In particular, the |
| 64 | + /// values [`IntegrationParameters::allowed_linear_error`], |
| 65 | + /// [`IntegrationParameters::max_corrective_velocity`], |
| 66 | + /// [`IntegrationParameters::prediction_distance`], [`RigidBodyActivation::normalized_linear_threshold`] |
| 67 | + /// are scaled by this value implicitly. |
| 68 | + /// |
| 69 | + /// This value can be understood as the number of units-per-meter in your physical world compared |
| 70 | + /// to a human-sized world in meter. For example, in a 2d game, if your typical object size is 100 |
| 71 | + /// pixels, set the [`Self::length_unit`] parameter to 100.0. The physics engine will interpret |
| 72 | + /// it as if 100 pixels is equivalent to 1 meter in its various internal threshold. |
| 73 | + /// (default `1.0`). |
| 74 | + pub length_unit: Real, |
| 75 | + |
| 76 | + /// Amount of penetration the engine won’t attempt to correct (default: `0.001m`). |
| 77 | + /// |
| 78 | + /// This value is implicitly scaled by [`IntegrationParameters::length_unit`]. |
| 79 | + pub normalized_allowed_linear_error: Real, |
| 80 | + /// Maximum amount of penetration the solver will attempt to resolve in one timestep (default: `10.0`). |
| 81 | + /// |
| 82 | + /// This value is implicitly scaled by [`IntegrationParameters::length_unit`]. |
| 83 | + pub normalized_max_corrective_velocity: Real, |
| 84 | + /// The maximal distance separating two objects that will generate predictive contacts (default: `0.002m`). |
| 85 | + /// |
| 86 | + /// This value is implicitly scaled by [`IntegrationParameters::length_unit`]. |
| 87 | + pub normalized_prediction_distance: Real, |
| 88 | + /// The number of solver iterations run by the constraints solver for calculating forces (default: `4`). |
| 89 | + pub num_solver_iterations: NonZeroUsize, |
| 90 | + /// Number of addition friction resolution iteration run during the last solver sub-step (default: `0`). |
| 91 | + pub num_additional_friction_iterations: usize, |
| 92 | + /// Number of internal Project Gauss Seidel (PGS) iterations run at each solver iteration (default: `1`). |
| 93 | + pub num_internal_pgs_iterations: usize, |
| 94 | + /// The number of stabilization iterations run at each solver iterations (default: `2`). |
| 95 | + pub num_internal_stabilization_iterations: usize, |
| 96 | + /// Minimum number of dynamic bodies in each active island (default: `128`). |
| 97 | + pub min_island_size: usize, |
| 98 | + /// Maximum number of substeps performed by the solver (default: `1`). |
| 99 | + pub max_ccd_substeps: usize, |
| 100 | +} |
0 commit comments