[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29699] branches/soc-2010-kwk: Convenience tools to quickly add different maps to the active material' s texture slots, all set up for painting.

Konrad Kleine konrad at konradwilhelm.de
Sat Jun 26 01:26:46 CEST 2010


Revision: 29699
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29699
Author:   kwk
Date:     2010-06-26 01:26:46 +0200 (Sat, 26 Jun 2010)

Log Message:
-----------
Convenience tools to quickly add different maps to the active material's texture slots, all set up for painting.

This video shows the tools in action: http://vimeo.com/12864832

Modified Paths:
--------------
    branches/soc-2010-kwk/release/scripts/op/image.py
    branches/soc-2010-kwk/release/scripts/ui/space_image.py
    branches/soc-2010-kwk/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2010-kwk/source/blender/makesdna/DNA_brush_types.h
    branches/soc-2010-kwk/source/blender/makesdna/DNA_scene_types.h

Modified: branches/soc-2010-kwk/release/scripts/op/image.py
===================================================================
--- branches/soc-2010-kwk/release/scripts/op/image.py	2010-06-25 23:13:37 UTC (rev 29698)
+++ branches/soc-2010-kwk/release/scripts/op/image.py	2010-06-25 23:26:46 UTC (rev 29699)
@@ -186,11 +186,92 @@
 
         return {'FINISHED'}
 
+def check_free_texture_slots(mat):
+    """Returns True if there are texture slots free in mat; otherwise False is returned"""
+    for slot in mat.texture_slots:
+        if slot == None:
+            return True
+    return False
+
+class MultiChannelAddChannel(bpy.types.Operator):
+    '''Add new channel (e.g. diffuse, bump, spec map) to the active material's next free texture slot. '''
+    bl_idname = "image.multi_channel_add_channel"
+    bl_label = "Add Channel"
+    bl_options = {'REGISTER', 'UNDO'}
+
+    channel_type = bpy.props.EnumProperty(items=(
+            ('DIFFUSE', "Diffuse Map", "A 32 Bit RGB(A) color map"),
+            ('SPECULAR', "Specular Map", "A 8 Bit greyscale map"),
+            ('BUMP', "Bump Map", "A 8 Bit greyscale map")
+            ),                
+            name="Channel Type",
+            description="This defines how the new image will be used in the texture.",
+            default='DIFFUSE')
+
+    def poll(self, context):
+        ''' Tests if a texture slot is free '''
+        mat = bpy.context.active_object.active_material
+        return check_free_texture_slots(mat)
+    
+    def execute(self, context):
+        ctype = self.properties.channel_type
+        mat = bpy.context.active_object.active_material
+        tex = None
+        
+        # Tests if a texture slot is free
+        if check_free_texture_slots(mat):
+            tex = bpy.data.textures.new(ctype)
+        
+        if tex != None:            
+            # Set texture type to be an bpy.types.ImageTexture object
+            tex.type = 'IMAGE'
+            tex.recast_type()
+            
+            # Decide which parts shall be influenced by the image texture
+            if ctype == 'DIFFUSE':
+                mat.add_texture(tex, texture_coordinates='UV', map_to='COLOR')
+            elif ctype == 'BUMP':
+                mat.add_texture(tex, texture_coordinates='UV', map_to='NORMAL')
+            elif ctype == 'SPECULAR':
+                mat.add_texture(tex, texture_coordinates='UV', map_to='SPECULARITY')
+                # XXX: (kwk) What about influencing the specular color?
+
+            mat.texture_slots[tex.name]
+
+#            # Diffuse maps are painted in color, so set the "stype" to color
+#            # (for bump/height map use 'GREYSCALE')
+            if ctype == 'DIFFUSE':
+                tex.stype = 'COLOR'
+            elif ctype == 'BUMP':
+                tex.stype = 'GREYSCALE'
+            elif ctype == 'SPECULAR':
+                tex.stype = 'GREYSCALE'
+                
+            # Create a new image (named after 
+            img = bpy.data.images.new(ctype)
+            # XXX: (kwk) How to get floating dialog like with layout.operator("image.new") ??? 
+#            if ctype == 'DIFFUSE':
+#                bpy.ops.image.new(name=ctype, width=1024, height=1024, color=(0, 0, 0), alpha=1, uv_test_grid=False, float=False)
+#            elif ctype == 'BUMP':
+#                bpy.ops.image.new(name=ctype, width=1024, height=1024, color=(0, 0, 0), alpha=0, uv_test_grid=False, float=False)
+#            elif ctype == 'SPECULAR':
+#                bpy.ops.image.new(name=ctype, width=1024, height=1024, color=(0, 0, 0), alpha=0, uv_test_grid=False, float=False)
+#                
+            # Set image file format
+            # If I remember correctly, this is default. XXX: (kwk) think about HDR?
+            img.file_format = 'TARGA'
+            
+            # Assign image to texture            
+            tex.image = img
+
+        return {'FINISHED'}
+
 classes = [
     EditExternally,
     SaveDirty,
     ProjectEdit,
-    ProjectApply]
+    ProjectApply,
+    MultiChannelAddChannel]
 
 
 def register():

