[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30159] branches/soc-2010-kwk: This commit enables the "Auto-Select-Image" feature.

Konrad Kleine konrad at konradwilhelm.de
Fri Jul 9 22:06:58 CEST 2010


Revision: 30159
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30159
Author:   kwk
Date:     2010-07-09 22:06:58 +0200 (Fri, 09 Jul 2010)

Log Message:
-----------
This commit enables the "Auto-Select-Image" feature.

For more information and a video, please see: http://wiki.blender.org/index.php/User:Kwk/Gsoc2010/AutoSelectPaintImage

SCENARIO

Consider having multiple objects, each with its own set of materials and textures. Let's say, a few of the textures are actually image textures and you want to paint onto them in the UV/Image editor. 

PROBLEM

Up until now the UV/Image Editor doesn't care which object is selected nor does it care which texture in the active material's texture slot is active. This makes quick switching of paint textures more complicated than it needs to be. 

IDEA

Whenever a texture in the active material's texture slot changes, the image in the UV/Image Editor shall reflect these changes with respect to a setting that indicates if this behavior is wanted or not.

USE CASES

If "Auto Select Image" it toggled on, when will
the UV/Image Editor update it's image?

If the user...

(1) explicitly selects another texture slot,
(2) selects another object with a different material
associated with it (implicit material change).
(3) explicitly selects another material.
(4) toggles the "Auto Select Image" option on.

Modified Paths:
--------------
    branches/soc-2010-kwk/release/scripts/ui/space_image.py
    branches/soc-2010-kwk/source/blender/blenkernel/intern/texture.c
    branches/soc-2010-kwk/source/blender/editors/render/render_shading.c
    branches/soc-2010-kwk/source/blender/editors/space_image/space_image.c
    branches/soc-2010-kwk/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2010-kwk/source/blender/makesdna/DNA_space_types.h
    branches/soc-2010-kwk/source/blender/makesrna/intern/rna_material.c
    branches/soc-2010-kwk/source/blender/makesrna/intern/rna_sculpt_paint.c
    branches/soc-2010-kwk/source/blender/makesrna/intern/rna_space.c
    branches/soc-2010-kwk/source/blender/makesrna/intern/rna_texture.c

Modified: branches/soc-2010-kwk/release/scripts/ui/space_image.py
===================================================================
--- branches/soc-2010-kwk/release/scripts/ui/space_image.py	2010-07-09 19:20:57 UTC (rev 30158)
+++ branches/soc-2010-kwk/release/scripts/ui/space_image.py	2010-07-09 20:06:58 UTC (rev 30159)
@@ -139,7 +139,7 @@
 
             layout.separator()
 
-            layout.prop(bpy.context.tool_settings.image_paint, "auto_select_image")            
+        layout.prop(sima, "auto_select_image")
 
 
 class IMAGE_MT_uvs_showhide(bpy.types.Menu):
@@ -662,7 +662,7 @@
 class IMAGE_PT_paint_multi_channel(bpy.types.Panel):
     bl_space_type = 'IMAGE_EDITOR'
     bl_region_type = 'UI'
-    bl_label = "Multi Channel Painting"
+    bl_label = "Channels"
     bl_context = "texture"
     bl_default_closed = False
 

Modified: branches/soc-2010-kwk/source/blender/blenkernel/intern/texture.c
===================================================================
--- branches/soc-2010-kwk/source/blender/blenkernel/intern/texture.c	2010-07-09 19:20:57 UTC (rev 30158)
+++ branches/soc-2010-kwk/source/blender/blenkernel/intern/texture.c	2010-07-09 20:06:58 UTC (rev 30159)
@@ -69,7 +69,6 @@
 #include "BKE_node.h"
 #include "BKE_animsys.h"
 
-
 /* ------------------------------------------------------------------------- */
 
 /* All support for plugin textures: */

Modified: branches/soc-2010-kwk/source/blender/editors/render/render_shading.c
===================================================================
--- branches/soc-2010-kwk/source/blender/editors/render/render_shading.c	2010-07-09 19:20:57 UTC (rev 30158)
+++ branches/soc-2010-kwk/source/blender/editors/render/render_shading.c	2010-07-09 20:06:58 UTC (rev 30159)
@@ -37,6 +37,7 @@
 #include "DNA_scene_types.h"
 #include "DNA_space_types.h"
 #include "DNA_world_types.h"
+#include "DNA_screen_types.h"
 
 #include "BKE_animsys.h"
 #include "BKE_context.h"

Modified: branches/soc-2010-kwk/source/blender/editors/space_image/space_image.c
===================================================================
--- branches/soc-2010-kwk/source/blender/editors/space_image/space_image.c	2010-07-09 19:20:57 UTC (rev 30158)
+++ branches/soc-2010-kwk/source/blender/editors/space_image/space_image.c	2010-07-09 20:06:58 UTC (rev 30159)
@@ -46,6 +46,7 @@
 #include "BKE_mesh.h"
 #include "BKE_screen.h"
 #include "BKE_utildefines.h"
