Commit Graph

57368 Commits

Author SHA1 Message Date
Lukas Tönne
b9b784f039 Moved the unused goal force calculation function to the main mass-spring
source file.
2015-01-20 09:30:00 +01:00
Lukas Tönne
2901d6ab21 Moved most of the main cloth solver function out of implicit code core.
Force calculation is disabled, will follow shortly.
2015-01-20 09:30:00 +01:00
Lukas Tönne
ac071de405 Moved init/free functions for solver data out of implicit core.
This also initializes spring matrix indices (off-diagonal 3x3 blocks),
which now uses a new API function.
2015-01-20 09:30:00 +01:00
Lukas Tönne
d2e8a72d8a Moved "set_positions" for cloth out of core implicit solver.
API for the solver now has functions for setting of vertex motion state
and the associated root transform data.
2015-01-20 09:30:00 +01:00
Lukas Tönne
0d60337a83 Renamed functions to make them explicitly refer to cloth, and split the
create/free functions for solver data off from the cloth solver.
2015-01-20 09:30:00 +01:00
Lukas Tönne
5322def57c Moved the cloth solver code into a new subfolder/library inside Blender
code.

The implicit solver itself should remain agnostic to the specifics of
the Blender data (cloth vs. hair). This way we could avoid the bloated
data conversion chain from particles/hair to derived mesh to cloth
modifier to implicit solver data and back. Every step in this chain adds
overhead as well as rounding errors and a possibility for bugs, not to
speak of making the code horribly complicated.

The new subfolder is named "physics" since it should be the start of a
somewhat "unified" physics systems combining all the various solvers in
the same place and managing things like synchronized time steps.
2015-01-20 09:30:00 +01:00
Lukas Tönne
1c8a33ab92 Desperate attempt to get stable collisions: Disable restitution and
handle only one collision contact at a time.

Collision still randomly explodes, even with differing results on the
same file. This could indicate a threading issue, possibly also related
to the dependency graph since multiple objects are involved in
collisions.
2015-01-20 09:30:00 +01:00
Lukas Tönne
3007fc6eb7 Revert "Ignore velocity changes when the cloth solver does not converge."
This reverts commit c52b8ae818844965d56714a71255408873275dc1.

Sadly, at this point solver convergence is an exception rather than the
rule... Individual hairs can "explode" easily and thus disable the whole
simulation, which isn't helpful either.
2015-01-20 09:30:00 +01:00
Lukas Tönne
8532cf206e Ignore velocity changes when the cloth solver does not converge.
This helps keep the simulation stable as long as there are only a few
substeps that become too constrained for the solver.

Eventually we need better feedback about these solver results, so that
artists can tweak situations specifically to resolve bad solver results.
This is somewhat similar to the camera tracker, which also can run into
cases that cannot be resolved and have to be fixed manually.
2015-01-20 09:30:00 +01:00
Lukas Tönne
3119d718f8 Moved collision response into the main cloth sim source file and fixed
some coordinate transform issues.

Collision response should be regarded as part of the dynamics system
instead of the basic collision detection.
2015-01-20 09:30:00 +01:00
Lukas Tönne
2b06b899b0 Correction for inverse constraint matrix rotation. 2015-01-20 09:30:00 +01:00
Lukas Tönne
0f3cbf3f56 Transform the constraint matrix and target solver vector z according to
the root frame transforms as well.

This ensures the hair constraints are actually in root space and applied
correctly by the solver.
2015-01-20 09:30:00 +01:00
Lukas Tönne
bc6fa4fa11 Use identity transform in the solver data roots to avoid possible errors
when this data is used outside the transform functions.
2015-01-20 09:29:59 +01:00
Lukas Tönne
b391e963a9 Option for disabling the root frame transformation altogether, mostly
for testing.
2015-01-20 09:29:59 +01:00
Lukas Tönne
c5038b12c3 Ported root frame transformation to the old cloth solver. 2015-01-20 09:29:59 +01:00
Lukas Tönne
3ad7974373 Switched back to the old solver for the time being.
The Eigen solver is not quite stable currently (possibly due to
incorrect porting of force calculations). It also still lacks threading
support and optimized matrix construction, making it slower in
comparison. Eventually would still like to switch, but fixing these
issues takes time.
2015-01-20 09:29:59 +01:00
Lukas Tönne
9f28ced756 Implemented gradient transformation for forces in the root frame (dFdX,
dFdV).
2015-01-20 09:29:59 +01:00
Lukas Tönne
2410dc32ff Removed unused variable. 2015-01-20 09:29:59 +01:00
Lukas Tönne
55a5351a03 First stage of implementing moving frames of reference for hair/cloth.
This adds transformations for each hair from world to "root space".
Currently positions and velocities are simply transformed for the solver
data and inverse-transformed when copying the results back to the cloth
data. This way the hair movement becomes independent from the movement
of the emitter object. Eventually the "fictitious" forces originating
from emitter movement can be added back in a controlled way.

