[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1790] contrib/py/scripts/addons/ texpaint_ui.py: adding michaels excellent texture paint layers script to contrib, http:// wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/3D_interaction/ Texture_paint_layers makes a lot of paint related workflows a lot easier on artists

Tom Musgrove LetterRip at gmail.com
Wed Apr 6 00:20:09 CEST 2011


Revision: 1790
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1790
Author:   letterrip
Date:     2011-04-05 22:20:08 +0000 (Tue, 05 Apr 2011)
Log Message:
-----------
adding michaels excellent texture paint layers script to contrib, http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/3D_interaction/Texture_paint_layers makes a lot of paint related workflows a lot easier on artists

Added Paths:
-----------
    contrib/py/scripts/addons/texpaint_ui.py

Added: contrib/py/scripts/addons/texpaint_ui.py
===================================================================
--- contrib/py/scripts/addons/texpaint_ui.py	                        (rev 0)
+++ contrib/py/scripts/addons/texpaint_ui.py	2011-04-05 22:20:08 UTC (rev 1790)
@@ -0,0 +1,583 @@
+bl_info = {
+    "name": "Texture Paint Layer Manager",
+    "author": "Michael Wiliamson",
+    "version": (1, 0),
+    "blender": (2, 5, 6),
+    "api": 35964,
+    "location": "Texture paint 'nkey' panel",
+    "description": "adds a layer manager for image based texture slots in paint and quick add layer tools",
+    "warning": "",
+    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/3D_interaction/Texture_paint_layers",
+    "tracker_url": "http://projects.blender.org/tracker/?func=add&group_id=153&atid=467",
+    "category": "Add Mesh"}
+        
+        
+import bpy
+from bpy.props import*
+import os
+from io_utils import ImportHelper
+
+
+#-------------------------------------------
+
+def load_a_brush(context, filepath):
+    if os.path.isdir(filepath):
+        return
+        
+    else:
+
+        try:
+            fn = bpy.path.display_name_from_filepath(filepath)
+            #create image and load...
+            img = bpy.data.images.load(filepath)
+            img.use_fake_user =True
+            
+            #create a texture
+            tex = bpy.data.textures.new(name =fn, type='IMAGE')
+            tex.use_fake_user =True
+            #tex.use_calculate_alpha = True
+            
+            #link the img to the texture
+            tex.image = img
+            
+        except:
+            print(f,'is not image?')
+
+    return {'FINISHED'}
+
+
+
+
+class load_single_brush(bpy.types.Operator, ImportHelper):
+    ''' Load an image as a brush texture'''
+    bl_idname = "texture.load_single_brush"  
+    bl_label = "Load Image as Brush"
+
+
+    @classmethod
+    def poll(cls, context):
+        return context.active_object != None
+
+    def execute(self, context):
+        return load_a_brush(context, self.filepath)
+
+#-------------------------------------------
+
+def loadbrushes(context, filepath):
+    if os.path.isdir(filepath):
+        directory = filepath
+        
+    else:
+        #is a file, find parent directory    
+        li = filepath.split(os.sep)
+        directory = filepath.rstrip(li[-1])
+        
+        
+    files = os.listdir(directory)
+    for f in files:
+        try:
+            fn = f[3:]
+            #create image and load...
+            img = bpy.data.images.load(filepath = directory +os.sep + f)
+            img.use_fake_user =True
+            
+            #create a texture
+            tex = bpy.data.textures.new(name =fn, type='IMAGE')
+            tex.use_fake_user =True
+            #tex.use_calculate_alpha = True
+            
+            #link the img to the texture
+            tex.image = img
+            
+        except:
+            print(f,'is not image?')
+            continue
+    return {'FINISHED'}
+
+
+
+
+class ImportBrushes(bpy.types.Operator, ImportHelper):
+    ''' Load a directory of images as brush textures '''
+    bl_idname = "texture.load_brushes"  
+    bl_label = "Load brushes directory"
+
+
+    @classmethod
+    def poll(cls, context):
+        return context.active_object != None
+
+    def execute(self, context):
+        return loadbrushes(context, self.filepath)
+
+#-------------------------------------------------------------------
+
+class OBJECT_PT_LoadBrushes(bpy.types.Panel):
+    bl_label = "Load Brush images"
+    bl_space_type = "VIEW_3D"
+    bl_region_type = "TOOLS"
+    #bl_context = "texturepaint"
+    
+    @classmethod
+    def poll(cls, context):
+        return (context.sculpt_object or context.image_paint_object)
+    
+    def draw(self, context):
+        layout = self.layout
+        row = layout.row()
+        row.operator('texture.load_brushes')
+        row = layout.row()
+        row.operator('texture.load_single_brush')
+
+
+#======================================================================
+
+
+
+
+
+class OBJECT_PT_Texture_paint_layers(bpy.types.Panel):
+    bl_label = "Texture Paint Layers"
+    bl_space_type = "VIEW_3D"
+    bl_region_type = "UI"
+    #bl_context = "texturepaint"
+    
+    @classmethod
+    def poll(cls, context):
+        return (context.image_paint_object)
+    
+    def draw(self, context):
+        layout = self.layout
+
+        ob = bpy.context.image_paint_object
+        if ob:
+            me = ob.data
+            mat = ob.active_material
+    
+            
+            row = layout.row()        
+            row.template_list(ob, "material_slots", ob, 
+                "active_material_index", rows=2 )
+            
+    
+            
+            #list Paintable textures
+            #TODO add filter for channel type
+            i = -1
+            for t in mat.texture_slots:
+                i+=1
+                try:
+                    if t.texture.type =='IMAGE':                
+                        row = layout.row(align= True)                
+                        if t.texture == mat.active_texture:
+                            ai =  'BRUSH_DATA'
+                        else:
+                            ai = 'BLANK1'
+                        row.operator('object.set_active_paint_layer', 
+                            text = "", icon = ai).tex_index =i   
+                        row.prop(t.texture,'name', text = "")
+        
+    
+                        #Visibility
+                        if t.use:
+                            ic = 'RESTRICT_VIEW_OFF'
+                        else:
+                            ic = 'RESTRICT_VIEW_ON'
+                        row.prop(t,'use', text = "",icon = ic)
+                except:
+                     continue
+    
+            
+    
+
+
+            
+            ts = mat.texture_slots[mat.active_texture_index]
+    
+            if ts:
+                row = layout.row()
+                row = layout.row()
+                row.label('Active Properties:', icon = 'BRUSH_DATA')
+    
+                #use if rather than elif... can be mapped to multiple things                
+                if ts.use_map_diffuse:
+                    row = layout.row()
+    
+                    row.prop(ts,'diffuse_factor', slider = True)
+                if ts.use_map_color_diffuse:
+                    row = layout.row()
+                    row.prop(ts,'diffuse_color_factor', slider = True)
+                if ts.use_map_alpha:
+                    row = layout.row()
+                    row.prop(ts,'alpha_factor', slider = True)
+                if ts.use_map_translucency:
+                    row = layout.row()
+                    row.prop(ts,'translucency_factor', slider = True)
+                
+                if ts.use_map_specular:
+                    row = layout.row()
+                    row.prop(ts,'specular_factor', slider = True)
+                if ts.use_map_color_spec:
+                    row = layout.row()
+                    row.prop(ts,'specular_color_factor', slider = True)
+                if ts.use_map_hardness:
+                    row = layout.row()
+                    row.prop(ts,'hardness_factor', slider = True)
+                    
+                if ts.use_map_normal:
+                    row = layout.row()
+                    row.prop(ts,'normal_factor', slider = True)
+                if ts.use_map_warp:
+                    row = layout.row()
+                    row.prop(ts,'warp_factor', slider = True)
+                if ts.use_map_displacement:
+                    row = layout.row()
+                    row.prop(ts,'displacement_factor', slider = True)  
+                    
+                if ts.use_map_ambient:
+                    row = layout.row()
+                    row.prop(ts,'ambient_factor', slider = True)               
+                if ts.use_map_emit:
+                    row = layout.row()
+                    row.prop(ts,'emit_factor', slider = True)                  
+                if ts.use_map_mirror:
+                    row = layout.row()
+                    row.prop(ts,'mirror_factor', slider = True)    
+                if ts.use_map_raymir:
+                    row = layout.row()
+                    row.prop(ts,'raymir_factor', slider = True)    
+                 
+                                    
+                row = layout.row()
+                row.prop(ts,'blend_type',text='')   
+        
+        
+
+#            
+#        row = layout.row()
+#        row.label('')              
+#        row = layout.row()
+#        row.label('WIP: Use the X to delete!:')                  
+#        row = layout.row()                 
+#        row.template_ID(mat, "active_texture", new="texture.new") 
+
+
+class OBJECT_PT_Texture_paint_add(bpy.types.Panel):
+    bl_label = "Add Paint Layers"
+    bl_space_type = "VIEW_3D"
+    bl_region_type = "UI"
+    #bl_context = "texturepaint"
+    
+    @classmethod
+    def poll(cls, context):
+        return (context.image_paint_object)
+
+    def draw(self, context):
+        layout = self.layout
+
+        ob = bpy.context.image_paint_object
+        if ob:
+            me = ob.data
+            mat = ob.active_material
+    
+            
+            #row = layout.row()   
+            col = layout.column(align =True)
+    
+    
+            col.operator('object.add_paint_layer',
+                text = "Add Color").ttype = 'COLOR' 
+            col.operator('object.add_paint_layer',
+                text = "Add Bump").ttype = 'NORMAL'
+            col.operator('object.add_paint_layer',
+                text = "Add Specular").ttype = 'SPECULAR'
+            col.operator('object.add_paint_layer',
+                text = "Add Emit").ttype = 'EMIT'      
+            
+        
+        
+
+def main(context,tn):
+    #tn is the index of the texture in the active material
+    ob = context.active_object
+    me = ob.data
+    mat = ob.active_material
+    mat.active_texture_index = tn    
+    ts = mat.texture_slots[tn]
+
+    #make sure it's visible
+    ts.use = True
+
+    #Mesh use UVs?
+    if not me.uv_textures:
+        bpy.ops.mesh.uv_texture_add()
+        
+    # texture Slot uses UVs?
+    if ts.texture_coords  == 'UV':
+        if ts.uv_layer:
+            uvtex = me.uv_textures[ts.uv_layer]
+        
+        else:
+            uvtex = me.uv_textures.active
+            me.uv_textures.active= uvtex

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list