Brushstroke Tools: Initial Version #328

Merged
Simon Thommes merged 229 commits from SimonThommes/blender-studio-tools:brushstroke_tools-initial-version into main 2024-11-06 15:03:47 +01:00
3 changed files with 14 additions and 9 deletions
Showing only changes of commit abb52a3311 - Show all commits

View File

@ -134,8 +134,10 @@ def set_brush_style(self, value):
ng_name = f'BSBST-BS.{value}' ng_name = f'BSBST-BS.{value}'
ng = utils.ensure_node_group(ng_name, [bs for bs in addon_prefs.brush_styles if bs.name==value][0].filepath) ng = utils.ensure_node_group(ng_name, [bs for bs in addon_prefs.brush_styles if bs.name==value][0].filepath)
# if ng.preview: if ng.preview:
# utils.set_preview(ng.preview.image_pixels_float, ng.preview.image_size[:]) utils.set_preview(ng.preview.image_pixels_float, ng.preview.image_size[:])
else:
utils.set_preview(None)
node = self.node_tree.nodes['Brush Style'] node = self.node_tree.nodes['Brush Style']
node_prev_inputs = [input.name for input in node.inputs] node_prev_inputs = [input.name for input in node.inputs]

View File

@ -214,8 +214,7 @@ def draw_material_settings(layout, material, surface_object=None):
if brush_panel: if brush_panel:
if settings.preview_texture: if settings.preview_texture:
row = brush_panel.row(align=True) row = brush_panel.row(align=True)
row.template_preview(settings.preview_texture, show_buttons=False, preview_id='brushstroke_preview') # TODO: Figure out how to redraw the preview on style change row.template_preview(settings.preview_texture, show_buttons=False, preview_id='brushstroke_preview')
brush_panel.prop(settings.preview_texture, 'use_flip_axis')
row = brush_panel.row(align=True) row = brush_panel.row(align=True)
row.prop_search(material, 'brush_style', addon_prefs, 'brush_styles', text='', icon='BRUSHES_ALL') row.prop_search(material, 'brush_style', addon_prefs, 'brush_styles', text='', icon='BRUSHES_ALL')

View File

@ -586,10 +586,15 @@ def round_n(val, n):
return round(val, n-int(math.floor(math.log10(abs(val))))-1) return round(val, n-int(math.floor(math.log10(abs(val))))-1)
def set_preview(pixels, size = (256, 256)): def set_preview(pixels, size = (256, 256)):
if not pixels: preview_name = '.BSBST-preview'
return
preview_name = 'BSBST-preview'
preview_img = bpy.data.images.get(preview_name) preview_img = bpy.data.images.get(preview_name)
preview_texture = bpy.data.textures.get(preview_name)
if not pixels:
if preview_img:
bpy.data.images.remove(preview_img)
if preview_texture:
bpy.data.textures.remove(preview_texture)
return
if preview_img: if preview_img:
if not len(preview_img.pixels) == len(pixels): if not len(preview_img.pixels) == len(pixels):
bpy.data.images.remove(preview_img) bpy.data.images.remove(preview_img)
@ -597,7 +602,6 @@ def set_preview(pixels, size = (256, 256)):
if not preview_img: if not preview_img:
preview_img = bpy.data.images.new(preview_name, width=size[0], height=size[1]) preview_img = bpy.data.images.new(preview_name, width=size[0], height=size[1])
preview_texture = bpy.data.textures.get(preview_name)
if not preview_texture: if not preview_texture:
preview_texture = bpy.data.textures.new(name=preview_name, type="IMAGE") preview_texture = bpy.data.textures.new(name=preview_name, type="IMAGE")
settings = bpy.context.scene.BSBST_settings settings = bpy.context.scene.BSBST_settings