Modified: branches/soc-2010-kwk/release/scripts/ui/space_image.py
===================================================================
--- branches/soc-2010-kwk/release/scripts/ui/space_image.py	2010-06-25 23:13:37 UTC (rev 29698)
+++ branches/soc-2010-kwk/release/scripts/ui/space_image.py	2010-06-25 23:26:46 UTC (rev 29699)
@@ -639,7 +639,7 @@
     bl_space_type = 'IMAGE_EDITOR'
     bl_region_type = 'UI'
     bl_label = "Paint Curve"
-    bl_default_closed = True
+    bl_default_closed = False
 
     def poll(self, context):
         sima = context.space_data
@@ -655,7 +655,42 @@
         layout.template_curve_mapping(brush, "curve")
         layout.operator_menu_enum("brush.curve_preset", "shape")
 
+class IMAGE_PT_paint_multi_channel(bpy.types.Panel):
+    bl_space_type = 'IMAGE_EDITOR'
+    bl_region_type = 'UI'
+    bl_label = "Multi Channel Painting"
+    bl_context = "texture"
+    bl_default_closed = False
 
+#    enable_multi_channel = bpy.props.BoolProperty(name="Enable Multi-Channel", description="Enable multi-channel painting", default=True)
+
+    def poll(self, context):
+        # TBD
+        return True       
+
+# XXX: (kwk)    For header and general indication if multi channel painting is
+#                enabled, add a boolean property or flag bit to "ImagePaintSettings"
+#                in "ToolSettings". This will hopefully be accessible via
+#                bpy.context.tool_settings.image_paint from within Python.
+#                ...IMAGEPAINT_MUTLI_CHANNEL_ENABLED is the flag to test for...
+
+#    def draw_header(self, context):
+#        self.layout.prop(self.properties, "enable_multi_channel", text="")
+
+    def draw(self, context):
+        # XXX: (kwk) CHECKOUT bpy.context.tool_settings.image_paint
+        layout = self.layout
+
+        row = layout.row()
+        
+        split = layout.split()
+#        
+        row = split.row(align=True)
+        row.label(text="Add:")
+        row.operator("image.multi_channel_add_channel", text="Diffuse").channel_type = 'DIFFUSE' # , icon='FILE_IMAGE'
+        row.operator("image.multi_channel_add_channel", text="Bump").channel_type = 'BUMP'
+        row.operator("image.multi_channel_add_channel", text="Specular").channel_type = 'SPECULAR'
+
 classes = [
     IMAGE_MT_view,
     IMAGE_MT_select,
@@ -671,6 +706,7 @@
     IMAGE_PT_paint,
     IMAGE_PT_paint_stroke,
     IMAGE_PT_paint_curve,
+    IMAGE_PT_paint_multi_channel,
     IMAGE_PT_game_properties,
     IMAGE_PT_view_properties,
     IMAGE_PT_view_histogram,

Modified: branches/soc-2010-kwk/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2010-kwk/source/blender/editors/sculpt_paint/paint_image.c	2010-06-25 23:13:37 UTC (rev 29698)
+++ branches/soc-2010-kwk/source/blender/editors/sculpt_paint/paint_image.c	2010-06-25 23:26:46 UTC (rev 29699)
@@ -4802,8 +4802,8 @@
 //	mouse[1]= event->y - ar->winrct.ymin + 1;
 	// XXX: (kwk) for now we use the location from paint stroke but it probably needs to be fixed.
 	RNA_float_get_array(itemptr, "location", mousef);
-	mouse[0] = (int) mousef[0] - ar->winrct.xmin + 1;
-	mouse[1] = (int) mousef[1] - ar->winrct.ymin + 1;
+	mouse[0] = (int) mousef[0] + ar->winrct.xmin + 1;
+	mouse[1] = (int) mousef[1] + ar->winrct.ymin + 1;
 	
 	time= PIL_check_seconds_timer();
 

Modified: branches/soc-2010-kwk/source/blender/makesdna/DNA_brush_types.h
===================================================================
--- branches/soc-2010-kwk/source/blender/makesdna/DNA_brush_types.h	2010-06-25 23:13:37 UTC (rev 29698)
+++ branches/soc-2010-kwk/source/blender/makesdna/DNA_brush_types.h	2010-06-25 23:26:46 UTC (rev 29699)
@@ -79,7 +79,7 @@
 #define BRUSH_JITTER_PRESSURE	16 /* was BRUSH_RAD_PRESSURE */
 #define BRUSH_SPACING_PRESSURE	32
 #define BRUSH_FIXED_TEX			64
-#define BRUSH_RAKE				128
+#define BRUSH_RAKE				128	
 #define BRUSH_ANCHORED			256
 #define BRUSH_DIR_IN			512
 #define BRUSH_SPACE				1024

Modified: branches/soc-2010-kwk/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/soc-2010-kwk/source/blender/makesdna/DNA_scene_types.h	2010-06-25 23:13:37 UTC (rev 29698)
+++ branches/soc-2010-kwk/source/blender/makesdna/DNA_scene_types.h	2010-06-25 23:26:46 UTC (rev 29699)
@@ -521,12 +521,15 @@
 typedef struct ImagePaintSettings {
 	Paint paint;
 
-	short flag, pad;
+	int flag; 
 	
 	/* for projection painting only */
 	short seam_bleed, normal_angle;
 	short screen_grab_size[2]; /* capture size for re-projection */
 
+	/* XXX: (kwk) For multi-channel painting */
+	
+	/* XXX: (kwk) still need pad1 here? */	
 	int pad1;
 
 	void *paintcursor;			/* wm handle */
@@ -1124,17 +1127,19 @@
 } SculptFlags;
 
 /* ImagePaintSettings.flag */
-#define IMAGEPAINT_DRAWING				1
-#define IMAGEPAINT_DRAW_TOOL			2
-#define IMAGEPAINT_DRAW_TOOL_DRAWING	4
+#define IMAGEPAINT_DRAWING				1<<0
+#define IMAGEPAINT_DRAW_TOOL			1<<1
+#define IMAGEPAINT_DRAW_TOOL_DRAWING	1<<2
 /* projection painting only */
-#define IMAGEPAINT_PROJECT_DISABLE		8	/* Non projection 3D painting */
-#define IMAGEPAINT_PROJECT_XRAY			16
-#define IMAGEPAINT_PROJECT_BACKFACE		32
-#define IMAGEPAINT_PROJECT_FLAT			64
-#define IMAGEPAINT_PROJECT_LAYER_CLONE	128
-#define IMAGEPAINT_PROJECT_LAYER_STENCIL	256
-#define IMAGEPAINT_PROJECT_LAYER_STENCIL_INV	512
+#define IMAGEPAINT_PROJECT_DISABLE		1<<3	/* Non projection 3D painting */
+#define IMAGEPAINT_PROJECT_XRAY			1<<4
+#define IMAGEPAINT_PROJECT_BACKFACE		1<<5
+#define IMAGEPAINT_PROJECT_FLAT			1<<6
+#define IMAGEPAINT_PROJECT_LAYER_CLONE	1<<7
+#define IMAGEPAINT_PROJECT_LAYER_STENCIL	1<<8
+#define IMAGEPAINT_PROJECT_LAYER_STENCIL_INV	1<<9
+/* for multi-channel painting */
+#define IMAGEPAINT_MUTLI_CHANNEL_ENABLED 1<<10
 
 /* toolsettings->uvcalc_flag */
 #define UVCALC_FILLHOLES			1





More information about the Bf-blender-cvs mailing list