http://en.wikipedia.org/wiki/Fictitious_force

Ignoring these fictitious forces or scaling their effect is physically
correct, because in the absence of external forces the hair will always
return to rest position in this root frame.

External forces currently are not yet transformed into the root space.
2015-01-20 09:29:59 +01:00
Lukas Tönne
d496b308db Disable some debugging options in Eigen to make it more usable in Debug
mode.

Eigen can become very slow in debug mode, which is a bit of a problem.
It relies heavily on compiler optimizations to remove function calls
etc. More optimizations may be desirable, possibly putting the implicit
solver into its own little library and enabling optimizations in debug
mode there could help.
2015-01-20 09:29:59 +01:00
Lukas Tönne
d115bdb505 Added new data in the cloth modifier for hair root information.
This will allow us to implement moving reference frames for hair and
make "fictitious" forces optional, aiding in creating stable and
controllable hair systems.

Adding data in this place is a nasty hack, but it's too difficult to
encode as a DM data layer and the whole cloth modifier/DM intermediate
data copying for hair should be removed anyway.
2015-01-20 09:29:59 +01:00
Lukas Tönne
da01c884e5 Cleanup, removed unused old code. 2015-01-20 09:29:59 +01:00
Lukas Tönne
d91a4cd1a1 Optimized matrix filling using the Eigen triplets method.
Otherwise the construction of matrices becomes very slow for larger
vertex counts because adding a new element is O(n), making it O(n^2) in
total.
2015-01-20 09:29:59 +01:00
Lukas Tönne
e55d11478d Added back external effector forces for the cloth solver. 2015-01-20 09:29:59 +01:00
Lukas Tönne
ace1b5050b Reenabled goal springs and removed the arbitrary structural scaling
factor.
2015-01-20 09:29:59 +01:00
Lukas Tönne
c7932e93fa Fixed bending forces for cloth springs. 2015-01-20 09:29:58 +01:00
Lukas Tönne
6d4c704f17 Correctly implemented and verified gravity, drag, structural springs. 2015-01-20 09:29:58 +01:00
Lukas Tönne
f336ca5952 Minor fix in debug print, so solver prints can be diff'ed. 2015-01-20 09:29:58 +01:00
Lukas Tönne
b241f23b19 A couple of defines to disable various influences on the cloth sim for
debugging.
2015-01-20 09:29:58 +01:00
Lukas Tönne
1819cbd02c Debug printing code for large sparse vectors and matrices, to compare
solver input/output of the old and new methods.
2015-01-20 09:29:58 +01:00
Lukas Tönne
8283122cda Added a new internal header for implicit solver defines.
Should become its own intern wrapper library eventually.
2015-01-20 09:29:58 +01:00
Lukas Tönne
7896827f75 Reenabled air drag force for cloth sim. 2015-01-20 09:29:58 +01:00
Lukas Tönne
e0b46b136e Arbitrary scaling factor for the structural spring forces (stretching).
This is not nice at all, but for some reason (possibly time scale) the
old force values are much too high and cause the solver to become
unstable. These will be revisited later anyway, so for now such scaling
should be fine.
2015-01-20 09:29:58 +01:00
Lukas Tönne
8163fca264 Switched to the modified CG method that supports constraints, and
added back structural stretch springs.
2015-01-20 09:29:58 +01:00
Lukas Tönne
c6a65ff5b8 Implemented a modifier conjugate gradient algorithm to support stable
constraining.

The algorithm is described in the paper "Large Steps in Cloth Simulation"
(Baraff/Witkin 1998). The same method was (incorrectly) implemented in
the old cloth solver.

