[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31385] branches/soc-2010-kwk: Added patches (adding map shortcuts and multi-image-layer painting) to be applied to trunk.

Konrad Kleine konrad at konradwilhelm.de
Mon Aug 16 18:10:04 CEST 2010


Revision: 31385
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31385
Author:   kwk
Date:     2010-08-16 18:10:03 +0200 (Mon, 16 Aug 2010)

Log Message:
-----------
Added patches (adding map shortcuts and multi-image-layer painting) to be applied to trunk.

Added Paths:
-----------
    branches/soc-2010-kwk/patches_for_trunk/
    branches/soc-2010-kwk/patches_for_trunk/image_layers_painting_ok_broken_opacity_and_delete.diff
    branches/soc-2010-kwk/patches_for_trunk/material_add_map.diff

Added: branches/soc-2010-kwk/patches_for_trunk/image_layers_painting_ok_broken_opacity_and_delete.diff
===================================================================
--- branches/soc-2010-kwk/patches_for_trunk/image_layers_painting_ok_broken_opacity_and_delete.diff	                        (rev 0)
+++ branches/soc-2010-kwk/patches_for_trunk/image_layers_painting_ok_broken_opacity_and_delete.diff	2010-08-16 16:10:03 UTC (rev 31385)
@@ -0,0 +1,967 @@
+Index: release/scripts/ui/space_image.py
+===================================================================
+--- release/scripts/ui/space_image.py	(Revision 31363)
++++ release/scripts/ui/space_image.py	(Arbeitskopie)
+@@ -663,6 +663,90 @@
+         row.operator("brush.curve_preset", icon="LINCURVE", text="").shape = 'LINE'
+         row.operator("brush.curve_preset", icon="NOCURVE", text="").shape = 'MAX'
+ 
++class IMAGE_PT_paint_add_map(bpy.types.Panel):
++    bl_space_type = 'IMAGE_EDITOR'
++    bl_region_type = 'UI'
++    bl_label = "Add Maps"
++    bl_context = "texture"
++    bl_default_closed = False
++
++    @classmethod
++    def poll(self, context):
++        # TBD
++        return True       
++
++    def draw(self, context):
++        layout = self.layout
++
++        row = layout.row()
++
++        split = layout.split()
++
++        row = split.row(align=True)
++        row.label(text="Add:")
++        row.operator("image.material_add_map", text="Diffuse").channel_type = 'DIFFUSE' # , icon='FILE_IMAGE'
++        row.operator("image.material_add_map", text="Bump").channel_type = 'BUMP'
++        row.operator("image.material_add_map", text="Specular").channel_type = 'SPECULAR'
++
++class IMAGE_PT_image_layers(bpy.types.Panel):
++    bl_space_type = 'IMAGE_EDITOR'
++    bl_region_type = 'UI'
++    bl_label = "Image Layers"
++ 
++    @classmethod
++    def poll(self, context):
++        sima = context.space_data
++        return (sima and (sima.image))
++ 
++    def draw(self, context):
++        layout = self.layout
++ 
++        sima = context.space_data
++        ima = sima.image
++        show_uvedit = sima.show_uvedit
++        uvedit = sima.uv_editor
++        layers = ima.image_layers
++ 
++        split = layout.split()
++ 
++        col = split.column()
++ 
++        if ima:            
++            row = layout.row()
++ 
++            row.template_list(ima, "image_layers", ima, "active_image_layer_index", rows=4)
++ 
++            col = row.column(align=True)
++            col.operator("image.image_layer_add", text="", icon='ZOOMIN')
++ 
++            if ima.active_image_layer:
++                col.operator("image.image_layer_remove", text="", icon='ZOOMOUT')
++ 
++                col.operator("image.image_layer_move", text="", icon='TRIA_UP').type = 'UP'
++                col.operator("image.image_layer_move", text="", icon='TRIA_DOWN').type = 'DOWN'
++ 
++                row = layout.row()
++ 
++                row.operator("image.image_layer_fill_color", text="Fill with Color")
++ 
++                row = layout.row()
++ 
++                row.label(text="Name")
++                col = row.column(align=True)
++                col.prop(ima.active_image_layer, "name", text="")
++ 
++                row = layout.row()
++ 
++                row.label(text="Opacity:")
++                col = row.column(align=True)
++                col.prop(ima.active_image_layer, "opacity", text="")
++ 
++                row = layout.row()
++ 
++                row.label(text="Invisible:")
++                col = row.column(align=True)
++                col.prop(ima.active_image_layer, "invisible", text="")
++
+ def register():
+     pass
+ 
+Index: release/scripts/op/image.py
+===================================================================
+--- release/scripts/op/image.py	(Revision 31363)
++++ release/scripts/op/image.py	(Arbeitskopie)
+@@ -188,7 +188,72 @@
+ 
+         return {'FINISHED'}
+ 
++def check_free_texture_slots(mat):
++    """Returns True if there are texture slots free in mat; otherwise False is returned"""
++    if mat != None:
++        for slot in mat.texture_slots:
++            if slot == None:
++                return True
++    return False
+ 
++class MaterialAddMap(bpy.types.Operator):
++    '''Add new map (e.g. diffuse, bump, specular) to the active material's next free texture slot.'''
++    bl_idname = "image.material_add_map"
++    bl_label = "Add Map"
++    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')
++
++    @classmethod
++    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 = 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')
++
++            mat.texture_slots[tex.name]
++               
++            # Create a new image (named after 
++            img = bpy.data.images.new(ctype)
++    
++            # Set image file format
++            # If I remember correctly, this is default.
++            img.file_format = 'TARGA'
++            
++            # Assign image to texture            
++            tex.image = img
++            
++
++        return {'FINISHED'}
++
+ def register():
+     pass
+ 
+Index: source/blender/blenkernel/intern/image.c
+===================================================================
+--- source/blender/blenkernel/intern/image.c	(Revision 31363)
++++ source/blender/blenkernel/intern/image.c	(Arbeitskopie)
+@@ -209,6 +209,8 @@
+ 			ima->renders[a]= NULL;
+ 		}
+ 	}
++	
++	image_free_image_layers(ima);
+ }
+ 
+ /* only image block itself */
+@@ -237,8 +239,16 @@
+ 	/* this function is intended to be thread safe. with IMA_NO_INDEX this
+ 	 * should be OK, but when iterating over the list this is more tricky
+ 	 * */
+-	if(index==IMA_NO_INDEX)
++	if(index==IMA_NO_INDEX) {
++		/* TODO: (kwk) This is an ugly hack to return always the active layer's ibuf */
++		ImageLayer *layer= imalayer_get_current(ima);
++		
++		if (layer && layer->ibufs.first)
++			return layer->ibufs.first;
++		
++		/* Only return "normal" image ibuf if no layer ibuf was found. */
+ 		return ima->ibufs.first;
++	}
+ 	else {
+ 		ImBuf *ibuf;
+ 
+@@ -283,6 +293,8 @@
+ 		/* now we don't want copies? */
+ 		if(link && ibuf->index==link->index)
+ 			image_remove_ibuf(ima, link);
++		
++		image_add_image_layer_base(ima);
+ 	}
+ }
+ 
+@@ -545,6 +557,275 @@
+ 	}
+ }
+ 
++void image_free_image_layers(struct Image *ima)
++{
++	ImageLayer *layer, *next;
++	ImBuf *ibuf;
++	void *lock;
++ 
++	if(ima==0)
++		return;
++ 
++	ibuf= BKE_image_acquire_ibuf(ima, NULL, &lock);
++ 
++	layer=(ImageLayer*)(ima->imlayers.first);
++	while(layer) {
++		next= layer->next;
++		BLI_remlink(&ima->imlayers, layer);
++		free_image_layer(layer);
++		layer= next;
++	}
++ 
++	BLI_freelistN(&ima->imlayers);
++ 
++	BKE_image_release_ibuf(ima, lock);
++}
++ 
++void free_image_layer(ImageLayer *layer)
++{
++	ImBuf *ibuf, *next;
++ 
++	if (!layer)
++		return;
++ 
++	ibuf= (layer->ibufs).first;
++	while(ibuf) {
++		next= ibuf->next;
++		BLI_remlink(&layer->ibufs, ibuf);
++ 
++		if((layer->flag & IMA_LAYER_BASE)==0) {
++			if (ibuf->userdata) {
++				MEM_freeN(ibuf->userdata);
++				ibuf->userdata = NULL;
++			}
++ 
++			IMB_freeImBuf(ibuf);
++		}
++		ibuf= next;
++	}
++	/*BLI_freelistN(&layer->ibufs);*/
++ 
++	MEM_freeN(layer);
++}
++ 
++ImageLayer *imalayer_get_current(Image *ima)
++{
++	ImageLayer *layer;
++	if(ima==0)
++		return 0;
++ 
++	for(layer=ima->imlayers.first; layer; layer=layer->next){
++		if(layer->flag & IMA_LAYER_CURRENT)
++			return layer;
++	}
++ 
++	return 0;
++}
++ 
++short imalayer_get_current_num(Image *ima)
++{
++	ImageLayer *layer;
++	short i;
++ 
++	if(ima==0)
++		return 0;
++ 
++	for(layer=ima->imlayers.first, i=0; layer; layer=layer->next, i++)
++		if(layer->flag & IMA_LAYER_CURRENT)
++			return i;
++ 
++	return i;
++}
++ 
++void imalayer_set_current_num(Image *ima, short index)
++{
++	ImageLayer *layer;
++	short i;
++ 
++	if(ima==0)
++		return;
++ 
++	for(layer=ima->imlayers.first, i=0; layer; layer=layer->next, i++) {
++		if(i == index)
++			layer->flag |= IMA_LAYER_CURRENT;
++		else
++			layer->flag &= ~IMA_LAYER_CURRENT;
++	}
++}
++ 
++void imalayer_fill_color(struct Image *ima, float color[4])
++{
++	ImageLayer *layer= NULL;
++	ImBuf *ibuf= NULL;
++	unsigned char *rect= NULL;
++	float *rect_float= NULL;
++	void *lock;
++ 
++	if (ima==NULL)
++		return;
++ 
++	ibuf= BKE_image_acquire_ibuf(ima, NULL, &lock);
++ 
++ 
++	layer= imalayer_get_current(ima);
++ 
++	if ((ibuf = ima->imlayers.first)) {
++		if (ibuf->flags & IB_rectfloat) {
++			rect_float= (float*)ibuf->rect_float;
++		}
++		else {
++			rect= (unsigned char*)ibuf->rect;
++		}
++ 
++		//BKE_image_buf_fill_color(rect, rect_float, ibuf->x, ibuf->y, color);
++	}
++ 
++	BKE_image_release_ibuf(ima, lock);
++}
++ 
++int image_remove_current_image_layer(Image *ima)
++{
++	ImageLayer *layer= NULL;
++ 
++	if(ima==NULL)
++		return FALSE;
++ 
++	layer= imalayer_get_current(ima);
++ 
++	free_image_layer(layer);
++ 
++	/* Ensure the first element in list gets selected (if any) */
++	if(ima->imlayers.first)
++		((ImageLayer *) ima->imlayers.first)->flag |= IMA_LAYER_CURRENT;
++ 
++	return TRUE;
++}
++ 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list