newton.solvers.SolverStyle3D#

class newton.solvers.SolverStyle3D(model, iterations=10, linear_iterations=10, drag_spring_stiff=1e2, enable_mouse_dragging=False)[source]#

Bases: SolverBase

Projective dynamics based cloth solver.

References

  1. Baraff, D. & Witkin, A. “Large Steps in Cloth Simulation.”

  2. 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),
)
classmethod register_custom_attributes(builder)#

Declare Style3D custom attributes under the style3d namespace.

See also

Custom Attributes for the custom attribute system overview.

__init__(model, iterations=10, linear_iterations=10, drag_spring_stiff=1e2, enable_mouse_dragging=False)#
Parameters:
  • model (Model) – The Model containing Style3D attributes to integrate.

  • iterations (int) – Number of non-linear iterations per step.

  • linear_iterations (int) – Number of linear iterations (currently PCG iter) per non-linear iteration.

  • drag_spring_stiff (float) – The stiffness of spring connecting barycentric-weighted drag-point and target-point.

  • enable_mouse_dragging (bool) – Enable/disable dragging kernel.

step(state_in, state_out, control, contacts, dt)#

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_in are updated in-place to the current iterate; the final positions and velocities are written to state_out.

Parameters:
update_drag_info(index, pos, bary_coord)#

Should be invoked when state changed.