diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2020-06-12 21:33:38 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2020-06-19 12:17:02 +0300 |
commit | 9e7012995249281b041d55607e7e7408857aa8c4 (patch) | |
tree | c798c27f235113ed4909fb6e11f68d84653ed8c6 /source/blender/blenkernel/intern/effect.c | |
parent | f382109f3885fc48d7becc526796d3324ab0aa42 (diff) |
Cloth: allow forces to act parallel to cloth.
Currently all force effectors can only act on cloth when the force is
perpendicular to the surface. This makes sense for wind, but not for
other forces; and the user may want even wind to have some friction.
This changes effector code to output two force vectors - although
you of course can pass the same pointer for both. The force is split
between the two outputs based on a new per-effector setting.
Differential Revision: https://developer.blender.org/D8017
Diffstat (limited to 'source/blender/blenkernel/intern/effect.c')
-rw-r--r-- | source/blender/blenkernel/intern/effect.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 7ed04c6976a..235c834fde9 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -108,7 +108,8 @@ PartDeflect *BKE_partdeflect_new(int type) break; case PFIELD_WIND: pd->shape = PFIELD_SHAPE_PLANE; - pd->f_flow = 1.0f; /* realistic wind behavior */ + pd->f_flow = 1.0f; /* realistic wind behavior */ + pd->f_wind_factor = 1.0f; /* only act perpendicularly to a surface */ break; case PFIELD_TEXTURE: pd->f_size = 1.0f; @@ -1072,7 +1073,8 @@ static void do_physical_effector(EffectorCache *eff, * scene = scene where it runs in, for time and stuff * lb = listbase with objects that take part in effecting * opco = global coord, as input - * force = force accumulator + * force = accumulator for force + * wind_force = accumulator for force only acting perpendicular to a surface * speed = actual current speed which can be altered * cur_time = "external" time in frames, is constant for static particles * loc_time = "local" time in frames, range <0-1> for the lifetime of particle @@ -1085,6 +1087,7 @@ void BKE_effectors_apply(ListBase *effectors, EffectorWeights *weights, EffectedPoint *point, float *force, + float *wind_force, float *impulse) { /* @@ -1120,22 +1123,27 @@ void BKE_effectors_apply(ListBase *effectors, if (efd.falloff > 0.0f) { efd.falloff *= eff_calc_visibility(colliders, eff, &efd, point); } - if (efd.falloff <= 0.0f) { - /* don't do anything */ - } - else if (eff->pd->forcefield == PFIELD_TEXTURE) { - do_texture_effector(eff, &efd, point, force); - } - else { - float temp1[3] = {0, 0, 0}, temp2[3]; - copy_v3_v3(temp1, force); + if (efd.falloff > 0.0f) { + float out_force[3] = {0, 0, 0}; - do_physical_effector(eff, &efd, point, force); + if (eff->pd->forcefield == PFIELD_TEXTURE) { + do_texture_effector(eff, &efd, point, out_force); + } + else { + do_physical_effector(eff, &efd, point, out_force); - /* for softbody backward compatibility */ - if (point->flag & PE_WIND_AS_SPEED && impulse) { - sub_v3_v3v3(temp2, force, temp1); - sub_v3_v3v3(impulse, impulse, temp2); + /* for softbody backward compatibility */ + if (point->flag & PE_WIND_AS_SPEED && impulse) { + sub_v3_v3v3(impulse, impulse, out_force); + } + } + + if (wind_force) { + madd_v3_v3fl(force, out_force, 1.0f - eff->pd->f_wind_factor); + madd_v3_v3fl(wind_force, out_force, eff->pd->f_wind_factor); + } + else { + add_v3_v3(force, out_force); } } } |