[Bf-blender-cvs] [91248876e51] master: GPencil MultiStroke modifier
YimingWu
noreply at git.blender.org
Thu Nov 14 19:36:05 CET 2019
Commit: 91248876e517983531c44ffc1692674684c67eed
Author: YimingWu
Date: Thu Nov 14 19:18:23 2019 +0100
Branches: master
https://developer.blender.org/rB91248876e517983531c44ffc1692674684c67eed
GPencil MultiStroke modifier
This patch includes a modifiers that developed for NPR rendering.
- MultiStroke modifier that generates multiple strokes around the original ones.
Differential Revision: https://developer.blender.org/D5795
===================================================================
M release/scripts/startup/bl_ui/properties_data_modifier.py
M source/blender/blenkernel/BKE_gpencil.h
M source/blender/blenkernel/intern/gpencil.c
M source/blender/gpencil_modifiers/CMakeLists.txt
M source/blender/gpencil_modifiers/MOD_gpencil_modifiertypes.h
M source/blender/gpencil_modifiers/intern/MOD_gpencil_util.c
A source/blender/gpencil_modifiers/intern/MOD_gpencilmultiply.c
M source/blender/makesdna/DNA_gpencil_modifier_types.h
M source/blender/makesrna/RNA_access.h
M source/blender/makesrna/intern/rna_gpencil_modifier.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 889a011886f..05e8f0fce38 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -2351,7 +2351,52 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
sub.active = bool(md.vertex_group)
sub.prop(md, "invert_vertex_group", text="", icon='ARROW_LEFTRIGHT')
+ def GP_MULTIPLY(self, layout, ob, md):
+ gpd = ob.data
+ col = layout.column()
+
+ col.prop(md, "duplications")
+ subcol = col.column()
+ subcol.enabled = md.duplications > 0
+ subcol.prop(md, "distance")
+ subcol.prop(md, "offset", slider=True)
+
+ subcol.separator()
+
+ subcol.prop(md, "enable_fading")
+ if md.enable_fading:
+ subcol.prop(md, "fading_center")
+ subcol.prop(md, "fading_thickness", slider=True)
+ subcol.prop(md, "fading_opacity", slider=True)
+
+ subcol.separator()
+
+ col.prop(md, "enable_angle_splitting")
+ if md.enable_angle_splitting:
+ col.prop(md, "split_angle")
+
+ col = layout.column()
+ col.separator()
+ col.label(text="Material:")
+ row = col.row(align=True)
+ row.prop_search(md, "material", gpd, "materials", text="", icon='SHADING_TEXTURE')
+ row.prop(md, "invert_materials", text="", icon='ARROW_LEFTRIGHT')
+ row = layout.row(align=True)
+ row.prop(md, "pass_index", text="Pass")
+ row.prop(md, "invert_material_pass", text="", icon='ARROW_LEFTRIGHT')
+
+ col = layout.column()
+ col.separator()
+
+ col.label(text="Layer:")
+ row = col.row(align=True)
+ row.prop_search(md, "layer", gpd, "layers", text="", icon='GREASEPENCIL')
+ row.prop(md, "invert_layers", text="", icon='ARROW_LEFTRIGHT')
+ row = layout.row(align=True)
+ row.prop(md, "layer_pass", text="Pass")
+ row.prop(md, "invert_layer_pass", text="", icon='ARROW_LEFTRIGHT')
+
classes = (
DATA_PT_modifiers,
DATA_PT_gpencil_modifiers,
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index d09917a9e41..21356db8abf 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -125,6 +125,12 @@ struct bGPDstroke *BKE_gpencil_add_stroke(struct bGPDframe *gpf,
int totpoints,
short thickness);
+struct bGPDstroke *BKE_gpencil_add_stroke_existing_style(struct bGPDframe *gpf,
+ struct bGPDstroke *existing,
+ int mat_idx,
+ int totpoints,
+ short thickness);
+
/* Stroke and Fill - Alpha Visibility Threshold */
#define GPENCIL_ALPHA_OPACITY_THRESH 0.001f
#define GPENCIL_STRENGTH_MIN 0.003f
@@ -238,6 +244,18 @@ bool BKE_gpencil_smooth_stroke_uv(struct bGPDstroke *gps, int point_index, float
bool BKE_gpencil_close_stroke(struct bGPDstroke *gps);
void BKE_gpencil_dissolve_points(struct bGPDframe *gpf, struct bGPDstroke *gps, const short tag);
+bool BKE_gpencil_stretch_stroke(struct bGPDstroke *gps, const float dist, const float tip_length);
+bool BKE_gpencil_trim_stroke_points(struct bGPDstroke *gps,
+ const int index_from,
+ const int index_to);
+bool BKE_gpencil_split_stroke(struct bGPDframe *gpf,
+ struct bGPDstroke *gps,
+ const int before_index,
+ struct bGPDstroke **remaining_gps);
+bool BKE_gpencil_shrink_stroke(struct bGPDstroke *gps, const float dist);
+
+float BKE_gpencil_stroke_length(const struct bGPDstroke *gps, bool use_3d);
+
void BKE_gpencil_get_range_selected(struct bGPDlayer *gpl, int *r_initframe, int *r_endframe);
float BKE_gpencil_multiframe_falloff_calc(
struct bGPDframe *gpf, int actnum, int f_init, int f_end, struct CurveMapping *cur_falloff);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index e885aa04881..df18f89da6f 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -505,6 +505,18 @@ bGPDstroke *BKE_gpencil_add_stroke(bGPDframe *gpf, int mat_idx, int totpoints, s
return gps;
}
+/* Add a stroke and copy the temporary drawing color value from one of the existing stroke */
+bGPDstroke *BKE_gpencil_add_stroke_existing_style(
+ bGPDframe *gpf, bGPDstroke *existing, int mat_idx, int totpoints, short thickness)
+{
+ bGPDstroke *gps = BKE_gpencil_add_stroke(gpf, mat_idx, totpoints, thickness);
+ /* Copy runtime color data so that strokes added in the modifier has the style.
+ * There are depsgrapgh reference pointers inside,
+ * change the copy function if interfere with future drawing implementation. */
+ memcpy(&gps->runtime, &existing->runtime, sizeof(bGPDstroke_Runtime));
+ return gps;
+}
+
/* ************************************************** */
/* Data Duplication */
@@ -1752,6 +1764,240 @@ bool BKE_gpencil_sample_stroke(bGPDstroke *gps, const float dist, const bool sel
return true;
}
+/**
+ * Backbone stretch similar to Freestyle.
+ * \param gps: Stroke to sample
+ * \param dist: Distance of one segment
+ * \param tip_length: Ignore tip jittering, set zero to use default value.
+ */
+bool BKE_gpencil_stretch_stroke(bGPDstroke *gps, const float dist, const float tip_length)
+{
+ bGPDspoint *pt = gps->points, *last_pt, *second_last, *next_pt;
+ int i;
+ float threshold = (tip_length == 0 ? 0.001f : tip_length);
+
+ if (gps->totpoints < 2 || dist < FLT_EPSILON) {
+ return false;
+ }
+
+ last_pt = &pt[gps->totpoints - 1];
+ second_last = &pt[gps->totpoints - 2];
+ next_pt = &pt[1];
+
+ float len1 = 0.0f;
+ float len2 = 0.0f;
+
+ i = 1;
+ while (len1 < threshold && gps->totpoints > i) {
+ next_pt = &pt[i];
+ len1 = len_v3v3(&next_pt->x, &pt->x);
+ i++;
+ }
+
+ i = 2;
+ while (len2 < threshold && gps->totpoints >= i) {
+ second_last = &pt[gps->totpoints - i];
+ len2 = len_v3v3(&last_pt->x, &second_last->x);
+ i++;
+ }
+
+ float extend1 = (len1 + dist) / len1;
+ float extend2 = (len2 + dist) / len2;
+
+ float result1[3], result2[3];
+
+ interp_v3_v3v3(result1, &next_pt->x, &pt->x, extend1);
+ interp_v3_v3v3(result2, &second_last->x, &last_pt->x, extend2);
+
+ copy_v3_v3(&pt->x, result1);
+ copy_v3_v3(&last_pt->x, result2);
+
+ return true;
+}
+
+/**
+ * Trim stroke to needed segments
+ * \param gps: Target stroke
+ * \param index_from: the index of the first point to be used in the trimmed result
+ * \param index_to: the index of the last point to be used in the trimmed result
+ */
+bool BKE_gpencil_trim_stroke_points(bGPDstroke *gps, const int index_from, const int index_to)
+{
+ bGPDspoint *pt = gps->points, *new_pt;
+ MDeformVert *dv, *new_dv;
+
+ const int new_count = index_to - index_from + 1;
+
+ if (new_count >= gps->totpoints) {
+ return false;
+ }
+
+ if (new_count == 1) {
+ BKE_gpencil_free_stroke_weights(gps);
+ MEM_freeN(gps->points);
+ gps->points = NULL;
+ gps->dvert = NULL;
+ gps->totpoints = 0;
+ return false;
+ }
+
+ new_pt = MEM_callocN(sizeof(bGPDspoint) * new_count, "gp_stroke_points_trimmed");
+
+ for (int i = 0; i < new_count; i++) {
+ memcpy(&new_pt[i], &pt[i + index_from], sizeof(bGPDspoint));
+ }
+
+ if (gps->dvert) {
+ new_dv = MEM_callocN(sizeof(MDeformVert) * new_count, "gp_stroke_dverts_trimmed");
+ for (int i = 0; i < new_count; i++) {
+ dv = &gps->dvert[i + index_from];
+ new_dv[i].flag = dv->flag;
+ new_dv[i].totweight = dv->totweight;
+ new_dv[i].dw = MEM_callocN(sizeof(MDeformWeight) * dv->totweight,
+ "gp_stroke_dverts_dw_trimmed");
+ for (int j = 0; j < dv->totweight; j++) {
+ new_dv[i].dw[j].weight = dv->dw[j].weight;
+ new_dv[i].dw[j].def_nr = dv->dw[j].def_nr;
+ }
+ }
+ MEM_freeN(gps->dvert);
+ gps->dvert = new_dv;
+ }
+
+ MEM_freeN(gps->points);
+ gps->points = new_pt;
+ gps->totpoints = new_count;
+
+ return true;
+}
+
+bool BKE_gpencil_split_stroke(bGPDframe *gpf,
+ bGPDstroke *gps,
+ const int before_index,
+ bGPDstroke **remaining_gps)
+{
+ bGPDstroke *new_gps;
+ bGPDspoint *pt = gps->points, *new_pt;
+ MDeformVert *dv, *new_dv;
+
+ if (before_index >= gps->totpoints || before_index == 0) {
+ return false;
+ }
+
+ const int new_count = gps->totpoints - before_index;
+ const int old_count = before_index;
+
+ /* Handle remaining segments first. */
+
+ new_gps = BKE_gpencil_add_stroke_existing_style(
+ gpf, gps, gps->mat_nr, new_count, gps->thickness);
+
+ new_pt = new_gps->points; /* Allocated from above. */
+
+ for (int i = 0; i < new_count; i++) {
+ memcpy(&new_pt[i], &pt[i + before_index], sizeof(bGPDspoint));
+ }
+
+ if (gps->dvert) {
+ new_dv = MEM_callocN(sizeof(MDeformVert) * new_count, "gp_stroke_dverts_remaining");
+ for (int i = 0; i < new_count; i++) {
+ dv = &gps->dvert[i + before_index];
+ new_dv[i].flag = dv->flag;
+ new_dv[i].totweight = dv->totweight;
+ new_dv[i].dw = MEM_callocN(sizeof(MDeformWeight) * dv->totweight,
+ "gp_stroke_dverts_dw_remaining");
+ for (int j = 0; j < dv->totweight; j++) {
+ new_dv[i].dw[j].weight = dv->dw[j].weight;
+ new_dv[i].dw[j].def_nr = dv->dw[j].def_nr;
+ }
+ }
+ new_gps->dvert = new_dv;
+ }
+
+ (*remaining_gps) = new_gps;
+
+ /* Trim the original stroke into a shorter one.
+ * Keep the end point. */
+
+ BKE_gpencil_trim_stroke_points(gps, 0, old_count);
+
+ return true;
+}
+
+/**
+ * Shrink the stroke by length.
+ * \p
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list