I’m making an addon which will allow you to add various layers (color, bump, specular) while in Texture Paint mode. I’m aware there is an addon already like this, but I wish to customize my own further. I’ve only got so far as the first button (add color). This button successfully adds a material and names it if the object doesn’t already have a material and I can create a texture slot for it but I can’t add an actual image to the texture slot to be used.
import bpy
#First function for the button "Add Color"
class betterPaintColor(bpy.types.Operator):
bl_idname = "object.better_paint_color"
bl_label = "Add Color"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
#Store name for convenience
obj = bpy.context.scene.objects.active
#Test if object has material or not
if len(obj.data.materials) == 0:
#Create a new material and give it the name of the object
mat = bpy.data.materials.new(obj.name)
#Assign it some properties
mat.diffuse_shader = 'LAMBERT'
mat.darkness = 0.8
#Assign Material to the active object
obj.active_material = bpy.data.materials[obj.name]
<i><b>(THIS IS THE AREA WHERE I NEED TO HAVE A TEXTURE APPLIED TO THE MATERIAL)</b></i>
#Switch to texture viewport shading
bpy.context.space_data.viewport_shade = 'TEXTURED'
return {'FINISHED'}
#Draw the addon into the Tool Shelf
class betterPaint(bpy.types.Panel):
bl_label = "Layers"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
#Make addon specific to Texture Paint mode
@classmethod
def poll(cls, context):
return (context.image_paint_object)
def draw(self, context):
#Store names for convenience
layout = self.layout
row = layout.row()
row.operator("object.better_paint_color", icon='BRUSH_DATA')
row = layout.row()
row.label(text="Add Bump", icon='BRUSH_DATA')
row = layout.row()
row.label(text="Add Specular", icon='BRUSH_DATA')
#register and unregister all classes for use with
#addon by running them through a loop.
classes = [betterPaint, betterPaintColor]
def register():
for c in classes:
bpy.utils.register_class(c)
def unregister():
for c in classes:
bpy.utils.unregister_class(c)
if __name__ == "__main__":
register()
I’d also really like to be able to place two text inputs like this:
(with default settings) for the user to change the size of the image map they are creating but also be able to just press the button if they don’t wish to first give it a value. Thanks for any help or leads.