+#include "BKE_texture.h"
 
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
@@ -586,14 +587,24 @@
 		}
 
 		BKE_mesh_end_editmesh(obedit->data, em);
+	}	
+	
+	/* (kwk) Now auto select image to display. */	
+	if (sima->flag & SI_AUTO_SELECT_IMAGE) {				
+		/* Get current object. */
+		Object *ob = CTX_data_active_object(C);	
+		
+		if (ob && ob->type == OB_MESH) {
+			/* Get current texture. */
+			Tex *tex = give_current_object_texture(ob);			
+			
+			if (tex && tex->type == TEX_IMAGE && tex->ima) {
+				ED_space_image_set(C, sima, CTX_data_scene(C), obedit, tex->ima);	
+			}
+		}
 	}
 }
 
-static void auto_select_image()
-{
-	
-}
-
 static void image_listener(ScrArea *sa, wmNotifier *wmn)
 {
 	SpaceImage *sima= (SpaceImage *)sa->spacedata.first;
@@ -615,6 +626,13 @@
 					ED_area_tag_refresh(sa);
 					ED_area_tag_redraw(sa);					
 					break;
+				/* (kwk) Redraw image if another object was selected. */
+				case ND_OB_SELECT:
+					if(sima->lock && (sima->flag & SI_AUTO_SELECT_IMAGE)) {
+						ED_area_tag_refresh(sa);
+						ED_area_tag_redraw(sa);
+					}
+					break;					
 			}
 			break;
 		case NC_IMAGE:
@@ -640,28 +658,24 @@
 			}
 		case NC_OBJECT:
 			switch(wmn->data) {
-				case ND_TRANSFORM:					
+				case ND_TRANSFORM:				
 					if(sima->lock && (sima->flag & SI_DRAWSHADOW)) {						
 						ED_area_tag_refresh(sa);
 						ED_area_tag_redraw(sa);
 					}
 					break;
 			}
-		/* XXX: (kwk) for auto selecting image */
+		/* (kwk) Redraw image if active texture index changed. */
+		case NC_TEXTURE:
 		case NC_MATERIAL:
 			switch(wmn->data) {
-				default:
-					printf("Material.");
-					fflush(stdout);
+				default:						
+					if(sima->lock && (sima->flag & SI_AUTO_SELECT_IMAGE)) {
+						ED_area_tag_refresh(sa);
+						ED_area_tag_redraw(sa);
+					}
 					break;
 			}
-		case NC_TEXTURE:
-			switch(wmn->data) {
-				default:
-					printf("Texture.");
-					fflush(stdout);
-					break;
-			}
 	}
 }
 

Modified: branches/soc-2010-kwk/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/soc-2010-kwk/source/blender/makesdna/DNA_scene_types.h	2010-07-09 19:20:57 UTC (rev 30158)
+++ branches/soc-2010-kwk/source/blender/makesdna/DNA_scene_types.h	2010-07-09 20:06:58 UTC (rev 30159)
@@ -1136,8 +1136,6 @@
 #define IMAGEPAINT_PROJECT_LAYER_CLONE	1<<7
 #define IMAGEPAINT_PROJECT_LAYER_STENCIL	1<<8
 #define IMAGEPAINT_PROJECT_LAYER_STENCIL_INV	1<<9
-/* ImagePaintSettings.flag (again) */
-#define IMAGEPAINT_AUTO_SELECT_IMAGE	1<<10
 
 /* toolsettings->uvcalc_flag */
 #define UVCALC_FILLHOLES			1

Modified: branches/soc-2010-kwk/source/blender/makesdna/DNA_space_types.h
===================================================================
--- branches/soc-2010-kwk/source/blender/makesdna/DNA_space_types.h	2010-07-09 19:20:57 UTC (rev 30158)
+++ branches/soc-2010-kwk/source/blender/makesdna/DNA_space_types.h	2010-07-09 20:06:58 UTC (rev 30159)
@@ -752,6 +752,7 @@
 #define SI_DRAW_STRETCH	1<<21
 #define SI_DISPGP		1<<22
 #define SI_DRAW_OTHER	1<<23
+#define SI_AUTO_SELECT_IMAGE 1<<24
 
 #define SI_COLOR_CORRECTION	1<<24
 

Modified: branches/soc-2010-kwk/source/blender/makesrna/intern/rna_material.c
===================================================================
--- branches/soc-2010-kwk/source/blender/makesrna/intern/rna_material.c	2010-07-09 19:20:57 UTC (rev 30158)
+++ branches/soc-2010-kwk/source/blender/makesrna/intern/rna_material.c	2010-07-09 20:06:58 UTC (rev 30159)
@@ -74,6 +74,14 @@
 		WM_main_add_notifier(NC_MATERIAL|ND_SHADING, ma);
 }
 
