[Bf-blender-cvs] [c2f77b90f8a] temp-gpencil-bezier-stroke-type: GPecnil: WIP Transfer weights from curve to polyline
Falk David
noreply at git.blender.org
Mon Apr 19 11:41:31 CEST 2021
Commit: c2f77b90f8adebfc224b2016f43587280983078f
Author: Falk David
Date: Mon Apr 19 11:39:34 2021 +0200
Branches: temp-gpencil-bezier-stroke-type
https://developer.blender.org/rBc2f77b90f8adebfc224b2016f43587280983078f
GPecnil: WIP Transfer weights from curve to polyline
===================================================================
M source/blender/blenkernel/intern/gpencil_curve.c
M source/blender/editors/gpencil/gpencil_weight_paint.c
===================================================================
diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c
index 82eec1b6f54..f791c4e3e59 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -45,6 +45,7 @@
#include "BKE_collection.h"
#include "BKE_context.h"
#include "BKE_curve.h"
+#include "BKE_deform.h"
#include "BKE_gpencil.h"
#include "BKE_gpencil_curve.h"
#include "BKE_gpencil_geom.h"
@@ -1590,6 +1591,41 @@ void BKE_gpencil_stroke_update_geometry_from_editcurve(bGPDstroke *gps,
gps->flag &= ~GP_STROKE_SELECT;
BKE_gpencil_stroke_select_index_reset(gps);
+ /* Interpolate weights. */
+ if (editcurve->dvert != NULL &&
+ (update_all_attributes || (flag & GP_GEO_UPDATE_POLYLINE_WEIGHT))) {
+ for (int i = 0, idx = 0; i < editcurve->tot_curve_points - 1; i++) {
+ MDeformVert *dv_curr = &editcurve->dvert[i];
+ MDeformVert *dv_next = &editcurve->dvert[i + 1];
+
+ if (dv_curr->totweight == 0 || dv_next->totweight == 0) {
+ continue;
+ }
+
+ int segment_length = (adaptive) ? segment_length_cache[i] : resolution;
+ for (int j = 0; j < segment_length; j++) {
+ MDeformVert *dvert = &gps->dvert[idx + j];
+ BKE_defvert_copy(dvert, dv_curr);
+ float t = (float)j / (float)segment_length;
+ for (int d = 0; d < dv_curr->totweight; d++) {
+ MDeformWeight *dw_a = BKE_defvert_ensure_index(dv_curr, d);
+ MDeformWeight *dw_b = BKE_defvert_ensure_index(dv_next, d);
+ MDeformWeight *dw_final = BKE_defvert_ensure_index(dvert, d);
+
+ if (dw_a->weight == dw_b->weight) {
+ dw_final->weight = dw_a->weight;
+ }
+ else {
+ dw_final->weight = smooth_interpf(dw_b->weight, dw_a->weight, t);
+ }
+ }
+ }
+ idx += segment_length;
+ }
+
+ /* TODO: Deal with cyclic strokes. */
+ }
+
/* free temp data */
MEM_freeN(points);
MEM_SAFE_FREE(segment_length_cache);
diff --git a/source/blender/editors/gpencil/gpencil_weight_paint.c b/source/blender/editors/gpencil/gpencil_weight_paint.c
index a04fe99ac86..780c837915c 100644
--- a/source/blender/editors/gpencil/gpencil_weight_paint.c
+++ b/source/blender/editors/gpencil/gpencil_weight_paint.c
@@ -37,6 +37,7 @@
#include "BKE_context.h"
#include "BKE_deform.h"
#include "BKE_gpencil.h"
+#include "BKE_gpencil_geom.h"
#include "BKE_main.h"
#include "BKE_object_deform.h"
#include "BKE_report.h"
@@ -640,7 +641,6 @@ static bool gpencil_weightpaint_brush_do_frame(bContext *C,
*--------------------------------------------------------------------- */
bool changed = false;
for (i = 0; i < gso->pbuffer_used; i++) {
- changed = true;
selected = &gso->pbuffer[i];
switch (tool) {
@@ -653,6 +653,10 @@ static bool gpencil_weightpaint_brush_do_frame(bContext *C,
printf("ERROR: Unknown type of GPencil Weight Paint brush\n");
break;
}
+
+ if (changed && GPENCIL_STROKE_TYPE_BEZIER(selected->gps)) {
+ BKE_gpencil_stroke_geometry_update(gso->gpd, selected->gps, GP_GEO_UPDATE_DEFAULT);
+ }
}
/* Clear the selected array, but keep the memory allocation.*/
gso->pbuffer = gpencil_select_buffer_ensure(
More information about the Bf-blender-cvs
mailing list