From 029be6f4b58f9af01dda9e8974a6d1a275ef5c4a Mon Sep 17 00:00:00 2001 From: Antony Riakiotakis Date: Thu, 24 Jul 2014 12:01:25 +0200 Subject: Change to previous commit, allow tweaking name at creation time. --- source/blender/editors/sculpt_paint/paint_image.c | 4 +-- .../editors/sculpt_paint/paint_image_proj.c | 40 ++++++++++++++-------- source/blender/editors/sculpt_paint/paint_intern.h | 2 +- 3 files changed, 28 insertions(+), 18 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 21def9fe6d4..f1a2a8156d8 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -1372,7 +1372,7 @@ void paint_proj_mesh_data_ensure(bContext *C, Object *ob, wmOperator *op) if (ma) { has_material = true; if (!ma->texpaintslot) { - proj_paint_add_slot(C, MAP_COL, ma, NULL); + proj_paint_add_slot(C, ma, NULL); } } } @@ -1385,7 +1385,7 @@ void paint_proj_mesh_data_ensure(bContext *C, Object *ob, wmOperator *op) Material *ma = BKE_material_add(CTX_data_main(C), "Material"); /* no material found, just assign to first slot */ assign_material(ob, ma, 1, BKE_MAT_ASSIGN_USERPREF); - proj_paint_add_slot(C, MAP_COL, ma, NULL); + proj_paint_add_slot(C, ma, NULL); } me = BKE_mesh_from_object(ob); diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 08cc964741e..8dfab793734 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -4816,11 +4816,10 @@ static EnumPropertyItem layer_type_items[] = { {0, NULL, 0, NULL, NULL} }; -bool proj_paint_add_slot(bContext *C, int type, Material *ma, wmOperator *op) +bool proj_paint_add_slot(bContext *C, Material *ma, wmOperator *op) { Object *ob = CTX_data_active_object(C); Scene *scene = CTX_data_scene(C); - int i; bool use_nodes = BKE_scene_use_new_shading_nodes(scene); if (!ob) @@ -4841,19 +4840,17 @@ bool proj_paint_add_slot(bContext *C, int type, Material *ma, wmOperator *op) if (mtex) { Main *bmain = CTX_data_main(C); Image *ima; - const char *name; + int type = MAP_COL; - /* get the name of the texture layer type */ - i = RNA_enum_from_value(layer_type_items, type); - BLI_assert(i != -1); - name = layer_type_items[i].name; + if (op) + type = RNA_enum_get(op->ptr, "type"); - mtex->tex = add_texture(bmain, DATA_(name)); + mtex->tex = add_texture(bmain, DATA_(layer_type_items[type].name)); mtex->mapto = type; if (mtex->tex) { - char imagename[FILE_MAX]; float color[4]; + char imagename[MAX_ID_NAME - 2] = "Material Diffuse Color"; int width = 1024; int height = 1024; bool use_float = false; @@ -4867,6 +4864,7 @@ bool proj_paint_add_slot(bContext *C, int type, Material *ma, wmOperator *op) gen_type = RNA_enum_get(op->ptr, "generated_type"); RNA_float_get_array(op->ptr, "color", color); alpha = RNA_boolean_get(op->ptr, "alpha"); + RNA_string_get(op->ptr, "name", imagename); } if (!use_float) { @@ -4875,9 +4873,6 @@ bool proj_paint_add_slot(bContext *C, int type, Material *ma, wmOperator *op) color[3] = 1.0; } - /* take the second letter to avoid the ID identifier */ - BLI_snprintf(imagename, FILE_MAX, "%s_%s", &ma->id.name[2], name); - ima = mtex->tex->ima = BKE_image_add_generated(bmain, width, height, imagename, alpha ? 32 : 24, use_float, gen_type, color); @@ -4899,17 +4894,31 @@ bool proj_paint_add_slot(bContext *C, int type, Material *ma, wmOperator *op) static int texture_paint_add_texture_paint_slot_exec(bContext *C, wmOperator *op) { - int type = RNA_enum_get(op->ptr, "type"); - - return proj_paint_add_slot(C, type, NULL, op); + return proj_paint_add_slot(C, NULL, op); } static int texture_paint_add_texture_paint_slot_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { + char imagename[MAX_ID_NAME - 2]; + Object *ob = CTX_data_active_object(C); + Material *ma = give_current_material(ob, ob->actcol); + int type = RNA_enum_get(op->ptr, "type"); + + type = RNA_enum_from_value(layer_type_items, type); + + /* get the name of the texture layer type */ + BLI_assert(type != -1); + + /* take the second letter to avoid the ID identifier */ + BLI_snprintf(imagename, FILE_MAX, "%s %s", &ma->id.name[2], layer_type_items[type].name); + + RNA_string_set(op->ptr, "name", imagename); return WM_operator_props_dialog_popup(C, op, 15 * UI_UNIT_X, 5 * UI_UNIT_Y); } +#define IMA_DEF_NAME N_("Untitled") + void PAINT_OT_add_texture_paint_slot(wmOperatorType *ot) { @@ -4932,6 +4941,7 @@ void PAINT_OT_add_texture_paint_slot(wmOperatorType *ot) /* properties */ prop = RNA_def_enum(ot->srna, "type", layer_type_items, 0, "Type", "Merge method to use"); RNA_def_property_flag(prop, PROP_HIDDEN); + RNA_def_string(ot->srna, "name", IMA_DEF_NAME, MAX_ID_NAME - 2, "Name", "Image datablock name"); prop = RNA_def_int(ot->srna, "width", 1024, 1, INT_MAX, "Width", "Image width", 1, 16384); RNA_def_property_subtype(prop, PROP_PIXEL); prop = RNA_def_int(ot->srna, "height", 1024, 1, INT_MAX, "Height", "Image height", 1, 16384); diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 921992ed2f9..fb4bedb6906 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -169,7 +169,7 @@ void paint_proj_stroke(const struct bContext *C, void *ps, const float prevmval_ void paint_proj_redraw(const struct bContext *C, void *pps, bool final); void paint_proj_stroke_done(void *ps); void paint_proj_mesh_data_ensure(bContext *C, struct Object *ob, struct wmOperator *op); -bool proj_paint_add_slot(bContext *C, int type, struct Material *ma, struct wmOperator *op); +bool proj_paint_add_slot(bContext *C, struct Material *ma, struct wmOperator *op); void paint_brush_color_get(struct Scene *scene, struct Brush *br, bool color_correction, bool invert, float distance, float pressure, float color[3], struct ColorManagedDisplay *display); bool paint_use_opacity_masking(struct Brush *brush); -- cgit v1.2.3