Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2020-03-16 20:14:24 +0300
committerJulian Eisel <julian@blender.org>2020-03-16 20:14:24 +0300
commitddbbd9928ec443f813ee4d46011288e360278e9f (patch)
tree91f50fc6e8e8b68be5686903aca191d43cdafae5 /source/blender/editors/gpencil
parentb86be9b2145458037fd0b17433b7af0efa7b6472 (diff)
parentd2ef342b2a50a7eac725889708fd689ffa126e25 (diff)
Merge branch 'temp-openxr-ghostxr' into temp-openxr-blenderside
Diffstat (limited to 'source/blender/editors/gpencil')
-rw-r--r--source/blender/editors/gpencil/CMakeLists.txt2
-rw-r--r--source/blender/editors/gpencil/gpencil_data.c12
-rw-r--r--source/blender/editors/gpencil/gpencil_intern.h4
-rw-r--r--source/blender/editors/gpencil/gpencil_ops.c4
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c4
-rw-r--r--source/blender/editors/gpencil/gpencil_primitive.c2
-rw-r--r--source/blender/editors/gpencil/gpencil_select.c120
-rw-r--r--source/blender/editors/gpencil/gpencil_utils.c3
-rw-r--r--source/blender/editors/gpencil/gpencil_vertex_paint.c18
9 files changed, 117 insertions, 52 deletions
diff --git a/source/blender/editors/gpencil/CMakeLists.txt b/source/blender/editors/gpencil/CMakeLists.txt
index 512e1ec6270..4083169d65c 100644
--- a/source/blender/editors/gpencil/CMakeLists.txt
+++ b/source/blender/editors/gpencil/CMakeLists.txt
@@ -58,8 +58,8 @@ set(SRC
gpencil_undo.c
gpencil_utils.c
gpencil_uv.c
- gpencil_vertex_paint.c
gpencil_vertex_ops.c
+ gpencil_vertex_paint.c
gpencil_weight_paint.c
gpencil_intern.h
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 9b33e999a25..e5d332a86de 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -3179,7 +3179,7 @@ void GPENCIL_OT_color_unlock_all(wmOperatorType *ot)
/* ***************** Select all strokes using color ************************ */
-static int gpencil_color_select_exec(bContext *C, wmOperator *op)
+static int gpencil_select_material_exec(bContext *C, wmOperator *op)
{
bGPdata *gpd = ED_gpencil_data_get_active(C);
Object *ob = CTX_data_active_object(C);
@@ -3249,15 +3249,15 @@ static int gpencil_color_select_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
-void GPENCIL_OT_color_select(wmOperatorType *ot)
+void GPENCIL_OT_select_material(wmOperatorType *ot)
{
/* identifiers */
- ot->name = "Select Color";
- ot->idname = "GPENCIL_OT_color_select";
- ot->description = "Select all Grease Pencil strokes using current color";
+ ot->name = "Select Material";
+ ot->idname = "GPENCIL_OT_select_material";
+ ot->description = "Select/Deselect all Grease Pencil strokes using current material";
/* callbacks */
- ot->exec = gpencil_color_select_exec;
+ ot->exec = gpencil_select_material_exec;
ot->poll = gpencil_active_color_poll;
/* flags */
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 2d36e426835..a12fd81e032 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -407,7 +407,7 @@ void GPENCIL_OT_select_less(struct wmOperatorType *ot);
void GPENCIL_OT_select_first(struct wmOperatorType *ot);
void GPENCIL_OT_select_last(struct wmOperatorType *ot);
void GPENCIL_OT_select_alternate(struct wmOperatorType *ot);
-void GPENCIL_OT_select_color(struct wmOperatorType *ot);
+void GPENCIL_OT_select_vertex_color(struct wmOperatorType *ot);
void GPENCIL_OT_duplicate(struct wmOperatorType *ot);
void GPENCIL_OT_delete(struct wmOperatorType *ot);
@@ -552,7 +552,7 @@ void GPENCIL_OT_color_hide(struct wmOperatorType *ot);
void GPENCIL_OT_color_reveal(struct wmOperatorType *ot);
void GPENCIL_OT_color_lock_all(struct wmOperatorType *ot);
void GPENCIL_OT_color_unlock_all(struct wmOperatorType *ot);
-void GPENCIL_OT_color_select(struct wmOperatorType *ot);
+void GPENCIL_OT_select_material(struct wmOperatorType *ot);
void GPENCIL_OT_set_active_material(struct wmOperatorType *ot);
/* convert old 2.7 files to 2.8 */
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index 275075c38db..233bebfc9b6 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -544,7 +544,7 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_select_first);
WM_operatortype_append(GPENCIL_OT_select_last);
WM_operatortype_append(GPENCIL_OT_select_alternate);
- WM_operatortype_append(GPENCIL_OT_select_color);
+ WM_operatortype_append(GPENCIL_OT_select_vertex_color);
WM_operatortype_append(GPENCIL_OT_duplicate);
WM_operatortype_append(GPENCIL_OT_delete);
@@ -653,7 +653,7 @@ void ED_operatortypes_gpencil(void)
WM_operatortype_append(GPENCIL_OT_color_reveal);
WM_operatortype_append(GPENCIL_OT_color_lock_all);
WM_operatortype_append(GPENCIL_OT_color_unlock_all);
- WM_operatortype_append(GPENCIL_OT_color_select);
+ WM_operatortype_append(GPENCIL_OT_select_material);
/* Editing (Time) --------------- */
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 46788eba370..e7586d95d29 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1653,9 +1653,6 @@ static void gp_session_validatebuffer(tGPsdata *p)
/* reset flags */
gpd->runtime.sbuffer_sflag = 0;
- /* reset region */
- gpd->runtime.ar = NULL;
-
/* reset inittime */
p->inittime = 0.0;
@@ -1884,7 +1881,6 @@ static bool gp_session_initdata(bContext *C, wmOperator *op, tGPsdata *p)
/* setup active color */
/* region where paint was originated */
- p->gpd->runtime.ar = CTX_wm_region(C);
int totcol = p->ob->totcol;
gp_init_colors(p);
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 96522d1750c..66c0131cd61 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -1157,8 +1157,6 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op)
/* set GP datablock */
tgpi->gpd = gpd;
- /* region where paint was originated */
- tgpi->gpd->runtime.ar = tgpi->region;
/* if brush doesn't exist, create a new set (fix damaged files from old versions) */
if ((paint->brush == NULL) || (paint->brush->gpencil_settings == NULL)) {
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index 26b68707d55..133891cda13 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -1655,7 +1655,50 @@ void GPENCIL_OT_select(wmOperatorType *ot)
}
/* Select by Vertex Color. */
-static bool gpencil_select_color_poll(bContext *C)
+/* Helper to create a hash of colors. */
+static void gpencil_selected_hue_table(bContext *C,
+ Object *ob,
+ const int threshold,
+ GHash *hue_table)
+{
+ const float range = pow(10, 5 - threshold);
+ float hsv[3];
+
+ /* Extract all colors. */
+ CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) {
+ LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+ LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
+ continue;
+ }
+ if (ED_gpencil_stroke_color_use(ob, gpl, gps) == false) {
+ continue;
+ }
+ if ((gps->flag & GP_STROKE_SELECT) == 0) {
+ continue;
+ }
+
+ /* Read all points to get all colors selected. */
+ bGPDspoint *pt;
+ int i;
+ for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+ if (((pt->flag & GP_SPOINT_SELECT) == 0) || (pt->vert_color[3] == 0.0f)) {
+ continue;
+ }
+ /* Round Hue value. */
+ rgb_to_hsv_compat_v(pt->vert_color, hsv);
+ uint key = truncf(hsv[0] * range);
+ if (!BLI_ghash_haskey(hue_table, POINTER_FROM_INT(key))) {
+ BLI_ghash_insert(hue_table, POINTER_FROM_INT(key), POINTER_FROM_INT(key));
+ }
+ }
+ }
+ }
+ }
+ CTX_DATA_END;
+}
+
+static bool gpencil_select_vertex_color_poll(bContext *C)
{
ToolSettings *ts = CTX_data_tool_settings(C);
Object *ob = CTX_data_active_object(C);
@@ -1678,38 +1721,46 @@ static bool gpencil_select_color_poll(bContext *C)
return false;
}
-static int gpencil_select_color_exec(bContext *C, wmOperator *op)
+static int gpencil_select_vertex_color_exec(bContext *C, wmOperator *op)
{
- const float threshold = RNA_float_get(op->ptr, "threshold");
-
ToolSettings *ts = CTX_data_tool_settings(C);
Object *ob = CTX_data_active_object(C);
+
+ const float threshold = RNA_int_get(op->ptr, "threshold");
+ const int selectmode = gpencil_select_mode_from_vertex(ts->gpencil_selectmode_vertex);
bGPdata *gpd = (bGPdata *)ob->data;
- if (!GPENCIL_VERTEX_MODE(gpd)) {
- return OPERATOR_CANCELLED;
- }
+ const float range = pow(10, 5 - threshold);
- Paint *paint = &ts->gp_vertexpaint->paint;
- Brush *brush = paint->brush;
bool done = false;
- float hsv_brush[3], hsv_stroke[3];
- rgb_to_hsv_compat_v(brush->rgb, hsv_brush);
+ /* Create a hash table with all selected colors. */
+ GHash *hue_table = BLI_ghash_int_new(__func__);
+ gpencil_selected_hue_table(C, ob, threshold, hue_table);
+ if (BLI_ghash_len(hue_table) == 0) {
+ BKE_report(op->reports, RPT_ERROR, "Select before some Vertex to use as a filter color");
+ BLI_ghash_free(hue_table, NULL, NULL);
+
+ return OPERATOR_CANCELLED;
+ }
- /* Select any visible stroke that uses this color */
+ /* Select any visible stroke that uses any of these colors. */
CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
bGPDspoint *pt;
int i;
bool gps_selected = false;
/* Check all stroke points. */
for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
- if (pt->vert_color[3] < 0.03f) {
+ if (pt->vert_color[3] == 0.0f) {
continue;
}
- rgb_to_hsv_compat_v(pt->vert_color, hsv_stroke);
- /* Only check Hue to get full value and saturation ranges. */
- if (compare_ff(hsv_stroke[0], hsv_brush[0], threshold)) {
+ /* Only check Hue to get value and saturation full ranges. */
+ float hsv[3];
+ /* Round Hue value. */
+ rgb_to_hsv_compat_v(pt->vert_color, hsv);
+ uint key = truncf(hsv[0] * range);
+
+ if (BLI_ghash_haskey(hue_table, POINTER_FROM_INT(key))) {
pt->flag |= GP_SPOINT_SELECT;
gps_selected = true;
}
@@ -1718,6 +1769,15 @@ static int gpencil_select_color_exec(bContext *C, wmOperator *op)
if (gps_selected) {
gps->flag |= GP_STROKE_SELECT;
done = true;
+
+ /* Extend stroke selection. */
+ if (selectmode == GP_SELECTMODE_STROKE) {
+ bGPDspoint *pt1 = NULL;
+
+ for (i = 0, pt1 = gps->points; i < gps->totpoints; i++, pt1++) {
+ pt1->flag |= GP_SPOINT_SELECT;
+ }
+ }
}
}
CTX_DATA_END;
@@ -1733,27 +1793,41 @@ static int gpencil_select_color_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, NULL);
}
+ /* Free memory. */
+ if (hue_table != NULL) {
+ BLI_ghash_free(hue_table, NULL, NULL);
+ }
+
return OPERATOR_FINISHED;
}
-void GPENCIL_OT_select_color(wmOperatorType *ot)
+void GPENCIL_OT_select_vertex_color(wmOperatorType *ot)
{
PropertyRNA *prop;
/* identifiers */
- ot->name = "Select Color";
- ot->idname = "GPENCIL_OT_select_color";
- ot->description = "Select all strokes with same color";
+ ot->name = "Select Vertex Color";
+ ot->idname = "GPENCIL_OT_select_vertex_color";
+ ot->description = "Select all points with similar vertex color of current selected";
/* callbacks */
- ot->exec = gpencil_select_color_exec;
- ot->poll = gpencil_select_color_poll;
+ ot->exec = gpencil_select_vertex_color_exec;
+ ot->poll = gpencil_select_vertex_color_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
- prop = RNA_def_float(ot->srna, "threshold", 0.01f, 0.0f, 1.0f, "Threshold", "", 0.0f, 1.0f);
+ prop = RNA_def_int(
+ ot->srna,
+ "threshold",
+ 0,
+ 0,
+ 5,
+ "Threshold",
+ "Tolerance of the selection. Higher values select a wider range of similar colors",
+ 0,
+ 5);
/* avoid re-using last var */
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index a975af1c19a..7fe6f374766 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -2583,10 +2583,9 @@ bool ED_gpencil_stroke_check_collision(GP_SpaceConversion *gsc,
bGPDspoint pt_dummy, pt_dummy_ps;
float boundbox_min[2] = {0.0f};
float boundbox_max[2] = {0.0f};
- float zerov3[3];
/* Check we have something to use (only for old files). */
- if (equals_v3v3(zerov3, gps->boundbox_min)) {
+ if (is_zero_v3(gps->boundbox_min)) {
BKE_gpencil_stroke_boundingbox_calc(gps);
}
diff --git a/source/blender/editors/gpencil/gpencil_vertex_paint.c b/source/blender/editors/gpencil/gpencil_vertex_paint.c
index c730d1b493e..45dc22bafba 100644
--- a/source/blender/editors/gpencil/gpencil_vertex_paint.c
+++ b/source/blender/editors/gpencil/gpencil_vertex_paint.c
@@ -104,6 +104,7 @@ typedef struct tGP_BrushVertexpaintData {
bGPdata *gpd;
Brush *brush;
+ float linear_color[3];
eGPDvertex_brush_Flag flag;
eGP_Vertex_SelectMaskFlag mask;
@@ -444,7 +445,7 @@ static bool brush_tint_apply(tGP_BrushVertexpaintData *gso,
/* Premult. */
mul_v3_fl(pt->vert_color, pt->vert_color[3]);
/* "Alpha over" blending. */
- interp_v3_v3v3(pt->vert_color, pt->vert_color, brush->rgb, inf);
+ interp_v3_v3v3(pt->vert_color, pt->vert_color, gso->linear_color, inf);
pt->vert_color[3] = pt->vert_color[3] * (1.0 - inf) + inf;
/* Un-premult. */
if (pt->vert_color[3] > 0.0f) {
@@ -463,7 +464,7 @@ static bool brush_tint_apply(tGP_BrushVertexpaintData *gso,
/* Premult. */
mul_v3_fl(gps->vert_color_fill, gps->vert_color_fill[3]);
/* "Alpha over" blending. */
- interp_v3_v3v3(gps->vert_color_fill, gps->vert_color_fill, brush->rgb, inf_fill);
+ interp_v3_v3v3(gps->vert_color_fill, gps->vert_color_fill, gso->linear_color, inf_fill);
gps->vert_color_fill[3] = gps->vert_color_fill[3] * (1.0 - inf_fill) + inf_fill;
/* Un-premult. */
if (gps->vert_color_fill[3] > 0.0f) {
@@ -483,19 +484,15 @@ static bool brush_replace_apply(tGP_BrushVertexpaintData *gso, bGPDstroke *gps,
/* Apply color to Stroke point. */
if (GPENCIL_TINT_VERTEX_COLOR_STROKE(brush)) {
- copy_v3_v3(pt->vert_color, brush->rgb);
- /* If not mix color, full replace. */
- if (pt->vert_color[3] == 0.0f) {
- pt->vert_color[3] = 1.0f;
+ if (pt->vert_color[3] > 0.0f) {
+ copy_v3_v3(pt->vert_color, gso->linear_color);
}
}
/* Apply color to Fill area (all with same color and factor). */
if (GPENCIL_TINT_VERTEX_COLOR_FILL(brush)) {
- copy_v3_v3(gps->vert_color_fill, brush->rgb);
- /* If not mix color, full replace. */
- if (gps->vert_color_fill[3] == 0.0f) {
- gps->vert_color_fill[3] = 1.0f;
+ if (gps->vert_color_fill[3] > 0.0f) {
+ copy_v3_v3(gps->vert_color_fill, gso->linear_color);
}
}
@@ -731,6 +728,7 @@ static bool gp_vertexpaint_brush_init(bContext *C, wmOperator *op)
op->customdata = gso;
gso->brush = paint->brush;
+ srgb_to_linearrgb_v3_v3(gso->linear_color, gso->brush->rgb);
BKE_curvemapping_initialize(gso->brush->curve);
gso->is_painting = false;