64 bool is_selected =
false;
73 bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
75 if ((gpf == gpl->actframe) || ((gpf->flag &
GP_FRAME_SELECT) && (is_multiedit))) {
86 if (gps->editcurve ==
NULL) {
145 brightness /= 100.0f;
146 float delta = contrast / 200.0f;
153 gain = 1.0f - delta * 2.0f;
154 gain = 1.0f /
max_ff(gain, FLT_EPSILON);
155 offset = gain * (brightness - delta);
159 gain =
max_ff(1.0f - delta * 2.0f, 0.0f);
160 offset = gain * brightness + delta;
165 bool changed =
false;
167 bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
170 if ((gpf == gpl->actframe) || ((gpf->flag &
GP_FRAME_SELECT) && (is_multiedit))) {
184 if (gps->vert_color_fill[3] > 0.0f) {
186 for (
int i2 = 0; i2 < 3; i2++) {
187 gps->vert_color_fill[i2] = gain * gps->vert_color_fill[i2] + offset;
196 for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
199 for (
int i2 = 0; i2 < 3; i2++) {
230 ot->
name =
"Vertex Paint Brightness/Contrast";
231 ot->
idname =
"GPENCIL_OT_vertex_color_brightness_contrast";
244 const float min = -100,
max = +100;
262 bool changed =
false;
264 bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
267 if ((gpf == gpl->actframe) || ((gpf->flag &
GP_FRAME_SELECT) && (is_multiedit))) {
283 if (gps->vert_color_fill[3] > 0.0f) {
288 hsv[0] += (hue - 0.5f);
292 else if (hsv[0] < 0.0f) {
307 for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
312 hsv[0] += (hue - 0.5f);
316 else if (hsv[0] < 0.0f) {
350 ot->
name =
"Vertex Paint Hue Saturation Value";
351 ot->
idname =
"GPENCIL_OT_vertex_color_hsv";
378 bool changed =
false;
380 bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
383 if ((gpf == gpl->actframe) || ((gpf->flag &
GP_FRAME_SELECT) && (is_multiedit))) {
397 if (gps->vert_color_fill[3] > 0.0f) {
399 for (
int i2 = 0; i2 < 3; i2++) {
400 gps->vert_color_fill[i2] = 1.0f - gps->vert_color_fill[i2];
411 for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
414 for (
int i2 = 0; i2 < 3; i2++) {
443 ot->
name =
"Vertex Paint Invert";
444 ot->
idname =
"GPENCIL_OT_vertex_color_invert";
470 bool changed =
false;
472 bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
475 if ((gpf == gpl->actframe) || ((gpf->flag &
GP_FRAME_SELECT) && (is_multiedit))) {
489 if (gps->vert_color_fill[3] > 0.0f) {
491 for (
int i2 = 0; i2 < 3; i2++) {
492 gps->vert_color_fill[i2] = gain * (gps->vert_color_fill[i2] + offset);
502 for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
505 for (
int i2 = 0; i2 < 3; i2++) {
535 ot->
name =
"Vertex Paint Levels";
536 ot->
idname =
"GPENCIL_OT_vertex_color_levels";
551 ot->
srna,
"offset", 0.0f, -1.0f, 1.0f,
"Offset",
"Value to add to colors", -1.0f, 1.0f);
553 ot->
srna,
"gain", 1.0f, 0.0f, FLT_MAX,
"Gain",
"Value to multiply colors by", 0.0f, 10.0f);
562 Brush *brush = paint->brush;
569 bool changed =
false;
571 bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
574 if ((gpf == gpl->actframe) || ((gpf->flag &
GP_FRAME_SELECT) && (is_multiedit))) {
590 gps->vert_color_fill[3] = factor;
599 for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
630 ot->
name =
"Vertex Paint Set Color";
631 ot->
idname =
"GPENCIL_OT_vertex_color_set";
644 RNA_def_float(
ot->
srna,
"factor", 1.0f, 0.001f, 1.0f,
"Factor",
"Mix Factor", 0.001f, 1.0f);
655 const float range =
pow(10.0f, threshold);
671 if (gp_style ==
NULL) {
683 if ((!use_fill) && (!use_stroke)) {
699 if (gps->vert_color_fill[3] > 0.0f) {
700 col[0] = truncf(gps->vert_color_fill[0] * range) / range;
701 col[1] = truncf(gps->vert_color_fill[1] * range) / range;
702 col[2] = truncf(gps->vert_color_fill[2] * range) / range;
714 for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
751 if ((use_stroke) && (use_fill)) {
752 switch (gp_style->
mode) {
755 strcpy(name,
"Line Stroke-Fill");
760 strcpy(name,
"Dots Stroke-Fill");
765 strcpy(name,
"Squares Stroke-Fill");
772 else if (use_stroke) {
773 switch (gp_style->
mode) {
776 strcpy(name,
"Line Stroke");
781 strcpy(name,
"Dots Stroke");
786 strcpy(name,
"Squares Stroke");
795 strcpy(name,
"Solid Fill");
834 bool changed =
false;
842 int totmat = *totcol;
861 if (gp_style ==
NULL) {
872 if ((!use_fill) && (!use_stroke)) {
895 for (i = 0; i < totmat; i++) {
896 mat_elm = &mat_table[i];
897 if (mat_elm->
ma ==
NULL) {
900 if (key == mat_elm->
key) {
934 mat_elm = &mat_table[i];
938 gps->mat_nr = mat_elm->
index;
943 gps->vert_color_fill[3] = 1.0f;
948 for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
983 ot->
name =
"Convert Stroke Materials to Vertex Color";
984 ot->
idname =
"GPENCIL_OT_material_to_vertex_color";
985 ot->
description =
"Replace materials in strokes with Vertex Color";
998 "Remove Unused Materials",
999 "Remove any unused material after the conversion");
1035 ot->
name =
"Extract Palette from Vertex Color";
1036 ot->
idname =
"GPENCIL_OT_extract_palette_vertex";
1037 ot->
description =
"Extract all colors used in Grease Pencil Vertex and create a Palette";
1048 ot->
srna,
"selected",
false,
"Only Selected",
"Convert only selected strokes");
1064 for (
int i = 0; i < gps->
totpoints; i++) {
1083 bool changed =
false;
1085 bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
1088 if ((gpf == gpl->actframe) || ((gpf->flag &
GP_FRAME_SELECT) && (is_multiedit))) {
1099 if (is_curve_edit) {
1100 if (gps->editcurve ==
NULL) {
1117 if (!is_multiedit) {
1141 {
GPPAINT_MODE_BOTH,
"BOTH", 0,
"Stroke and Fill",
"Reset Vertex Color to Stroke and Fill"},
1146 ot->
name =
"Reset Vertex Color";
1147 ot->
idname =
"GPENCIL_OT_stroke_reset_vertex_color";
1148 ot->
description =
"Reset vertex color for all or selected strokes";
#define CTX_DATA_BEGIN(C, Type, instance, member)
struct Object * CTX_data_active_object(const bContext *C)
struct Main * CTX_data_main(const bContext *C)
struct ToolSettings * CTX_data_tool_settings(const bContext *C)
General operations, lookup, etc. for materials.
struct MaterialGPencilStyle * BKE_gpencil_material_settings(struct Object *ob, short act)
@ BKE_MAT_ASSIGN_USERPREF
struct Material * BKE_gpencil_material_add(struct Main *bmain, const char *name)
void BKE_object_material_assign(struct Main *bmain, struct Object *ob, struct Material *ma, short act, int assign_type)
bool BKE_object_material_slot_add(struct Main *bmain, struct Object *ob)
short * BKE_object_material_len_p(struct Object *ob)
bool BKE_palette_from_hash(struct Main *bmain, struct GHash *color_table, const char *name, const bool linear)
void BKE_reportf(ReportList *reports, ReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
bool BLI_ghash_haskey(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
GHash * BLI_ghash_int_new(const char *info) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
void BLI_ghash_insert(GHash *gh, void *key, void *val)
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
#define LISTBASE_FOREACH(type, var, list)
MINLINE float max_ff(float a, float b)
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
unsigned int rgb_to_cpack(float r, float g, float b)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void zero_v4(float r[4])
#define POINTER_FROM_INT(i)
void DEG_id_tag_update(struct ID *id, int flag)
@ ID_RECALC_COPY_ON_WRITE
#define GPENCIL_ANY_VERTEX_MASK(flag)
#define GPENCIL_VERTEX_MODE(gpd)
#define GPENCIL_MULTIEDIT_SESSIONS_ON(gpd)
#define GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)
@ GP_MATERIAL_STROKE_PATTERN
@ GP_MATERIAL_STROKE_SHOW
@ GP_MATERIAL_MODE_SQUARE
@ GP_MATERIAL_STROKE_STYLE_TEXTURE
@ GP_MATERIAL_FILL_STYLE_SOLID
Read Guarded memory(de)allocation.
@ WM_OP_INVOKE_REGION_WIN
bool ED_gpencil_stroke_material_editable(Object *ob, const bGPDlayer *gpl, const bGPDstroke *gps)
bool ED_gpencil_stroke_can_use(const bContext *C, const bGPDstroke *gps)
static int gpencil_material_to_vertex_exec(bContext *C, wmOperator *op)
static bool gpencil_vertexpaint_mode_poll(bContext *C)
static int gpencil_vertexpaint_hsv_exec(bContext *C, wmOperator *op)
static int gpencil_vertexpaint_set_exec(bContext *C, wmOperator *op)
static int gpencil_vertexpaint_brightness_contrast_exec(bContext *C, wmOperator *op)
static const EnumPropertyItem gpencil_modesEnumPropertyItem_mode[]
static int gpencil_stroke_reset_vertex_color_exec(bContext *C, wmOperator *op)
static bool gpencil_extract_palette_vertex_poll(bContext *C)
static int gpencil_vertexpaint_invert_exec(bContext *C, wmOperator *op)
void GPENCIL_OT_stroke_reset_vertex_color(wmOperatorType *ot)
static uint get_material_type(MaterialGPencilStyle *gp_style, bool use_stroke, bool use_fill, char *name)
static int gpencil_vertexpaint_levels_exec(bContext *C, wmOperator *op)
static void gpencil_reset_vertex(bGPDstroke *gps, eGp_Vertex_Mode mode)
void GPENCIL_OT_vertex_color_levels(wmOperatorType *ot)
static bool gpencil_material_to_vertex_poll(bContext *C)
void GPENCIL_OT_vertex_color_invert(wmOperatorType *ot)
void GPENCIL_OT_vertex_color_hsv(wmOperatorType *ot)
void GPENCIL_OT_vertex_color_brightness_contrast(wmOperatorType *ot)
static bool gpencil_extract_palette_from_vertex(bContext *C, const bool selected, const int threshold)
static bool is_any_stroke_selected(bContext *C, const bool is_multiedit, const bool is_curve_edit)
void GPENCIL_OT_vertex_color_set(wmOperatorType *ot)
struct GPMatArray GPMatArray
void GPENCIL_OT_material_to_vertex_color(wmOperatorType *ot)
static int gpencil_extract_palette_vertex_exec(bContext *C, wmOperator *op)
void GPENCIL_OT_extract_palette_vertex(wmOperatorType *ot)
void *(* MEM_calloc_arrayN)(size_t len, size_t size, const char *str)
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
int RNA_int_get(PointerRNA *ptr, const char *name)
float RNA_float_get(PointerRNA *ptr, const char *name)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, const char *ui_name, const char *ui_description)
struct MaterialGPencilStyle * gp_style
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports
int WM_operator_name_call(bContext *C, const char *opstring, short context, PointerRNA *properties)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)