[Bf-blender-cvs] [db84495] master: Add operator that deletes a texture paint layer for blender internal.

Antony Riakiotakis noreply at git.blender.org
Tue Aug 26 19:00:39 CEST 2014


Commit: db844959d18e21e8fbb6f1f3a425b757d0dcb05b
Author: Antony Riakiotakis
Date:   Tue Aug 26 19:00:25 2014 +0200
Branches: master
https://developer.blender.org/rBdb844959d18e21e8fbb6f1f3a425b757d0dcb05b

Add operator that deletes a texture paint layer for blender internal.

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/intern/material.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/sculpt_paint/paint_intern.h
M	source/blender/editors/sculpt_paint/paint_ops.c
M	source/blender/makesdna/DNA_material_types.h
M	source/blender/makesrna/intern/rna_material.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index e91ec59..31e7f60 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1038,12 +1038,16 @@ class VIEW3D_PT_slots_projectpaint(View3DPanel, Panel):
                               mat, "paint_active_slot", rows=2)
 
             if (not mat.use_nodes) and (context.scene.render.engine == 'BLENDER_RENDER'):
-                col.operator_menu_enum("paint.add_texture_paint_slot", "type")
+                row = col.row(align=True)
+                row.operator_menu_enum("paint.add_texture_paint_slot", "type")
+                row.operator("paint.delete_texture_paint_slot", text="", icon='X')
 
-                slot = mat.texture_paint_slots[mat.paint_active_slot]
-                col.separator()
-                col.label("UV Map")
-                col.prop_search(slot, "uv_layer", ob.data, "uv_textures", text="")
+                if mat.texture_paint_slots:
+                    slot = mat.texture_paint_slots[mat.paint_active_slot]
+
+                    col.separator()
+                    col.label("UV Map")
+                    col.prop_search(slot, "uv_layer", ob.data, "uv_textures", text="")
 
         col.separator()
         col.operator("image.save_dirty", text="Save All Images")
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index ab33c2b..6daf000 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -1388,7 +1388,10 @@ void BKE_texpaint_slot_refresh_cache(Material *ma, bool use_nodes)
 		for (mtex = ma->mtex, i = 0; i < MAX_MTEX; i++, mtex++) {
 			if (get_mtex_slot_valid_texpaint(*mtex)) {
 				ma->texpaintslot[index].ima = (*mtex)->tex->ima;
-				ma->texpaintslot[index++].uvname = (*mtex)->uvname;
+				ma->texpaintslot[index].uvname = (*mtex)->uvname;
+				ma->texpaintslot[index].mtex = *mtex;
+				
+				index++;
 			}
 		}
 	}
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 643e4aa..614c166 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -4966,3 +4966,59 @@ void PAINT_OT_add_texture_paint_slot(wmOperatorType *ot)
 	             "Generated Type", "Fill the image with a grid for UV map testing");
 	RNA_def_boolean(ot->srna, "float", 0, "32 bit Float", "Create image with 32 bit floating point bit depth");
 }
+
+static int texture_paint_delete_texture_paint_slot_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	Object *ob = CTX_data_active_object(C);
+	Scene *scene = CTX_data_scene(C);
+	Material *ma;
+	bool use_nodes = BKE_scene_use_new_shading_nodes(scene);
+	TexPaintSlot *slot;
+	int i;
+	
+	/* not supported for node-based engines */
+	if (!ob || use_nodes)
+		return OPERATOR_CANCELLED;
+	
+	ma = give_current_material(ob, ob->actcol);
+	
+	if (!ma->texpaintslot)
+		return OPERATOR_CANCELLED;
+	
+	slot = ma->texpaintslot + ma->paint_active_slot;
+	
+	/* find the material texture slot that corresponds to the current slot */
+	for (i = 0; i < MAX_MTEX; i++) {
+		if (ma->mtex[i] == slot->mtex) {
+			if (ma->mtex[i]->tex)
+				id_us_min(&ma->mtex[i]->tex->id);
+			MEM_freeN(ma->mtex[i]);
+			ma->mtex[i] = NULL;
+			
+			BKE_texpaint_slot_refresh_cache(ma, false);
+			DAG_id_tag_update(&ma->id, 0);
+			WM_event_add_notifier(C, NC_MATERIAL, CTX_data_scene(C));
+			/* we need a notifier for data change since we change the displayed modifier uvs */
+			WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);			
+			return OPERATOR_FINISHED;
+		}
+	}
+	
+	return OPERATOR_CANCELLED;
+}
+
+
+void PAINT_OT_delete_texture_paint_slot(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Delete Texture Paint Slot";
+	ot->description = "Add a texture paint slot";
+	ot->idname = "PAINT_OT_delete_texture_paint_slot";
+
+	/* api callbacks */
+	ot->exec = texture_paint_delete_texture_paint_slot_exec;
+	ot->poll = ED_operator_region_view3d_active;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index 57285ad..8d42bbb 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -184,6 +184,7 @@ void PAINT_OT_texture_paint_toggle(struct wmOperatorType *ot);
 void PAINT_OT_project_image(struct wmOperatorType *ot);
 void PAINT_OT_image_from_view(struct wmOperatorType *ot);
 void PAINT_OT_add_texture_paint_slot(struct wmOperatorType *ot);
+void PAINT_OT_delete_texture_paint_slot(struct wmOperatorType *ot);
 void PAINT_OT_image_paint(struct wmOperatorType *ot);
 
 /* uv sculpting */
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index 3605ce5..90161fa 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -1083,6 +1083,7 @@ void ED_operatortypes_paint(void)
 	WM_operatortype_append(PAINT_OT_image_from_view);
 	WM_operatortype_append(PAINT_OT_brush_colors_flip);
 	WM_operatortype_append(PAINT_OT_add_texture_paint_slot);
+	WM_operatortype_append(PAINT_OT_delete_texture_paint_slot);
 
 	/* weight */
 	WM_operatortype_append(PAINT_OT_weight_paint_toggle);
diff --git a/source/blender/makesdna/DNA_material_types.h b/source/blender/makesdna/DNA_material_types.h
index ba617ba..bd791c9 100644
--- a/source/blender/makesdna/DNA_material_types.h
+++ b/source/blender/makesdna/DNA_material_types.h
@@ -86,6 +86,7 @@ typedef struct GameSettings {
 typedef struct TexPaintSlot {
 	struct Image *ima; /* image to be painted on */
 	char *uvname; /* customdata index for uv layer, MAX_NAME*/
+	struct MTex *mtex; /* hook for blender internal materials. Not terribily nice, but serves for usability now  */
 } TexPaintSlot;
 
 typedef struct Material {
diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c
index 70da4ab..4031c70 100644
--- a/source/blender/makesrna/intern/rna_material.c
+++ b/source/blender/makesrna/intern/rna_material.c
@@ -2211,7 +2211,9 @@ static void rna_def_tex_slot(BlenderRNA *brna)
 	RNA_def_property_string_sdna(prop, NULL, "uvname");
 	RNA_def_property_ui_text(prop, "UV Map", "Name of UV map");
 	RNA_def_property_update(prop, NC_GEOM | ND_DATA, "rna_Material_update");
-
+	
+	prop = RNA_def_property(srna, "mtex", PROP_POINTER, PROP_NONE);
+	RNA_def_property_struct_type(prop, "MaterialTextureSlot");
 }




More information about the Bf-blender-cvs mailing list