It is based on restricting the degrees of freedom (ndof) of vertices
using a block matrix and a vector of target velocity deltas.
See chapter 5 of the paper for details.
2015-01-20 09:29:58 +01:00
Lukas Tönne
722fd30a9f Reimplemented Goal springs for the Eigen CG solver method.
Note that goal springs currently are really bad ... They have a factor
on hairs that "fades" goal influence from the root to the tip. The last
point on the hair is completely free, which makes the goal springs
pretty much useless on their own without supporting bend stiffness.
Can only assume this was added to compensate unphysical behavior of
goal springs when using uniform weight, but it's a poor replacement for
true localized bending forces ...
2015-01-20 09:29:58 +01:00
Lukas Tönne
d2c0503f19 To make gravity a true force vector, multiply by the mass. 2015-01-20 09:29:58 +01:00
Lukas Tönne
83137358c0 Alternative new solver for cloth using the Eigen CG solver instead of
a custom built solver.

The old cloth solver is broken unfortunately. Eigen is a designated
linear algebra library and very likely their implementation is a lot
better (can't compare until it's implemented though).

Only basic gravity is active atm, spring forces, external force fields,
damping and volumetric friction have to be added back by converting
the data into the Eigen format.
2015-01-20 09:29:58 +01:00
Lukas Tönne
396f7ea158 Don't try to enforce a velocity change for pinned vertices; their
velocity is defined externally by hair root motion.
2015-01-20 09:29:58 +01:00
Lukas Tönne
d1cb8b08bd Use squareroot of the current epsilon error target for CG, since we
square this value anyway.
2015-01-20 09:29:57 +01:00
Lukas Tönne
8ec4c31d9c Disabled collision culling on the inside of the collider faces for now,
this seems to remove too many contact points somehow ...
2015-01-20 09:29:57 +01:00
Lukas Tönne
4bfd3c8f0c Fix for collision response, the impulse response was far too small. 2015-01-20 09:29:57 +01:00
Lukas Tönne
27ecda9995 Use the S matrix of the modifier CG algorithm for implementing collision
responses.

The S matrix together with the z Vector encodes the degrees of freedom
of a colliding hair point and the target velocity change. In a collision
the hair vertex is restricted in the normal direction (when moving
toward the collider) and the collision dynamics define target velocity.
2015-01-20 09:29:57 +01:00
Lukas Tönne
02ab74eb55 Better contact point near-test for hair.
This simply uses the position above the triangle instead of the
intersection point of the vertex path. The other method was broken
anyway, but also has a problem catching all the contacts reliably. The
new method might have a few false positives but that is acceptable.
2015-01-20 09:29:57 +01:00
Lukas Tönne
93194eb0e9 Fixed for hair collision detection, old/new positions were swapped. 2015-01-20 09:29:57 +01:00
Lukas Tönne
971419c27d Reduced minimum for cloth solver substeps to 1.
This is not very useful for artists, but helps with debugging.
2015-01-20 09:29:57 +01:00
Lukas Tönne
b8a9579954 Removed own debug print. 2015-01-20 09:29:57 +01:00
Lukas Tönne
ae162f61e7 Added a comment and use the new CG solver as the "official" version now. 2015-01-20 09:29:57 +01:00
Lukas Tönne
c6e5f6afe0 Fixed implementation of the Conjugate Gradient method for the cloth
solver that properly supports constraints with some degrees-of-freedom.

The previous solver implementation only used the S matrix (constraint
filter matrix) for pinning vertices, in which case all elements are
zero and the error doesn't show up. With partial constraints (useful for
collision contacts) the matrix has non-zero off-diagonal elements and
the algorithm easily diverges.

There are also initial steps for implementing collision prevention as
described in the Baraff/Witkin paper "Large Steps in Cloth Simulation"
(http://www.cs.cmu.edu/~baraff/papers/sig98.pdf).
2015-01-20 09:29:57 +01:00
Lukas Tönne
b38663338e Hair collision: Use the S matrix for enforcing contact constraints.
This is a first test, the contacts are very explosive atm because they
basically pin hair vertices globally on collision, which leads to
stretching of the springs which is then suddenly released in the next
frame.
2015-01-20 09:29:57 +01:00