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 20 additions and 3 deletions
Showing only changes of commit bb6bf1778e - Show all commits

View File

@ -233,6 +233,7 @@ class BSBST_Settings(bpy.types.PropertyGroup):
description="Estimate the length, width and distribution density of the brush strokes based on the bounding box to provide a reasonable starting point regardless of scale") description="Estimate the length, width and distribution density of the brush strokes based on the bounding box to provide a reasonable starting point regardless of scale")
silent_switch: bpy.props.BoolProperty(default=False) silent_switch: bpy.props.BoolProperty(default=False)
preview_texture: bpy.props.PointerProperty(type=bpy.types.Texture)
classes = [ classes = [
BSBST_socket_info, BSBST_socket_info,

View File

@ -212,6 +212,10 @@ def draw_material_settings(layout, material, surface_object=None):
brush_header, brush_panel = layout.panel('brush_panel', default_closed = True) brush_header, brush_panel = layout.panel('brush_panel', default_closed = True)
brush_header.label(text='Brush Style', icon='BRUSHES_ALL') brush_header.label(text='Brush Style', icon='BRUSHES_ALL')
if brush_panel: if brush_panel:
if settings.preview_texture:
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 = 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')
row.operator('brushstroke_tools.refresh_styles', text='', icon='FILE_REFRESH') row.operator('brushstroke_tools.refresh_styles', text='', icon='FILE_REFRESH')

View File

@ -531,12 +531,24 @@ def round_n(val, n):
def set_preview(pixels): def set_preview(pixels):
if not pixels: if not pixels:
return return
preview_name = '.BSBST-preview' preview_name = 'BSBST-preview'
preview_img = bpy.data.images.get(preview_name) preview_img = bpy.data.images.get(preview_name)
if not preview_img: if not preview_img:
preview_img = bpy.data.images.new(preview_name, width=256, height=256, float_buffer=True, is_data=True) preview_img = bpy.data.images.new(preview_name, width=256, height=256)
if not len(preview_img.pixels) == len(pixels):
return # TODO handle different sizes
preview_img.pixels.foreach_set(pixels) preview_texture = bpy.data.textures.get(preview_name)
if preview_texture:
bpy.data.textures.remove(preview_texture)
preview_texture = bpy.data.textures.new(name=preview_name, type="IMAGE")
preview_texture.extension = 'EXTEND'
preview_texture.image = preview_img
settings = bpy.context.scene.BSBST_settings
settings.preview_texture = preview_texture
preview_img.pixels.foreach_set(numpy.array(pixels, dtype=numpy.float32))
def register(): def register():
bpy.app.handlers.depsgraph_update_post.append(refresh_preset) bpy.app.handlers.depsgraph_update_post.append(refresh_preset)