pub struct XpbdSolver {
pub num_substeps: usize,
pub num_iterations: usize,
pub sleep_threshold: Real,
pub sleep_counter_max: usize,
pub sleep_state: SleepState,
/* private fields */
}Expand description
Extended Position Based Dynamics (XPBD) solver.
The solver performs the following pipeline per call to XpbdSolver::solve:
- Predict positions using semi-implicit Euler integration.
- For each sub-step, project all constraints.
- Update velocities from corrected positions.
- Apply velocity damping.
Fields§
§num_substeps: usizeNumber of sub-steps per solver call.
num_iterations: usizeNumber of constraint-projection iterations per sub-step.
sleep_threshold: RealVelocity magnitude threshold below which a body is considered asleep.
sleep_counter_max: usizeNumber of consecutive solver calls all particles must be below the
sleep threshold before the body transitions to SleepState::Asleep.
sleep_state: SleepStateCurrent sleep state.
Implementations§
Source§impl XpbdSolver
impl XpbdSolver
Sourcepub fn new(num_substeps: usize) -> Self
pub fn new(num_substeps: usize) -> Self
Create a new XPBD solver with the given number of sub-steps.
Sourcepub fn with_iterations(num_substeps: usize, num_iterations: usize) -> Self
pub fn with_iterations(num_substeps: usize, num_iterations: usize) -> Self
Create a solver with explicit sub-step and iteration counts.
Sourcepub fn cfl_timestep(
body: &SoftBody,
dt_max: Real,
max_displacement: Real,
) -> Real
pub fn cfl_timestep( body: &SoftBody, dt_max: Real, max_displacement: Real, ) -> Real
Compute an adaptive CFL time-step given the current body state.
Returns the largest dt such that no particle moves more than
max_displacement in one sub-step.
If all particles are static or have zero velocity, returns dt_max.
Sourcepub fn solve(
&mut self,
body: &mut SoftBody,
constraints: &mut [Box<dyn SoftConstraint>],
dt: Real,
)
pub fn solve( &mut self, body: &mut SoftBody, constraints: &mut [Box<dyn SoftConstraint>], dt: Real, )
Run one full solve step over body with the given constraints.
Sourcepub fn integrate_positions(&self, body: &mut SoftBody, dt: Real)
pub fn integrate_positions(&self, body: &mut SoftBody, dt: Real)
Integrate particle positions forward by dt without constraint projection.
Useful when you want to call the integration and projection phases separately (e.g. from a higher-level PBD loop).
Sourcepub fn integrate_velocities(&self, body: &mut SoftBody, dt: Real)
pub fn integrate_velocities(&self, body: &mut SoftBody, dt: Real)
Update particle velocities from the displacement since the last
integrate_positions call (i.e. from prev_position).
Call this after all constraint projections for a sub-step.
Sourcepub fn apply_damping(&self, body: &mut SoftBody)
pub fn apply_damping(&self, body: &mut SoftBody)
Apply velocity damping to all dynamic particles.
Sourcepub fn kinetic_energy(body: &SoftBody) -> Real
pub fn kinetic_energy(body: &SoftBody) -> Real
Compute total kinetic energy of the body (½ Σ mᵢ |vᵢ|²).
Sourcepub fn max_displacement(body: &SoftBody) -> Real
pub fn max_displacement(body: &SoftBody) -> Real
Compute the maximum particle displacement in the last sub-step.
Useful for adaptive iteration count decisions.
Trait Implementations§
Source§impl Clone for XpbdSolver
impl Clone for XpbdSolver
Source§fn clone(&self) -> XpbdSolver
fn clone(&self) -> XpbdSolver
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for XpbdSolver
impl Debug for XpbdSolver
Auto Trait Implementations§
impl Freeze for XpbdSolver
impl RefUnwindSafe for XpbdSolver
impl Send for XpbdSolver
impl Sync for XpbdSolver
impl Unpin for XpbdSolver
impl UnsafeUnpin for XpbdSolver
impl UnwindSafe for XpbdSolver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.