Skip to main content

XpbdSolver

Struct XpbdSolver 

Source
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:

  1. Predict positions using semi-implicit Euler integration.
  2. For each sub-step, project all constraints.
  3. Update velocities from corrected positions.
  4. Apply velocity damping.

Fields§

§num_substeps: usize

Number of sub-steps per solver call.

§num_iterations: usize

Number of constraint-projection iterations per sub-step.

§sleep_threshold: Real

Velocity magnitude threshold below which a body is considered asleep.

§sleep_counter_max: usize

Number of consecutive solver calls all particles must be below the sleep threshold before the body transitions to SleepState::Asleep.

§sleep_state: SleepState

Current sleep state.

Implementations§

Source§

impl XpbdSolver

Source

pub fn new(num_substeps: usize) -> Self

Create a new XPBD solver with the given number of sub-steps.

Source

pub fn with_iterations(num_substeps: usize, num_iterations: usize) -> Self

Create a solver with explicit sub-step and iteration counts.

Source

pub fn wake(&mut self)

Wake the body up (reset sleep counter and state).

Source

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.

Source

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.

Source

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).

Source

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.

Source

pub fn apply_damping(&self, body: &mut SoftBody)

Apply velocity damping to all dynamic particles.

Source

pub fn kinetic_energy(body: &SoftBody) -> Real

Compute total kinetic energy of the body (½ Σ mᵢ |vᵢ|²).

Source

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

Source§

fn clone(&self) -> XpbdSolver

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for XpbdSolver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for XpbdSolver

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.