Brushstroke Tools: Initial Version #328
@ -40,6 +40,14 @@ def update_context_material(self, context):
|
||||
if not style_object:
|
||||
return
|
||||
utils.set_brushstroke_material(style_object, self.context_material)
|
||||
ng = bpy.data.node_groups.get(f'BSBST-BS.{self.context_material.brush_style}')
|
||||
if not ng:
|
||||
utils.set_preview(None)
|
||||
return
|
||||
if ng.preview:
|
||||
utils.set_preview(ng.preview.image_pixels_float, ng.preview.image_size[:], ng.name)
|
||||
else:
|
||||
utils.set_preview(None)
|
||||
|
||||
def update_link_context_type(self, context):
|
||||
self.link_context = True
|
||||
@ -134,11 +142,10 @@ def set_brush_style(self, 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)
|
||||
|
||||
if utils.compare_versions(bpy.app.version, (4,2,4)) >= 0:
|
||||
if ng.preview:
|
||||
utils.set_preview(ng.preview.image_pixels_float, ng.preview.image_size[:])
|
||||
else:
|
||||
utils.set_preview(None)
|
||||
if ng.preview:
|
||||
utils.set_preview(ng.preview.image_pixels_float, ng.preview.image_size[:], ng.name)
|
||||
else:
|
||||
utils.set_preview(None)
|
||||
|
||||
node = self.node_tree.nodes['Brush Style']
|
||||
node_prev_inputs = [input.name for input in node.inputs]
|
||||
|
@ -6,6 +6,8 @@ from bpy.app.handlers import persistent
|
||||
|
||||
addon_version = (0,0,0)
|
||||
|
||||
preview_name = '.BSBST-preview'
|
||||
|
||||
ng_list = [
|
||||
".brushstroke_tools.draw_processing",
|
||||
".brushstroke_tools.pre_processing",
|
||||
@ -587,17 +589,23 @@ def round_n(val, n):
|
||||
"""
|
||||
return round(val, n-int(math.floor(math.log10(abs(val))))-1)
|
||||
|
||||
def set_preview(pixels, size = (256, 256)):
|
||||
preview_name = '.BSBST-preview'
|
||||
def clear_preview():
|
||||
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)
|
||||
if preview_img:
|
||||
bpy.data.images.remove(preview_img)
|
||||
if preview_texture:
|
||||
bpy.data.textures.remove(preview_texture)
|
||||
|
||||
def set_preview(pixels, size = (256, 256), id=''):
|
||||
preview_img = bpy.data.images.get(preview_name)
|
||||
preview_texture = bpy.data.textures.get(preview_name)
|
||||
if not pixels or compare_versions(bpy.app.version, (4,2,4)) < 0:
|
||||
clear_preview()
|
||||
return
|
||||
if preview_img:
|
||||
if id and id == preview_img['BSBST-id']:
|
||||
return
|
||||
if not len(preview_img.pixels) == len(pixels):
|
||||
bpy.data.images.remove(preview_img)
|
||||
preview_img = None
|
||||
@ -613,6 +621,7 @@ def set_preview(pixels, size = (256, 256)):
|
||||
preview_texture.image = preview_img
|
||||
|
||||
preview_img.pixels.foreach_set(numpy.array(pixels, dtype=numpy.float32))
|
||||
preview_img['BSBST-id'] = id
|
||||
|
||||
preview_img.pack()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user