Mass-Spring System#
In this section, we first revisit the problem formulation of clothing dynamics and then introduce how XRTailor integrates it.
Symbols#
\(\nabla X\): Gradient of \(X\)
\(\dot{X}\): First derivative of \(X\)
\(\ddot{X}\): Second derivative of \(X\)
Background#
Mass-Spring System#
The cloth is usually considered as a mass-spring system. An ideal spring satisfies Hooke’s law: the spring force tries to restore the rest length.
Simple Spring
The system has the following energy potential:
The force is evaluated by the negative gradient of the energy:
Explicit Integration#
Physics-based simulation integrate the system evolving in time according to Newton’s laws of motion.
Explicit Integration
The simplest way to integrate clothing dynamics is Explicit Euler integration:
Compute internal and external forces:
Update velocities using forces:
Update positions using velocities:
This method is easy to implement, but it suffers from the overshooting problem when a large time step is selected. Using a small time step increases the computational burden. Hence, explicit integration is usually not a practical choice for clothing dynamics.
Implicit Integration#
Due to the limitations of explicit integration, implicit Euler integration is proposed. The method reformulates the system as an optimization problem, which is a more robust alternative and produces accurate and realistic clothing mechanics.
Problem Formulation#
Implicit integration integrates both \(x\) and \(v\) implicitly:
Unlike explicit integration, which evaluates forces using the current step \(f^{n}\), implicit integration evaluates forces using the next step \(f^{n+1}\). Therefore, we cannot get an analytical solution for equations (6, 7).
Assuming that \(f\) is holonomic, i.e., depending on \(x\) only, the question is how to solve the following equation:
which is equivalent to the following non-linear optimization problem:
Proof.
which is the same as equation (7).
Newton’s Solve#
The Newton-Raphson method, commonly known as Newton’s method, solves the optimization problem \(x^* = argmin F(x)\) where \(F(x)\) is Lipschitz continuous. The problem is equivalent to finding the root of \(F^{'}(x) = 0\). Given a current \(x^{k}\), we approximate our goal by:
Then, we employ Newton’s method to iteratively solve for \(x^*\) such that \(F'(x^*)=0\):
Newton's Solve
Specifically, we have the first and second derivatives of \(F(x)\):
The algorithm comes to:
Newton's Method for Implicit Integration
Solving such a large, sparse, non-linear system is complex and computationally expensive since we need to evaluate \(H(x^{n})\) in equation (12), which is called the Hessian. Therefore, implicit integration is rarely used in real-time applications.
Position-Based Dynamics#
Methodology#
The position-based approach directly modifies vertex positions instead of evaluating forces. Hence, it does not need to solve for the Hessian. We first revisit the problem from the energy potential and Newton’s equations of motion. Then we introduce how the position-based approach works.
The system has an energy potential \(U(x)\), where \(x=[x_1, x_2, ..., x_n]^T\) represents the system state using vertex coordinates. The elastic energy potential \(U\) is:
where \(k\) is the spring constant representing stiffness; \(\Delta x\) represents the extension, i.e., how far the vertex moves beyond the rest position. For a single constraint \(C_1\), its potential energy has the following form:
For a system with \(m\) constraints, it can be written in matrix form:
where \(C(x) = [C_{1}(x), ..., C_{m}(x)]^T\) is the constraint column vector; \(\alpha\) is a block diagonal compliance matrix corresponding to the inverse of stiffness \(k_1, ..., k_m\).
According to Newton’s equations of motion:
Substituting equation (15) into (16), we have:
in which \(M\) is a diagonal mass matrix of cloth vertices.
We use the implicit Euler method to perform time discretization on equation (17):
where \(\alpha\) is a block diagonal matrix representing inverse stiffness. For more details, please refer to Appendix: Implicit Euler Time Discretization. The equation can be simplified as:
where \(n\) represents the iteration count; \(\tilde{x} = 2 x^n - x^{n-1} = x^n + v^n \Delta t\) is the predicted position. The elastic force \(f_{elastic}\) is evaluated by the gradient of the energy potential \(U(x)\):
XPBD converts it into a constrained problem by introducing a Lagrange multiplier:
where \(\lambda_{elastic} = [\lambda_{1}, ..., \lambda_{m}]^{T}\) represents the vector of constraint multipliers; \(\tilde{\alpha} = \frac{\alpha}{\Delta{t}^{2}}\) is the compliance matrix.
Substituting \(\lambda\) into equation (19, 20), we have the discrete constrained equations of motion and label them as \(g\) and \(h\), respectively:
Our goal is to find \(x\) and \(\lambda\) that satisfy:
Linearizing equations (23), we obtain the following linear Newton subproblem. Notice that we omit the superscript \((n+1)\) that represents the time step; to emphasize per-iteration unknowns we use the subscript \((i)\). For more information on the linearization, please refer to Appendix: Linearization of g and h. The linearized equation becomes:
where \(K = \frac{\partial g}{\partial x}\) is related to the second derivative of energy, i.e., it has a Hessian term as in equation (12). The system can be solved for \(\Delta x\) and the multiplier \(\Delta \lambda\) accordingly:
This iteratively updates \(x\) and \(\lambda\) that satisfy equation (23). However, as mentioned before, the evaluation of the Hessian is too expensive, and the system needs a line search algorithm to be robust. Therefore, XPBD makes two approximations to simplify the problem:
\(K \approx M\), thus omitting geometric stiffness and Hessian terms. This approximation slows down the local convergence rate but does not change the global error.
\(g(x_i, \lambda_i)=0\), which is trivially true for the first Newton iteration when initialized with \(x_0 = \tilde x\) and \(\lambda_0 = 0\).
The simplified problem is given by:
The problem can be written as a reduced system using a partition matrix (see Appendix: Reduced System via Partition Matrix) or the Schur complement:
The positional update is given by:
Regarding the update for the Lagrange multiplier, if we take a single constraint with index \(j\), \(\Delta \lambda_{j}\) is given by:
If we set \(\alpha_j = 0\), it degenerates to the scaling factor \(s\) in classic PBD:
and the \(\Delta x\) comes to:
Step Integration#
In the PBD method, the cloth stiffness is related to the time step size and iteration count, which has limited use. We employed the XPBD scheme to update vertex positions in XRTailor. The overall algorithm that integrates clothing dynamics is:
XRTailor Simulation Loop
We incorporated the small-steps[3] technique to speed up the descent. We found that although using a large step size reduces stretchiness and achieves higher material stiffness, jittering or artifacts may occur during simulation. Hence, the step size is set to 1 in Quality Mode for stability and > 1 in Swift Mode for efficiency.
Appendix#
Implicit Euler Time Discretization#
We have Newton’s equation in continuous form in equation (17):
where \(\ddot{x}\) represents acceleration and can be represented as the second derivative of \(x\) by time \(t\):
Assume that \(x(t)\) is a function of time \(t\); our goal is to estimate the value of \(x\) at time \(t^{n+1}\). We first linearize \(x(t)\) using a Taylor expansion:
Substituting \(t = t^n + \Delta t\), we have the discretized representation at \(x(t^n + \Delta t)\):
Similarly, substituting \(t = t^n - \Delta t\), we have \(x(t^n - \Delta t)\):
We denote \(x(t^n - \Delta t), x(t^n), x(t^n + \Delta t)\) as \(x^{n-1}, x^n, x^{n+1}\) in the discretized representation; equations (35, 36) can be reformulated as:
Adding the two equations in (37), we have:
Linearization of g and h#
For an arbitrary non-linear equation \(F(z) = 0\) where \(z\) represents an unknown vector, it can be linearized using a Taylor expansion:
Substituting \(z = z^i + \Delta z\),
Specifically, we have \(F\) and \(z\) in XPBD:
Linearize the equations at the current iteration step \((x_i, \lambda_{i})\):
which is equivalent to:
Reduced System via Partition Matrix#
The simplified problem is given by:
In partition matrix form:
From the top equation, since the mass matrix \(M\) can be inverted, we can obtain \(\Delta x\):
Substituting \(\Delta x\) and \(h(x_i, \lambda_i)\) into the bottom equation, we get:
References#
[1]: https://games-cn.org/games103/
[2]: Macklin M, Müller M, Chentanez N. XPBD: position-based simulation of compliant constrained dynamics[C]//Proceedings of the 9th International Conference on Motion in Games. 2016: 49-54.
[3]: Macklin M, Storey K, Lu M, et al. Small steps in physics simulation[C]//Proceedings of the 18th Annual ACM SIGGRAPH/Eurographics Symposium on Computer Animation. 2019: 1-7.