[Bf-blender-cvs] [a4b0a65909e] soc-2019-npr: GPencil: Backbone Stretcher modifier
YimingWu
noreply at git.blender.org
Wed Jun 5 06:21:15 CEST 2019
Commit: a4b0a65909e85acb2bf613ccc8db492242b23832
Author: YimingWu
Date: Wed Jun 5 12:20:48 2019 +0800
Branches: soc-2019-npr
https://developer.blender.org/rBa4b0a65909e85acb2bf613ccc8db492242b23832
GPencil: Backbone Stretcher modifier
===================================================================
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/draw/engines/lanpr/lanpr_access.c
M source/blender/draw/engines/lanpr/lanpr_access.h
M source/blender/draw/engines/lanpr/lanpr_chain.c
M source/blender/draw/engines/lanpr/lanpr_ops.c
M source/blender/editors/interface/interface_templates.c
M source/blender/editors/screen/screen_ops.c
M source/blender/editors/space_file/filesel.c
M source/blender/editors/undo/ed_undo.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_gpencilbackbonestretch.c
M source/blender/gpencil_modifiers/intern/MOD_gpencilsample.c
M source/blender/makesdna/DNA_gpencil_modifier_types.h
M source/blender/makesdna/DNA_gpencil_types.h
M source/blender/makesrna/RNA_access.h
M source/blender/makesrna/intern/rna_constraint.c
M source/blender/makesrna/intern/rna_gpencil.c
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 fbccf42f780..687d41a4d44 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -2270,6 +2270,10 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
def GP_SAMPLE(self, layout, ob, md):
col = layout.column()
col.prop(md, "length")
+
+ def GP_BACKBONE(self, layout, ob, md):
+ col = layout.column()
+ col.prop(md, "length")
classes = (
diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index ae19b40f7bf..ebc21493b53 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -212,6 +212,7 @@ void BKE_gpencil_stroke_2d_flat_ref(const struct bGPDspoint *ref_points,
void BKE_gpencil_transform(struct bGPdata *gpd, float mat[4][4]);
bool BKE_gpencil_sample_stroke(struct bGPDstroke *gps, float dist);
+bool BKE_gpencil_stretch_stroke(struct bGPDstroke *gps, float dist);
bool BKE_gpencil_smooth_stroke(struct bGPDstroke *gps, int i, float inf);
bool BKE_gpencil_smooth_stroke_strength(struct bGPDstroke *gps, int point_index, float influence);
bool BKE_gpencil_smooth_stroke_thickness(struct bGPDstroke *gps, int point_index, float influence);
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 7c54cfd1737..1bc1c0e1257 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1397,49 +1397,60 @@ void BKE_gpencil_dvert_ensure(bGPDstroke *gps)
/* ************************************************** */
-static int stroke_march_next_point(bGPDstroke *gps, int next_point_index, float* current, float dist, float *result, float* pressure, float* strength){
- float remaining_till_next=0.0f;
+static int stroke_march_next_point(bGPDstroke *gps,
+ int next_point_index,
+ float *current,
+ float dist,
+ float *result,
+ float *pressure,
+ float *strength)
+{
+ float remaining_till_next = 0.0f;
float remaining_march = dist;
float step_start[3];
float point[3];
- if(!(next_point_index<gps->totpoints)) return -1;
+ if (!(next_point_index < gps->totpoints))
+ return -1;
- copy_v3_v3(step_start,current);
+ copy_v3_v3(step_start, current);
point[0] = gps->points[next_point_index].x;
point[1] = gps->points[next_point_index].y;
point[2] = gps->points[next_point_index].z;
- remaining_till_next = len_v3v3(point,step_start);
+ remaining_till_next = len_v3v3(point, step_start);
- while(remaining_till_next < remaining_march){
+ while (remaining_till_next < remaining_march) {
remaining_march -= remaining_till_next;
point[0] = gps->points[next_point_index].x;
point[1] = gps->points[next_point_index].y;
point[2] = gps->points[next_point_index].z;
- copy_v3_v3(step_start,point);
+ copy_v3_v3(step_start, point);
next_point_index++;
- if(!(next_point_index<gps->totpoints)){
- next_point_index=gps->totpoints-1;
+ if (!(next_point_index < gps->totpoints)) {
+ next_point_index = gps->totpoints - 1;
break;
}
point[0] = gps->points[next_point_index].x;
point[1] = gps->points[next_point_index].y;
point[2] = gps->points[next_point_index].z;
- remaining_till_next = len_v3v3(point,step_start);
+ remaining_till_next = len_v3v3(point, step_start);
}
- if(remaining_till_next < remaining_march){
+ if (remaining_till_next < remaining_march) {
result[0] = gps->points[next_point_index].x;
result[1] = gps->points[next_point_index].y;
result[2] = gps->points[next_point_index].z;
*pressure = gps->points[next_point_index].pressure;
*strength = gps->points[next_point_index].strength;
return 0;
- }else{
- float ratio = remaining_march/remaining_till_next;
- interp_v3_v3v3(result,step_start,point,ratio);
- *pressure = interpf(gps->points[next_point_index-1].pressure,gps->points[next_point_index].pressure,ratio);
- *strength = interpf(gps->points[next_point_index-1].strength,gps->points[next_point_index].strength,ratio);
+ }
+ else {
+ float ratio = remaining_march / remaining_till_next;
+ interp_v3_v3v3(result, step_start, point, ratio);
+ *pressure = interpf(
+ gps->points[next_point_index - 1].pressure, gps->points[next_point_index].pressure, ratio);
+ *strength = interpf(
+ gps->points[next_point_index - 1].strength, gps->points[next_point_index].strength, ratio);
return next_point_index;
}
}
@@ -1454,47 +1465,59 @@ bool BKE_gpencil_sample_stroke(bGPDstroke *gps, float dist)
bGPDspoint *pt = gps->points;
int i;
- if(gps->totpoints < 2 || dist < FLT_EPSILON) return false;
+ if (gps->totpoints < 2 || dist < FLT_EPSILON)
+ return false;
- for (i=0;i<gps->totpoints;i++){
- pt[i].flag &= ~GP_SPOINT_TAG_FEATURE; // feature point preservation not implemented yet
+ for (i = 0; i < gps->totpoints; i++) {
+ pt[i].flag &= ~GP_SPOINT_TAG_FEATURE; // feature point preservation not implemented yet
}
- float length=0.0f;
+ float length = 0.0f;
float last_coord[3], this_coord[3];
- last_coord[0]=pt[0].x; last_coord[1]=pt[0].y; last_coord[2]=pt[0].z;
- for (i=1;i<gps->totpoints;i++){
- this_coord[0]=pt[i].x; this_coord[1]=pt[i].y; this_coord[2]=pt[i].z;
- length+=len_v3v3(last_coord,this_coord);
- }
-
- int count = (int)(length/dist)+3; // preserve some extra in case
-
- bGPDspoint *new_pt = MEM_callocN(sizeof(bGPDspoint)*count,"gp_stroke_points_sampled");
-
- int next_point_index=1; i=0;
- float pressure,strength;
- last_coord[0]=pt[0].x; last_coord[1]=pt[0].y; last_coord[2]=pt[0].z;
+ last_coord[0] = pt[0].x;
+ last_coord[1] = pt[0].y;
+ last_coord[2] = pt[0].z;
+ for (i = 1; i < gps->totpoints; i++) {
+ this_coord[0] = pt[i].x;
+ this_coord[1] = pt[i].y;
+ this_coord[2] = pt[i].z;
+ length += len_v3v3(last_coord, this_coord);
+ }
+
+ int count = (int)(length / dist) + 3; // preserve some extra in case
+
+ bGPDspoint *new_pt = MEM_callocN(sizeof(bGPDspoint) * count, "gp_stroke_points_sampled");
+
+ int next_point_index = 1;
+ i = 0;
+ float pressure, strength;
+ last_coord[0] = pt[0].x;
+ last_coord[1] = pt[0].y;
+ last_coord[2] = pt[0].z;
// 1st point
- new_pt[i].x = last_coord[0]; new_pt[i].y = last_coord[1]; new_pt[i].z = last_coord[2];
+ new_pt[i].x = last_coord[0];
+ new_pt[i].y = last_coord[1];
+ new_pt[i].z = last_coord[2];
new_pt[i].pressure = pt[0].pressure;
new_pt[i].strength = pt[0].strength;
i++;
- while((next_point_index=stroke_march_next_point(gps,next_point_index,last_coord,dist,last_coord,&pressure,&strength))>-1){
+ while ((next_point_index = stroke_march_next_point(
+ gps, next_point_index, last_coord, dist, last_coord, &pressure, &strength)) > -1) {
new_pt[i].x = last_coord[0];
new_pt[i].y = last_coord[1];
new_pt[i].z = last_coord[2];
new_pt[i].pressure = pressure;
new_pt[i].strength = strength;
i++;
- if(next_point_index == 0) break; // last point finished
+ if (next_point_index == 0)
+ break; // last point finished
}
gps->points = new_pt;
gps->totpoints = i;
-
- MEM_freeN(pt);//original
+
+ MEM_freeN(pt); // original
gps->flag |= GP_STROKE_RECALC_GEOMETRY;
gps->tot_triangles = 0;
@@ -1502,6 +1525,35 @@ bool BKE_gpencil_sample_stroke(bGPDstroke *gps, float dist)
return true;
}
+/**
+ * Backbone stretch similar to Freestyle.
+ * \param gps: Stroke to sample
+ * \param dist: Distance of one segment
+ */
+bool BKE_gpencil_stretch_stroke(bGPDstroke *gps, float dist)
+{
+ bGPDspoint *pt = gps->points, *last_pt, *second_last, *next_pt;
+ int i;
+
+ 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 = len_v3v3(&next_pt->x, &pt->x);
+ float extend1 = (len1 + dist) / len1;
+ float len2 = len_v3v3(&last_pt->x, &second_last->x);
+ float extend2 = (len2 + dist) / len2;
+
+ interp_v3_v3v3(&pt->x, &next_pt->x, &pt->x, extend1);
+ interp_v3_v3v3(&last_pt->x, &second_last->x, &last_pt->x, extend2);
+
+ return true;
+}
+
/**
* Apply smooth to stroke point
* \param gps: Stroke to smooth
diff --git a/source/blender/draw/engines/lanpr/lanpr_access.c b/source/blender/draw/engines/lanpr/lanpr_access.c
index 524a08eacd5..c2a44730475 100644
--- a/source/blender/draw/engines/lanpr/lanpr_access.c
+++ b/source/blender/draw/engines/lanpr/lanpr_access.c
@@ -243,7 +243,8 @@ void lanpr_generate_gpencil_from_chain(
printf("NULL LANPR rb!\n");
return;
}
- if (scene->lanpr.master_mode != LANPR_MASTER_MODE_SOFTWARE) return;
+ if (scene->lanpr.master_mode != LANPR_MASTER_MODE_SOFTWARE)
+ return;
int color_idx = 0;
int tot_points = 0;
@@ -281,11 +282,13 @@ void lanpr_generate_gpencil_from_chain(
}
}
-void lanpr_update_data_for_external(Depsgraph *depsgraph){
+void lanpr_update_data_for_external(Depsgraph *depsgraph)
+{
Scene *scene = DEG_get_evaluated_scene(depsgraph);
SceneLANPR *lanpr = &scene->lanpr;
- if (lanpr->master_mode != LANPR_MASTER_MODE_SOFTWARE) return;
- if (lanpr->render_buffer && lanpr->render_buffer->cached_for_frame != scene->r.cfra){
+ if (lanpr->master_mode != LANPR_MASTER_MODE_SOFTWARE)
+ return;
+ if (lanpr->render_buffer && lanpr->render_buffer->cached_for_frame != scene->r.cfra) {
lanpr_compute_feature_lines_internal(depsgraph, lanpr, scene);
}
}
diff --git a/source/blender/draw/engines/lanpr/lanpr_access.h b/source/blender/draw/engines/lanpr/lanpr_access.h
index baa9dbb07ea..5bc56b19910 100644
--- a/source/blender/draw/engines/lanpr/lanpr_access.h
+++ b/source/blender/draw/engines/lanpr/lanpr_access.h
@@ -18,12 +18,10 @@ void lanpr_generate_gpencil_from_chain(
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list