[Bf-blender-cvs] [2875fb9e7bb] blender2.8: Texture Paint: Don't create material if operation is cancelled

Jacques Lucke noreply at git.blender.org
Mon Oct 15 13:53:39 CEST 2018


Commit: 2875fb9e7bbc183ae2c40f9e0c8961ace12e767e
Author: Jacques Lucke
Date:   Mon Oct 15 13:53:14 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB2875fb9e7bbc183ae2c40f9e0c8961ace12e767e

Texture Paint: Don't create material if operation is cancelled

Reviewers: brecht

Differential Revision: https://developer.blender.org/D3793

===================================================================

M	source/blender/editors/sculpt_paint/paint_image_proj.c

===================================================================

diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index b5f9104f023..28a48562264 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -5827,46 +5827,57 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op)
 	return false;
 }
 
-static int texture_paint_add_texture_paint_slot_exec(bContext *C, wmOperator *op)
+static int get_texture_layer_type(wmOperator *op, const char *prop_name)
 {
-	if (proj_paint_add_slot(C, op)) {
-		return OPERATOR_FINISHED;
-	}
-	else {
-		return OPERATOR_CANCELLED;
-	}
+	int type_value = RNA_enum_get(op->ptr, prop_name);
+	int type = RNA_enum_from_value(layer_type_items, type_value);
+	BLI_assert(type != -1);
+	return type;
 }
 
-
-static int texture_paint_add_texture_paint_slot_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+static Material *get_or_create_current_material(bContext *C, Object *ob)
 {
-	char imagename[MAX_ID_NAME - 2];
-	Main *bmain = CTX_data_main(C);
-	Object *ob = ED_object_active_context(C);
 	Material *ma = give_current_material(ob, ob->actcol);
-	int type = RNA_enum_get(op->ptr, "type");
-
 	if (!ma) {
+		Main *bmain = CTX_data_main(C);
 		ma = BKE_material_add(bmain, "Material");
-		/* no material found, just assign to first slot */
 		assign_material(bmain, ob, ma, ob->actcol, BKE_MAT_ASSIGN_USERPREF);
 	}
+	return ma;
+}
 
-	if (!ma->nodetree) {
-		ED_node_shader_default(C, &ma->id);
-	}
+static int texture_paint_add_texture_paint_slot_exec(bContext *C, wmOperator *op)
+{
+	Object *ob = ED_object_active_context(C);
+	Material *ma = get_or_create_current_material(C, ob);
 
+	int type = get_texture_layer_type(op, "type");
 	proj_paint_default_color(op, type, ma);
 
-	type = RNA_enum_from_value(layer_type_items, type);
+	if (proj_paint_add_slot(C, op)) {
+		return OPERATOR_FINISHED;
+	}
+	else {
+		return OPERATOR_CANCELLED;
+	}
+}
 
-	/* get the name of the texture layer type */
-	BLI_assert(type != -1);
+static void get_default_texture_layer_name_for_object(Object *ob, int texture_type, char *dst, int dst_length)
+{
+	Material *ma = give_current_material(ob, ob->actcol);
+	const char *base_name = ma ? &ma->id.name[2] : &ob->id.name[2];
+	BLI_snprintf(dst, dst_length, "%s %s", base_name, layer_type_items[texture_type].name);
+}
 
-	/* take the second letter to avoid the ID identifier */
-	BLI_snprintf(imagename, sizeof(imagename), "%s %s", &ma->id.name[2], layer_type_items[type].name);
+static int texture_paint_add_texture_paint_slot_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+	Object *ob = ED_object_active_context(C);
+	int type = get_texture_layer_type(op, "type");
 
+	char imagename[MAX_ID_NAME - 2];
+	get_default_texture_layer_name_for_object(ob, type, (char *)&imagename, sizeof(imagename));
 	RNA_string_set(op->ptr, "name", imagename);
+
 	return WM_operator_props_dialog_popup(C, op, 15 * UI_UNIT_X, 5 * UI_UNIT_Y);
 }



More information about the Bf-blender-cvs mailing list