GPencil: New Noise modifier random in Keyframes only

This is for some animation styles that usually copy and paste keyframes and they want avoid that both frames look equal, but they don't want noise randomness changes in the inbetween frames.

The patch adds a new random `Mode` option to select when the noise change.

Reviewed By: pepeland

Maniphest Tasks: T97099

Differential Revision: https://developer.blender.org/D14566
This commit is contained in:
Antonio Vazquez 2022-05-02 17:28:24 +02:00
parent b1e0be0d25
commit 0d9e22d43c
Notes: blender-bot 2023-02-14 08:10:10 +01:00
Referenced by issue #97099, GPencil: New option to apply Random Noise modifier only to keyframes
3 changed files with 33 additions and 3 deletions

View File

@ -122,6 +122,8 @@ static void deformStroke(GpencilModifierData *md,
const int def_nr = BKE_object_defgroup_name_index(ob, mmd->vgname);
const bool invert_group = (mmd->flag & GP_NOISE_INVERT_VGROUP) != 0;
const bool use_curve = (mmd->flag & GP_NOISE_CUSTOM_CURVE) != 0 && mmd->curve_intensity;
const int cfra = (int)DEG_get_ctime(depsgraph);
const bool is_keyframe = (mmd->noise_mode == GP_NOISE_RANDOM_KEYFRAME);
if (!is_stroke_affected_by_modifier(ob,
mmd->layername,
@ -148,7 +150,13 @@ static void deformStroke(GpencilModifierData *md,
seed += BLI_hash_string(md->name);
if (mmd->flag & GP_NOISE_USE_RANDOM) {
seed += ((int)DEG_get_ctime(depsgraph)) / mmd->step;
if (!is_keyframe) {
seed += cfra / mmd->step;
}
else {
/* If change every keyframe, use the last keyframe. */
seed += gpf->framenum;
}
}
/* Sanitize as it can create out of bound reads. */
@ -302,7 +310,12 @@ static void random_panel_draw(const bContext *UNUSED(C), Panel *panel)
uiLayoutSetActive(layout, RNA_boolean_get(ptr, "use_random"));
uiItemR(layout, ptr, "step", 0, NULL, ICON_NONE);
uiItemR(layout, ptr, "random_mode", 0, NULL, ICON_NONE);
const int mode = RNA_enum_get(ptr, "random_mode");
if (mode != GP_NOISE_RANDOM_KEYFRAME) {
uiItemR(layout, ptr, "step", 0, NULL, ICON_NONE);
}
}
static void mask_panel_draw(const bContext *UNUSED(C), Panel *panel)

View File

@ -102,7 +102,8 @@ typedef struct NoiseGpencilModifierData {
/** Noise Frequency scaling */
float noise_scale;
float noise_offset;
char _pad[4];
short noise_mode;
char _pad[2];
/** How many frames before recalculate randoms. */
int step;
/** Custom index for passes. */
@ -127,6 +128,11 @@ typedef enum eNoiseGpencil_Flag {
GP_NOISE_INVERT_MATERIAL = (1 << 11),
} eNoiseGpencil_Flag;
typedef enum eNoiseRandomGpencil_Mode {
GP_NOISE_RANDOM_STEP = 0,
GP_NOISE_RANDOM_KEYFRAME = 1,
} eNoiseRandomGpencil_Mode;
typedef struct SubdivGpencilModifierData {
GpencilModifierData modifier;
/** Material for filtering. */

View File

@ -232,6 +232,11 @@ static const EnumPropertyItem gpencil_envelope_mode_items[] = {
"Add fill segments to create the envelope. Don't keep the original stroke"},
{0, NULL, 0, NULL, NULL},
};
static const EnumPropertyItem modifier_noise_random_mode_items[] = {
{GP_NOISE_RANDOM_STEP, "STEP", 0, "Steps", "Apply random every N steps"},
{GP_NOISE_RANDOM_KEYFRAME, "KEYFRAME", 0, "On Keyframes", "Apply random every keyframe"},
{0, NULL, 0, NULL, NULL},
};
#endif
#ifdef RNA_RUNTIME
@ -959,6 +964,12 @@ static void rna_def_modifier_gpencilnoise(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Inverse Pass", "Inverse filter");
RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
prop = RNA_def_property(srna, "random_mode", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "noise_mode");
RNA_def_property_enum_items(prop, modifier_noise_random_mode_items);
RNA_def_property_ui_text(prop, "Mode", "How the random changes are applied");
RNA_def_property_update(prop, 0, "rna_GpencilModifier_update");
RNA_define_lib_overridable(false);
}