Fix T60778: Grease pencil Hook modifieronly affects strokes with more than 2 points

Also fixed Lattice and Noise modifier.
This commit is contained in:
Antonioya
2019-01-23 10:36:52 +01:00
parent baa5fe1bfc
commit 9ff73e61b1
3 changed files with 25 additions and 12 deletions
@@ -210,7 +210,7 @@ static void deformStroke(
if (!is_stroke_affected_by_modifier(
ob,
mmd->layername, mmd->pass_index, mmd->layer_pass, 3, gpl, gps,
mmd->layername, mmd->pass_index, mmd->layer_pass, 1, gpl, gps,
mmd->flag & GP_HOOK_INVERT_LAYER, mmd->flag & GP_HOOK_INVERT_PASS,
mmd->flag & GP_HOOK_INVERT_LAYERPASS))
{
@@ -83,7 +83,7 @@ static void deformStroke(
if (!is_stroke_affected_by_modifier(
ob,
mmd->layername, mmd->pass_index, mmd->layer_pass, 3, gpl, gps,
mmd->layername, mmd->pass_index, mmd->layer_pass, 1, gpl, gps,
mmd->flag & GP_LATTICE_INVERT_LAYER, mmd->flag & GP_LATTICE_INVERT_PASS,
mmd->flag & GP_LATTICE_INVERT_LAYERPASS))
{
@@ -96,8 +96,8 @@ static bool dependsOnTime(GpencilModifierData *md)
/* aply noise effect based on stroke direction */
static void deformStroke(
GpencilModifierData *md, Depsgraph *depsgraph,
Object *ob, bGPDlayer *gpl, bGPDstroke *gps)
GpencilModifierData *md, Depsgraph *depsgraph,
Object *ob, bGPDlayer *gpl, bGPDstroke *gps)
{
NoiseGpencilModifierData *mmd = (NoiseGpencilModifierData *)md;
bGPDspoint *pt0, *pt1;
@@ -108,6 +108,7 @@ static void deformStroke(
int sc_frame = 0;
int sc_diff = 0;
const int def_nr = defgroup_name_index(ob, mmd->vgname);
const float unit_v3[3] = { 1.0f, 1.0f, 1.0f };
/* Random generator, only init once. */
if (mmd->rng == NULL) {
@@ -117,10 +118,10 @@ static void deformStroke(
}
if (!is_stroke_affected_by_modifier(
ob,
mmd->layername, mmd->pass_index, mmd->layer_pass, 3, gpl, gps,
mmd->flag & GP_NOISE_INVERT_LAYER, mmd->flag & GP_NOISE_INVERT_PASS,
mmd->flag & GP_NOISE_INVERT_LAYERPASS))
ob,
mmd->layername, mmd->pass_index, mmd->layer_pass, 1, gpl, gps,
mmd->flag & GP_NOISE_INVERT_LAYER, mmd->flag & GP_NOISE_INVERT_PASS,
mmd->flag & GP_NOISE_INVERT_LAYERPASS))
{
return;
}
@@ -130,7 +131,12 @@ static void deformStroke(
zero_v3(vec2);
/* calculate stroke normal*/
BKE_gpencil_stroke_normal(gps, normal);
if (gps->totpoints > 2) {
BKE_gpencil_stroke_normal(gps, normal);
}
else {
copy_v3_v3(normal, unit_v3);
}
/* move points */
for (int i = 0; i < gps->totpoints; i++) {
@@ -143,7 +149,7 @@ static void deformStroke(
if (gps->dvert) {
dvert = &gps->dvert[0];
}
pt0 = &gps->points[1];
pt0 = (gps->totpoints > 1) ? &gps->points[1] : &gps->points[0];
pt1 = &gps->points[0];
}
else {
@@ -174,7 +180,7 @@ static void deformStroke(
sc_diff = abs(mmd->scene_frame - sc_frame);
/* only recalc if the gp frame change or the number of scene frames is bigger than step */
if ((!gpl->actframe) || (mmd->gp_frame != gpl->actframe->framenum) ||
(sc_diff >= mmd->step))
(sc_diff >= mmd->step))
{
vran = mmd->vrand1 = BLI_rng_get_float(mmd->rng);
vdir = mmd->vrand2 = BLI_rng_get_float(mmd->rng);
@@ -203,7 +209,14 @@ static void deformStroke(
mmd->gp_frame = -999999;
}
/* apply randomness to location of the point */
/* if vec2 is zero, set to something */
if (gps->totpoints < 3) {
if ((vec2[0] == 0.0f) && (vec2[1] == 0.0f) && (vec2[2] == 0.0f)) {
copy_v3_v3(vec2, unit_v3);
}
}
/* apply randomness to location of the point */
if (mmd->flag & GP_NOISE_MOD_LOCATION) {
/* factor is too sensitive, so need divide */
shift = ((vran * mmd->factor) / 1000.0f) * weight;