Brushstroke Tools: Initial Version #328
@ -134,8 +134,8 @@ def set_brush_style(self, 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)
|
||||
|
||||
#if ng.preview:
|
||||
# utils.set_preview(ng.preview.image_pixels_float)
|
||||
# if ng.preview:
|
||||
# utils.set_preview(ng.preview.image_pixels_float, ng.preview.image_size[:])
|
||||
|
||||
node = self.node_tree.nodes['Brush Style']
|
||||
node_prev_inputs = [input.name for input in node.inputs]
|
||||
|
@ -530,28 +530,33 @@ def round_n(val, n):
|
||||
"""
|
||||
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:
|
||||
return
|
||||
preview_name = 'BSBST-preview'
|
||||
preview_img = bpy.data.images.get(preview_name)
|
||||
if not preview_img:
|
||||
preview_img = bpy.data.images.new(preview_name, width=256, height=256)
|
||||
if preview_img:
|
||||
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)
|
||||
if preview_texture:
|
||||
bpy.data.textures.remove(preview_texture)
|
||||
if not 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_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))
|
||||
|
||||
# TODO pack image
|
||||
# TODO delete pre-save
|
||||
# TODO set height of preview region
|
||||
|
||||
def register():
|
||||
bpy.app.handlers.depsgraph_update_post.append(refresh_preset)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user