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:
authorJeroen Bakker <jbakker>2022-04-08 17:37:35 +0300
committerJeroen Bakker <jeroen@blender.org>2022-04-08 17:42:50 +0300
commit8b7cd1ed2a17e40661101eea4adae99e8e3d02e9 (patch)
tree8c3f1f2a14d699fad0367ce529254f2efb517acf /source/blender/makesrna
parent63d2980efa2fb170b471e4905ec81cd1472e5268 (diff)
Painting: Canvas switcher for painting brushes/tools.
This patch adds color attributes to TexPaintSlot. This allows an easier selection when painting color attributes. Previously when selecting a paint tool the user had to start a stroke, before the UI reflected the correct TexPaintSlot. Now when switching the slot the active tool is checked and immediate the UI is drawn correctly. In the future the canvas selector will also be used to select an image or image texture node to paint on. Basic implementation has already been done inside this patch. A limitation of this patch is that is isn't possible anymore to rename images directly from the selection panel. This is currently allowed in master. But as CustomDataLayers aren't ID fields and not owned by the material supporting this wouldn't be easy. {F12953989} In the future we should update the create slot operator to also include color attributes. Sources could also be extended to use other areas of the object that use image textures (particles, geom nodes, etc... ). Reviewed By: brecht Maniphest Tasks: T96709 Differential Revision: https://developer.blender.org/D14455
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r--source/blender/makesrna/intern/rna_material.c108
-rw-r--r--source/blender/makesrna/intern/rna_scene.c4
-rw-r--r--source/blender/makesrna/intern/rna_sculpt_paint.c60
-rw-r--r--source/blender/makesrna/intern/rna_workspace.c13
4 files changed, 168 insertions, 17 deletions
diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c
index fc3baa65ef6..15e7e12bbf8 100644
--- a/source/blender/makesrna/intern/rna_material.c
+++ b/source/blender/makesrna/intern/rna_material.c
@@ -8,10 +8,13 @@
#include <stdlib.h>
#include "DNA_material_types.h"
+#include "DNA_mesh_types.h"
#include "DNA_texture_types.h"
#include "BLI_math.h"
+#include "BKE_customdata.h"
+
#include "RNA_define.h"
#include "RNA_enum_types.h"
@@ -136,10 +139,9 @@ static void rna_Material_texpaint_begin(CollectionPropertyIterator *iter, Pointe
iter, (void *)ma->texpaintslot, sizeof(TexPaintSlot), ma->tot_slots, 0, NULL);
}
-static void rna_Material_active_paint_texture_index_update(Main *bmain,
- Scene *UNUSED(scene),
- PointerRNA *ptr)
+static void rna_Material_active_paint_texture_index_update(bContext *C, PointerRNA *ptr)
{
+ Main *bmain = CTX_data_main(C);
bScreen *screen;
Material *ma = (Material *)ptr->owner_id;
@@ -152,26 +154,43 @@ static void rna_Material_active_paint_texture_index_update(Main *bmain,
}
if (ma->texpaintslot) {
- Image *image = ma->texpaintslot[ma->paint_active_slot].ima;
- for (screen = bmain->screens.first; screen; screen = screen->id.next) {
- wmWindow *win = ED_screen_window_find(screen, bmain->wm.first);
- if (win == NULL) {
- continue;
- }
+ TexPaintSlot *slot = &ma->texpaintslot[ma->paint_active_slot];
+ Image *image = slot->ima;
+ if (image) {
+ for (screen = bmain->screens.first; screen; screen = screen->id.next) {
+ wmWindow *win = ED_screen_window_find(screen, bmain->wm.first);
+ if (win == NULL) {
+ continue;
+ }
- ScrArea *area;
- for (area = screen->areabase.first; area; area = area->next) {
- SpaceLink *sl;
- for (sl = area->spacedata.first; sl; sl = sl->next) {
- if (sl->spacetype == SPACE_IMAGE) {
- SpaceImage *sima = (SpaceImage *)sl;
- if (!sima->pin) {
- ED_space_image_set(bmain, sima, image, true);
+ ScrArea *area;
+ for (area = screen->areabase.first; area; area = area->next) {
+ SpaceLink *sl;
+ for (sl = area->spacedata.first; sl; sl = sl->next) {
+ if (sl->spacetype == SPACE_IMAGE) {
+ SpaceImage *sima = (SpaceImage *)sl;
+ if (!sima->pin) {
+ ED_space_image_set(bmain, sima, image, true);
+ }
}
}
}
}
}
+
+ /* For compatibility reasons with vertex paint we activate the color attribute. */
+ if (slot->attribute_name) {
+ Object *ob = CTX_data_active_object(C);
+ if (ob != NULL && ob->type == OB_MESH) {
+ Mesh *mesh = ob->data;
+ CustomDataLayer *layer = BKE_id_attributes_color_find(&mesh->id, slot->attribute_name);
+ if (layer != NULL) {
+ BKE_id_attributes_active_color_set(&mesh->id, layer);
+ }
+ DEG_id_tag_update(&ob->id, 0);
+ WM_main_add_notifier(NC_GEOM | ND_DATA, &ob->id);
+ }
+ }
}
DEG_id_tag_update(&ma->id, 0);
@@ -281,6 +300,49 @@ static void rna_TexPaintSlot_uv_layer_set(PointerRNA *ptr, const char *value)
}
}
+static void rna_TexPaintSlot_name_get(PointerRNA *ptr, char *value)
+{
+ TexPaintSlot *data = (TexPaintSlot *)(ptr->data);
+
+ if (data->ima != NULL) {
+ BLI_strncpy_utf8(value, data->ima->id.name + 2, MAX_NAME);
+ return;
+ }
+
+ if (data->attribute_name != NULL) {
+ BLI_strncpy_utf8(value, data->attribute_name, MAX_NAME);
+ return;
+ }
+
+ value[0] = '\0';
+}
+
+static int rna_TexPaintSlot_name_length(PointerRNA *ptr)
+{
+ TexPaintSlot *data = (TexPaintSlot *)(ptr->data);
+ if (data->ima != NULL) {
+ return strlen(data->ima->id.name) - 2;
+ }
+ if (data->attribute_name != NULL) {
+ return strlen(data->attribute_name);
+ }
+
+ return 0;
+}
+
+static int rna_TexPaintSlot_icon_get(PointerRNA *ptr)
+{
+ TexPaintSlot *data = (TexPaintSlot *)(ptr->data);
+ if (data->ima != NULL) {
+ return ICON_IMAGE;
+ }
+ if (data->attribute_name != NULL) {
+ return ICON_COLOR;
+ }
+
+ return ICON_NONE;
+}
+
static bool rna_is_grease_pencil_get(PointerRNA *ptr)
{
Material *ma = (Material *)ptr->data;
@@ -963,6 +1025,17 @@ static void rna_def_tex_slot(BlenderRNA *brna)
RNA_def_struct_ui_text(
srna, "Texture Paint Slot", "Slot that contains information about texture painting");
+ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_string_funcs(
+ prop, "rna_TexPaintSlot_name_get", "rna_TexPaintSlot_name_length", NULL);
+ RNA_def_property_ui_text(prop, "Name", "Name of the slot");
+
+ prop = RNA_def_property(srna, "icon_value", PROP_INT, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_int_funcs(prop, "rna_TexPaintSlot_icon_get", NULL, NULL);
+ RNA_def_property_ui_text(prop, "Icon", "Paint slot icon");
+
prop = RNA_def_property(srna, "uv_layer", PROP_STRING, PROP_NONE);
RNA_def_property_string_maxlength(prop, 64); /* else it uses the pointer size! */
RNA_def_property_string_sdna(prop, NULL, "uvname");
@@ -1019,6 +1092,7 @@ void rna_def_texpaint_slots(BlenderRNA *brna, StructRNA *srna)
RNA_def_property_range(prop, 0, SHRT_MAX);
RNA_def_property_ui_text(
prop, "Active Paint Texture Index", "Index of active texture paint slot");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(
prop, NC_MATERIAL | ND_SHADING_LINKS, "rna_Material_active_paint_texture_index_update");
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index fa34e7a40c0..7f0a9627a17 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -3049,6 +3049,10 @@ static void rna_def_tool_settings(BlenderRNA *brna)
RNA_def_property_pointer_sdna(prop, NULL, "imapaint");
RNA_def_property_ui_text(prop, "Image Paint", "");
+ prop = RNA_def_property(srna, "paint_mode", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "paint_mode");
+ RNA_def_property_ui_text(prop, "Paint Mode", "");
+
prop = RNA_def_property(srna, "uv_sculpt", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "uvsculpt");
RNA_def_property_ui_text(prop, "UV Sculpt", "");
diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c
index 1ea7b35cedb..37c687ddb2b 100644
--- a/source/blender/makesrna/intern/rna_sculpt_paint.c
+++ b/source/blender/makesrna/intern/rna_sculpt_paint.c
@@ -84,6 +84,13 @@ static const EnumPropertyItem rna_enum_gpencil_paint_mode[] = {
};
#endif
+static const EnumPropertyItem rna_enum_canvas_source_items[] = {
+ {PAINT_CANVAS_SOURCE_COLOR_ATTRIBUTE, "COLOR_ATTRIBUTE", 0, "Color Attribute", ""},
+ {PAINT_CANVAS_SOURCE_MATERIAL, "MATERIAL", 0, "Material", ""},
+ {PAINT_CANVAS_SOURCE_IMAGE, "IMAGE", 0, "Image", ""},
+ {0, NULL, 0, NULL, NULL},
+};
+
const EnumPropertyItem rna_enum_symmetrize_direction_items[] = {
{BMO_SYMMETRIZE_NEGATIVE_X, "NEGATIVE_X", 0, "-X to +X", ""},
{BMO_SYMMETRIZE_POSITIVE_X, "POSITIVE_X", 0, "+X to -X", ""},
@@ -418,6 +425,11 @@ static char *rna_ImagePaintSettings_path(PointerRNA *UNUSED(ptr))
return BLI_strdup("tool_settings.image_paint");
}
+static char *rna_PaintModeSettings_path(PointerRNA *UNUSED(ptr))
+{
+ return BLI_strdup("tool_settings.paint_mode");
+}
+
static char *rna_UvSculpt_path(PointerRNA *UNUSED(ptr))
{
return BLI_strdup("tool_settings.uv_sculpt");
@@ -537,6 +549,30 @@ static void rna_ImaPaint_canvas_update(bContext *C, PointerRNA *UNUSED(ptr))
}
}
+/** \name Paint mode settings
+ * \{ */
+
+static bool rna_PaintModeSettings_canvas_image_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
+{
+ Image *image = (Image *)value.owner_id;
+ return !ELEM(image->type, IMA_TYPE_COMPOSITE, IMA_TYPE_R_RESULT);
+}
+
+static void rna_PaintModeSettings_canvas_source_update(bContext *C, PointerRNA *UNUSED(ptr))
+{
+ Scene *scene = CTX_data_scene(C);
+ Object *ob = CTX_data_active_object(C);
+ /* When canvas source changes the pbvh would require updates when switching between color
+ * attributes. */
+ if (ob && ob->type == OB_MESH) {
+ BKE_texpaint_slots_refresh_object(scene, ob);
+ DEG_id_tag_update(&ob->id, 0);
+ WM_main_add_notifier(NC_GEOM | ND_DATA, &ob->id);
+ }
+}
+
+/* \} */
+
static bool rna_ImaPaint_detect_data(ImagePaintSettings *imapaint)
{
return imapaint->missing_data == 0;
@@ -964,6 +1000,29 @@ static void rna_def_vertex_paint(BlenderRNA *brna)
prop, "Radial Symmetry Count X Axis", "Number of times to copy strokes across the surface");
}
+static void rna_def_paint_mode(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "PaintModeSettings", NULL);
+ RNA_def_struct_sdna(srna, "PaintModeSettings");
+ RNA_def_struct_path_func(srna, "rna_PaintModeSettings_path");
+ RNA_def_struct_ui_text(srna, "Paint Mode", "Properties of paint mode");
+
+ prop = RNA_def_property(srna, "canvas_source", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, rna_enum_canvas_source_items);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_ui_text(prop, "Source", "Source to select canvas from");
+ RNA_def_property_update(prop, 0, "rna_PaintModeSettings_canvas_source_update");
+
+ prop = RNA_def_property(srna, "canvas_image", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_funcs(
+ prop, NULL, NULL, NULL, "rna_PaintModeSettings_canvas_image_poll");
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_CONTEXT_UPDATE);
+ RNA_def_property_ui_text(prop, "Texture", "Image used as as painting target");
+}
+
static void rna_def_image_paint(BlenderRNA *brna)
{
StructRNA *srna;
@@ -1551,6 +1610,7 @@ void RNA_def_sculpt_paint(BlenderRNA *brna)
rna_def_gp_sculptpaint(brna);
rna_def_gp_weightpaint(brna);
rna_def_vertex_paint(brna);
+ rna_def_paint_mode(brna);
rna_def_image_paint(brna);
rna_def_particle_edit(brna);
rna_def_gpencil_guides(brna);
diff --git a/source/blender/makesrna/intern/rna_workspace.c b/source/blender/makesrna/intern/rna_workspace.c
index f32a74be6e2..0b6c3934985 100644
--- a/source/blender/makesrna/intern/rna_workspace.c
+++ b/source/blender/makesrna/intern/rna_workspace.c
@@ -32,6 +32,7 @@
# include "DNA_space_types.h"
# include "ED_asset.h"
+# include "ED_paint.h"
# include "RNA_access.h"
@@ -180,6 +181,12 @@ const EnumPropertyItem *rna_WorkSpace_tools_mode_itemf(bContext *UNUSED(C),
return DummyRNA_DEFAULT_items;
}
+static bool rna_WorkSpaceTool_use_paint_canvas_get(PointerRNA *ptr)
+{
+ bToolRef *tref = ptr->data;
+ return ED_paint_tool_use_canvas(NULL, tref);
+}
+
static int rna_WorkSpaceTool_index_get(PointerRNA *ptr)
{
bToolRef *tref = ptr->data;
@@ -291,6 +298,12 @@ static void rna_def_workspace_tool(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Tool Mode", "");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ prop = RNA_def_property(srna, "use_paint_canvas", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Index", "");
+ RNA_def_property_boolean_funcs(prop, "rna_WorkSpaceTool_use_paint_canvas_get", NULL);
+ RNA_def_property_ui_text(prop, "Use Paint Canvas", "Does this tool use an painting canvas");
+
RNA_define_verify_sdna(0);
prop = RNA_def_property(srna, "has_datablock", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);