+static void rna_Material_active_texture_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+	/* XXX: (kwk) This is a hack to process changes to the active texture index. */
+	WM_main_add_notifier(NC_TEXTURE|ND_DATACHANGED, NULL);
+	
+	rna_Material_update(bmain, scene, ptr);
+}
+
 static void rna_Material_draw_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
 	Material *ma= ptr->id.data;
@@ -1742,7 +1750,7 @@
 	/* common */
 	rna_def_animdata_common(srna);
 	rna_def_mtex_common(srna, "rna_Material_mtex_begin", "rna_Material_active_texture_get",
-		"rna_Material_active_texture_set", "MaterialTextureSlot", "rna_Material_update");
+		"rna_Material_active_texture_set", "MaterialTextureSlot", "rna_Material_active_texture_update");
 	
 	/* only material has this one */
 	prop= RNA_def_property(srna, "use_textures", PROP_BOOLEAN, PROP_NONE);

Modified: branches/soc-2010-kwk/source/blender/makesrna/intern/rna_sculpt_paint.c
===================================================================
--- branches/soc-2010-kwk/source/blender/makesrna/intern/rna_sculpt_paint.c	2010-07-09 19:20:57 UTC (rev 30158)
+++ branches/soc-2010-kwk/source/blender/makesrna/intern/rna_sculpt_paint.c	2010-07-09 20:06:58 UTC (rev 30159)
@@ -369,11 +369,6 @@
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", IMAGEPAINT_PROJECT_LAYER_CLONE);
 	RNA_def_property_ui_text(prop, "Clone Layer", "Use another UV layer as clone source, otherwise use 3D the cursor as the source");
 	
-	/*  selecting the active paint image by active textures in texture stack */
-	prop= RNA_def_property(srna, "auto_select_image", PROP_BOOLEAN, PROP_NONE);
-	RNA_def_property_boolean_sdna(prop, NULL, "flag", IMAGEPAINT_AUTO_SELECT_IMAGE);
-	RNA_def_property_ui_text(prop, "Auto Select Image", "Automatically select image by active texture in the texture stack");
-	
 	/* integers */
 	
 	prop= RNA_def_property(srna, "seam_bleed", PROP_INT, PROP_UNSIGNED);

Modified: branches/soc-2010-kwk/source/blender/makesrna/intern/rna_space.c
===================================================================
--- branches/soc-2010-kwk/source/blender/makesrna/intern/rna_space.c	2010-07-09 19:20:57 UTC (rev 30158)
+++ branches/soc-2010-kwk/source/blender/makesrna/intern/rna_space.c	2010-07-09 20:06:58 UTC (rev 30159)
@@ -362,6 +362,12 @@
 	paint_init(&scene->toolsettings->imapaint.paint, PAINT_CURSOR_TEXTURE_PAINT);
 }
 
+static void rna_SpaceImageEditor_auto_select_image_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{	
+	/* (kwk) Inform image spaces to update their view if they want to. */
+	WM_main_add_notifier(NC_TEXTURE|ND_DATACHANGED, NULL);
+}
+
 static int rna_SpaceImageEditor_show_render_get(PointerRNA *ptr)
 {
 	SpaceImage *sima= (SpaceImage*)(ptr->data);
@@ -1354,6 +1360,12 @@
 	RNA_def_property_ui_icon(prop, ICON_TPAINT_HLT, 0);
 	RNA_def_property_update(prop, NC_SPACE|ND_SPACE_IMAGE, "rna_SpaceImageEditor_paint_update");
 	
+	/*  selecting the active paint image by active textures in texture stack */
+	prop= RNA_def_property(srna, "auto_select_image", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "flag", SI_AUTO_SELECT_IMAGE);
+	RNA_def_property_ui_text(prop, "Auto Select Image", "Automatically select image by active texture in the texture stack");
+	RNA_def_property_update(prop, NC_SPACE|ND_SPACE_IMAGE, "rna_SpaceImageEditor_auto_select_image_update");
+	
 	/* grease pencil */
 	prop= RNA_def_property(srna, "grease_pencil", PROP_POINTER, PROP_NONE);
 	RNA_def_property_pointer_sdna(prop, NULL, "gpd");

Modified: branches/soc-2010-kwk/source/blender/makesrna/intern/rna_texture.c
===================================================================
--- branches/soc-2010-kwk/source/blender/makesrna/intern/rna_texture.c	2010-07-09 19:20:57 UTC (rev 30158)
+++ branches/soc-2010-kwk/source/blender/makesrna/intern/rna_texture.c	2010-07-09 20:06:58 UTC (rev 30159)
@@ -127,7 +127,7 @@
 static void rna_Texture_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
 	Tex *tex= ptr->id.data;
-
+	
 	DAG_id_flush_update(&tex->id, 0);
 	WM_main_add_notifier(NC_TEXTURE, tex);
 }





More information about the Bf-blender-cvs mailing list