[Bf-blender-cvs] [abfa37f7156] greasepencil-object: Add step parameter to Noise modifier
Antonio Vazquez
noreply at git.blender.org
Tue Jul 18 12:07:04 CEST 2017
Commit: abfa37f715626aa71ba4d7c34e96809d207752a0
Author: Antonio Vazquez
Date: Tue Jul 18 12:06:54 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rBabfa37f715626aa71ba4d7c34e96809d207752a0
Add step parameter to Noise modifier
Now it is possible to define a number of frames between recalculate random noise. This allows to reduce the speed of change because before, sometimes was too fast.
===================================================================
M release/scripts/startup/bl_ui/properties_data_modifier.py
M source/blender/blenkernel/intern/gpencil.c
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/makesrna/intern/rna_modifier.c
M source/blender/modifiers/intern/MOD_gpencilnoise.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 4c4a3aff50d..3374dc37590 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1536,11 +1536,14 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
row = col.row(align=True)
row.prop(md, "factor")
row.prop(md, "random", text="", icon="TIME", toggle=True)
- col.prop(md, "passindex", text="Pass")
+ row = col.row()
+ row.enabled = md.random
+ row.prop(md, "step")
col = split.column()
col.label("Layer:")
col.prop_search(md, "layer", gpd, "layers", text="", icon="GREASEPENCIL")
+ col.prop(md, "passindex", text="Pass")
row = layout.row(align=True)
row.label("Affect:")
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 0cb35af3094..56c99488379 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1586,11 +1586,17 @@ void ED_gpencil_noise_modifier(GpencilNoiseModifierData *mmd, bGPDlayer *gpl, bG
float shift, vran, vdir;
float normal[3];
float vec1[3], vec2[3];
+ Scene *scene = NULL;
+ int sc_frame = 0;
+ int sc_diff = 0;
if (!is_stroke_affected_by_modifier(mmd->layername, mmd->passindex, 3, gpl, gps)) {
return;
}
+ scene = mmd->modifier.scene;
+ sc_frame = CFRA;
+
/* calculate stroke normal*/
ED_gpencil_stroke_normal(gps, normal);
@@ -1606,12 +1612,23 @@ void ED_gpencil_noise_modifier(GpencilNoiseModifierData *mmd, bGPDlayer *gpl, bG
normalize_v3(vec2);
/* use random noise */
if (mmd->flag & GP_NOISE_USE_RANDOM) {
- vran = BLI_frand();
- vdir = BLI_frand();
+ 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)) {
+ vran = mmd->vrand1 = BLI_frand();
+ vdir = mmd->vrand2 = BLI_frand();
+ mmd->gp_frame = gpl->actframe->framenum;
+ mmd->scene_frame = sc_frame;
+ }
+ else {
+ vran = mmd->vrand1;
+ vdir = mmd->vrand2;
+ }
}
else {
vran = 1.0f;
vdir = i % 2;
+ mmd->gp_frame = -999999;
}
/* apply randomness to location of the point */
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index cd9ba951e21..f5cdfafea08 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1622,7 +1622,10 @@ typedef struct GpencilNoiseModifierData {
int passindex; /* custom index for passes */
int flag; /* several flags */
float factor; /* factor of noise */
- char pad[4];
+ int step; /* how many frames before recalculate randoms */
+ int gp_frame; /* last gp frame used */
+ int scene_frame; /* last scene frame used */
+ float vrand1, vrand2; /* random values */
} GpencilNoiseModifierData;
typedef enum eGpencilNoise_Flag {
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index f6e9ae95394..57ff93aef79 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -4819,6 +4819,12 @@ static void rna_def_modifier_gpencilnoise(BlenderRNA *brna)
RNA_def_property_range(prop, 0, 100);
RNA_def_property_ui_text(prop, "Pass", "Pass index");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+ prop = RNA_def_property(srna, "step", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "step");
+ RNA_def_property_range(prop, 1, 100);
+ RNA_def_property_ui_text(prop, "Step", "Number of frames before recalculate random values again");
+ RNA_def_property_update(prop, 0, "rna_Modifier_update");
}
static void rna_def_modifier_gpencilsubdiv(BlenderRNA *brna)
diff --git a/source/blender/modifiers/intern/MOD_gpencilnoise.c b/source/blender/modifiers/intern/MOD_gpencilnoise.c
index 2e383e30de9..2f455b7157e 100644
--- a/source/blender/modifiers/intern/MOD_gpencilnoise.c
+++ b/source/blender/modifiers/intern/MOD_gpencilnoise.c
@@ -35,11 +35,11 @@
#include "DNA_gpencil_types.h"
#include "BLI_utildefines.h"
+
#include "BKE_DerivedMesh.h"
#include "BKE_gpencil.h"
#include "MOD_modifiertypes.h"
-#include "BKE_gpencil.h"
static void initData(ModifierData *md)
{
@@ -48,6 +48,11 @@ static void initData(ModifierData *md)
gpmd->flag |= GP_NOISE_MOD_LOCATION;
gpmd->factor = 0.5f;
gpmd->layername[0] = '\0';
+ gpmd->step = 1;
+ gpmd->scene_frame = -999999;
+ gpmd->gp_frame = -999999;
+ gpmd->vrand1 = 1.0;
+ gpmd->vrand2 = 1.0;
BKE_gpencil_batch_cache_alldirty();
}
More information about the Bf-blender-cvs
mailing list