Brushstroke Tools: Initial Version #328
@ -135,7 +135,7 @@ def set_brush_style(self, 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]
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user