newton.solvers.SolverStyle3D#
- class newton.solvers.SolverStyle3D(model, *, config=None, iterations=_LEGACY_UNSET, linear_iterations=_LEGACY_UNSET, drag_spring_stiff=_LEGACY_UNSET, enable_mouse_dragging=_LEGACY_UNSET)[source]#
Bases:
SolverBaseProjective dynamics based cloth solver.
References
Baraff, D. & Witkin, A. “Large Steps in Cloth Simulation.”
Liu, T. et al. “Fast Simulation of Mass-Spring Systems.”
Implicit-Euler method solves the following non-linear equation:
\[\begin{split}(M / dt^2 + H(x)) \cdot dx &= (M / dt^2) \cdot (x_{prev} + v_{prev} \cdot dt - x) + f_{ext}(x) + f_{int}(x) \\ &= (M / dt^2) \cdot (x_{prev} + v_{prev} \cdot dt + (dt^2 / M) \cdot f_{ext}(x) - x) + f_{int}(x) \\ &= (M / dt^2) \cdot (x_{inertia} - x) + f_{int}(x)\end{split}\]- Notations:
\(M\): mass matrix
\(x\): unsolved particle position
\(H\): Hessian matrix (function of x)
\(P\): PD-approximated Hessian matrix (constant)
\(A\): \(M / dt^2 + H(x)\) or \(M / dt^2 + P\)
\(rhs\): Right hand side of the equation: \((M / dt^2) \cdot (x_{inertia} - x) + f_{int}(x)\)
\(res\): Residual: \(rhs - A \cdot dx_{init}\), or rhs if \(dx_{init} = 0\)
See also
newton.solvers.style3d exposes helper functions that populate Style3D cloth data on a
ModelBuilder.Example
Build a mesh-based cloth with
newton.solvers.style3d.add_cloth_mesh():from newton.solvers import style3d builder = newton.ModelBuilder() SolverStyle3D.register_custom_attributes(builder) style3d.add_cloth_mesh( builder, pos=wp.vec3(0.0, 0.0, 0.0), rot=wp.quat_identity(), vel=wp.vec3(0.0, 0.0, 0.0), vertices=mesh.vertices.tolist(), indices=mesh.indices.tolist(), density=0.3, tri_aniso_ke=wp.vec3(1.0e2, 1.0e2, 1.0e1), edge_aniso_ke=wp.vec3(2.0e-5, 1.0e-5, 5.0e-6), )
Or build a grid with
newton.solvers.style3d.add_cloth_grid():style3d.add_cloth_grid( builder, pos=wp.vec3(-0.5, 0.0, 2.0), rot=wp.quat_identity(), dim_x=64, dim_y=32, cell_x=0.1, cell_y=0.1, vel=wp.vec3(0.0, 0.0, 0.0), mass=0.1, tri_aniso_ke=wp.vec3(1.0e2, 1.0e2, 1.0e1), edge_aniso_ke=wp.vec3(2.0e-4, 1.0e-4, 5.0e-5), )
- class Config(*, iterations=10, linear_iterations=10, drag_spring_stiff=100.0, enable_mouse_dragging=False)#
Bases:
objectRuntime options for
SolverStyle3D.The solver keeps the supplied object as
SolverStyle3D.config. Changes made before a subsequentSolverStyle3D.step()take effect on that step. Captured CUDA graphs must be recaptured to use updated configuration values.Example
Configure a solver for an existing model:
config = SolverStyle3D.Config(iterations=20, linear_iterations=10) solver = SolverStyle3D(model, config=config) solver.config.iterations = 30
- __init__(*, iterations=10, linear_iterations=10, drag_spring_stiff=100.0, enable_mouse_dragging=False)#
- classmethod register_custom_attributes(builder)#
Declare Style3D custom attributes under the
style3dnamespace.See also
Custom Attributes for the custom attribute system overview.
- __init__(model, *, config=None, iterations=_LEGACY_UNSET, linear_iterations=_LEGACY_UNSET, drag_spring_stiff=_LEGACY_UNSET, enable_mouse_dragging=_LEGACY_UNSET)#
Initialize the Style3D solver.
Deprecated since version 1.8: The
iterations,linear_iterations,drag_spring_stiff, andenable_mouse_draggingkeyword arguments are deprecated. Pass their values throughconfig=SolverStyle3D.Config(...)instead.- Parameters:
model (Model) – The
Modelcontaining Style3D attributes to integrate.config (Config | None) – Runtime options. If
None, useConfigdefaults with any supplied legacy keyword options. The solver keeps this object publicly asconfig; changes take effect on the next step. An explicit configuration cannot be combined with legacy options.iterations (int) – Deprecated keyword option for
Config.iterations.linear_iterations (int) – Deprecated keyword option for
Config.linear_iterations.drag_spring_stiff (float) – Deprecated keyword option for
Config.drag_spring_stiff.enable_mouse_dragging (bool) – Deprecated keyword option for
Config.enable_mouse_dragging.
- Raises:
TypeError – If
configis not aConfigorNone, or if a configuration is combined with legacy keyword options.
- step(state_in, state_out, control, contacts, dt, *, observables=None)#
Advance the Style3D solver by one time step.
The solver performs non-linear projective dynamics iterations with optional collision handling. During the solve, positions in
state_inare updated in-place to the current iterate; the final positions and velocities are written tostate_out.- Parameters:
state_in (newton.State) – Input
newton.State(positions updated in-place).state_out (newton.State) – Output
newton.Statewith the final state.control (Control) –
newton.Controlinput (currently unused).contacts (Contacts) –
newton.Contactsused for collision response.dt (float) – Time step in seconds.
observables (Observables | None) – Optional solver observable arrays allocated by
observables(). This solver declares no supported observables, so only an empty container is accepted.
- Raises:
ValueError – If
Config.iterationsis less than 1. Neither input nor output state is modified in this case.
- config: Config#
Live solver options, retained by reference when supplied at construction.
Edit fields or replace this object with a
Configbetween calls tostep(). Captured CUDA graphs must be recaptured after changes.
- property drag_spring_stiff: float#
Legacy alias for
Config.drag_spring_stiff.Deprecated since version 1.8: Use
solver.config.drag_spring_stiffinstead.
- property enable_mouse_dragging: bool#
Legacy alias for
Config.enable_mouse_dragging.Deprecated since version 1.8: Use
solver.config.enable_mouse_dragginginstead.
- property linear_iterations: int#
Legacy alias for
Config.linear_iterations.Deprecated since version 1.8: Use
solver.config.linear_iterationsinstead.
- property nonlinear_iterations: int#
Legacy alias for
Config.iterations.Deprecated since version 1.8: Use
solver.config.iterationsinstead.