Commit Graph

46603 Commits

Author SHA1 Message Date
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
da01c884e5 Cleanup, removed unused old code. 2015-01-20 09:29:59 +01:00
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
e55d11478d Added back external effector forces for the cloth solver. 2015-01-20 09:29:59 +01:00
ace1b5050b Reenabled goal springs and removed the arbitrary structural scaling
factor.
2015-01-20 09:29:59 +01:00
c7932e93fa Fixed bending forces for cloth springs. 2015-01-20 09:29:58 +01:00
6d4c704f17 Correctly implemented and verified gravity, drag, structural springs. 2015-01-20 09:29:58 +01:00
f336ca5952 Minor fix in debug print, so solver prints can be diff'ed. 2015-01-20 09:29:58 +01:00
b241f23b19 A couple of defines to disable various influences on the cloth sim for
debugging.
2015-01-20 09:29:58 +01:00
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
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
7896827f75 Reenabled air drag force for cloth sim. 2015-01-20 09:29:58 +01:00
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
8163fca264 Switched to the modified CG method that supports constraints, and
added back structural stretch springs.
2015-01-20 09:29:58 +01:00
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
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
d2c0503f19 To make gravity a true force vector, multiply by the mass. 2015-01-20 09:29:58 +01:00
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
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
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
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
4bfd3c8f0c Fix for collision response, the impulse response was far too small. 2015-01-20 09:29:57 +01:00
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
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
93194eb0e9 Fixed for hair collision detection, old/new positions were swapped. 2015-01-20 09:29:57 +01:00
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
b8a9579954 Removed own debug print. 2015-01-20 09:29:57 +01:00
ae162f61e7 Added a comment and use the new CG solver as the "official" version now. 2015-01-20 09:29:57 +01:00
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
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
fc083b4e5b Preparation for collision code fixing.
Instead of handling contact tests and collision response in the same
function in collision.c, first generate contact points and return them
as a list, then free at the end of the stepping function. This way the
contact response can be integrated into the conjugate gradient method
properly instead of using the hackish and unstable double evaluation
that is currently used.
2015-01-20 09:29:57 +01:00
0f45f4a3e2 Cleanup: added some comments to the members of Implicit_Data. 2015-01-20 09:29:57 +01:00
c6db1d0858 Cleanup: No point in passing all the implicit solver arguments
individually.
2015-01-20 09:29:56 +01:00
e9849bdf17 Cleanup: removed the unused olddV vectors from implicit solver data. 2015-01-20 09:29:56 +01:00
ccad968e26 Some more debug elements for hair collisions. 2015-01-20 09:29:56 +01:00
f98d388fd3 Extended line/face collision near-check, to allow for distance margins.
The original BLI method for line/triangle intersection returns false
in case the line does not actually intersect, but in order to generate
repulsion forces we need to also handle contacts inside the margin.
2015-01-20 09:29:56 +01:00
dbf7840643 Fix bounce/repulse calculation. 2015-01-20 09:29:56 +01:00
d43f760892 Hair debugging: use "categories" (strings) for grouping debug elements
and support clearing for categories.
2015-01-20 09:29:56 +01:00
70df8f8dd6 Fix for hair collision detection: need to use the second point of the
timestep segment.

This ensures the distance for a collision pair is the one of the current
point position, and the response gets calculated accordingly.
2015-01-20 09:29:56 +01:00
a580be6399 Use repulsion forces in combination with the one-time penalty forces
in collision.
2015-01-20 09:29:56 +01:00
67fdd5e01a Fix for crash when going into particle edit mode with baked hair
simulation.

Note that this currently generates an extreme amount of points, by
making a edit pathcache curve for each hair in every frame! But at least
doesn't simply crash now.
2015-01-20 09:29:56 +01:00
f757364fc0 Clear debug_data pointer in local cloth modifier data of the particle
systems on blend file load.
2015-01-20 09:29:56 +01:00
1ed88bb24e Partial response force for hair collisions.
This implements a penalty force as well as a repulsion force to avoid
further penetration, as suggested in
"Simulating Complex Hair with Robust Collision Handling"
(http://graphics.snu.ac.kr/publications/2005-choe-HairSim/Choe_2005_SCA.pdf)

Friction forces are still missing. More problematic is handling of
moving colliders, when face swap places with the hair vertex and a
collision is missed, putting the vertex inside the mesh volume. Larger
margins might help, but ultimately using Bullet collision detection is
probably more reliable and failsafe.
2015-01-20 09:29:56 +01:00
d8cf12fe5a Debug drawing for simulations, to aid in visualizing abstract data such
as forces, velocities, contact points etc.

This uses a hash table to store debug elements (dots, lines, vectors at
this point). The hash table allows continuous display of elements that
are generated only in certain time steps, e.g. contact points, while
avoiding massive memory allocation. In any case, this system is really
a development feature, but very helpful in finding issues with the
internal solver data.
2015-01-20 09:29:56 +01:00
5a43e8493e Some initial collision code, without actual response forces still.
This is still using the old BVH tree collision methods to generate
contact points, similar to what cloth does. This should be replaced
by a Bullet collision check, but generating contacts in this way is
easier for now, and lets us test responses and stability (although in
more complex collision cases the BVH method fails utterly, beside being
terribly inefficient with many colliders).
2015-01-20 09:29:21 +01:00
ba8b8ec998 Implemented internal hair pressure to prevent hair from collapsing in
on itself.

This uses the same voxel structure as the hair smoothing algorithm.
A slightly different method was suggested in the original paper
(Volumetric Methods for Simulation and Rendering of Hair), but this is
based on directing hair based on a target density, which is another
way of implementing global goals. Our own approach is to define a
pressure threshold above which the hair is repelled in the density
gradient direction to simulate internal pressure from collisions.
2015-01-20 09:29:21 +01:00
345c7b144d Fixed hair velocity smoothing.
This is an important hair interaction feature that simulates friction
between hairs in an efficient way. The method is based on the paper
"Volumetric Methods for Simulation and Rendering of Hair"
( http://graphics.pixar.com/library/Hair/paper.pdf )

It was partially implemented already, but didn't work in this simplified
version. The same voxel structure can be used for implemeting repelling
forces on hair based on density, which can help a hair system maintain
volume instead of collapsing in on itself.
2015-01-20 09:29:21 +01:00
b331a82910 Support for various data properties of the hair grid in the voxel
texture.
2015-01-20 09:29:21 +01:00
efc0cd1658 Fixed voxel grid initialization from hair points and colliders by using
the suggested tent function from the original paper.

Plain float->int conversion for the grid location otherwise leads to
skewed data and unnecessary loss of information.
2015-01-20 09:29:21 +01:00
5f41b19463 New voxel texture mode "Hair", for displaying the internal hair volume
structure as a texture.

This is mostly a debugging feature that may be removed again later.
2015-01-20 09:29:21 +01:00