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
2 changed files with 17 additions and 12 deletions
Showing only changes of commit cb90d4d955 - Show all commits

View File

@ -134,8 +134,8 @@ def set_brush_style(self, value):
ng_name = f'BSBST-brushstroke.{value}' ng_name = f'BSBST-brushstroke.{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) # utils.set_preview(ng.preview.image_pixels_float, ng.preview.image_size[:])
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

@ -530,28 +530,33 @@ 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): def set_preview(pixels, size = (256, 256)):
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 preview_img:
preview_img = bpy.data.images.new(preview_name, width=256, height=256)
if not len(preview_img.pixels) == len(pixels): if not len(preview_img.pixels) == len(pixels):
return # TODO handle different sizes bpy.data.images.remove(preview_img)
preview_img = None
if not preview_img:
preview_img = bpy.data.images.new(preview_name, width=size[0], height=size[1])
preview_texture = bpy.data.textures.get(preview_name) preview_texture = bpy.data.textures.get(preview_name)
if preview_texture: if not preview_texture:
bpy.data.textures.remove(preview_texture)
preview_texture = bpy.data.textures.new(name=preview_name, type="IMAGE") 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 = bpy.context.scene.BSBST_settings
settings.preview_texture = preview_texture settings.preview_texture = preview_texture
preview_texture.extension = 'EXTEND'
preview_texture.crop_max_x = size[1]/size[0]
preview_texture.image = preview_img
preview_img.pixels.foreach_set(numpy.array(pixels, dtype=numpy.float32)) preview_img.pixels.foreach_set(numpy.array(pixels, dtype=numpy.float32))
# TODO pack image
# TODO delete pre-save
# TODO set height of preview region
def register(): def register():
bpy.app.handlers.depsgraph_update_post.append(refresh_preset) bpy.app.handlers.depsgraph_update_post.append(refresh_preset)