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
4 changed files with 16 additions and 3 deletions
Showing only changes of commit 515c824dc1 - Show all commits

View File

@ -1,4 +1,5 @@
import bpy import bpy
import random
from . import utils from . import utils
class BSBST_OT_new_brushstrokes(bpy.types.Operator): class BSBST_OT_new_brushstrokes(bpy.types.Operator):
@ -118,7 +119,15 @@ class BSBST_OT_new_brushstrokes(bpy.types.Operator):
elif link_context_type=='MATERIAL': elif link_context_type=='MATERIAL':
brushstrokes_object.modifiers[mod.name][f'{v.identifier}'] = settings.preset_material brushstrokes_object.modifiers[mod.name][f'{v.identifier}'] = settings.preset_material
elif link_context_type=='UVMAP': elif link_context_type=='UVMAP':
brushstrokes_object.modifiers[mod.name][f'{v.identifier}_use_attribute'] = True
brushstrokes_object.modifiers[mod.name][f'{v.identifier}_attribute_name'] = surface_object.data.uv_layers.active.name brushstrokes_object.modifiers[mod.name][f'{v.identifier}_attribute_name'] = surface_object.data.uv_layers.active.name
elif link_context_type=='RANDOM':
vmin = v.min_value
vmax = v.max_value
val = vmin + random.random() * (vmax - vmin)
brushstrokes_object.modifiers[mod.name][f'{v.identifier}_use_attribute'] = False
brushstrokes_object.modifiers[mod.name][f'{v.identifier}'] = type(brushstrokes_object.modifiers[mod.name][f'{v.identifier}'])(val)
# refresh UI # refresh UI
for mod in brushstrokes_object.modifiers: for mod in brushstrokes_object.modifiers:
mod.node_group.interface_update(context) mod.node_group.interface_update(context)
@ -213,6 +222,7 @@ class BSBST_OT_init_preset(bpy.types.Operator):
utils.mark_socket_context_type(mod_info, 'Socket_2', 'FLOW_OBJECT') utils.mark_socket_context_type(mod_info, 'Socket_2', 'FLOW_OBJECT')
utils.mark_socket_context_type(mod_info, 'Socket_3', 'UVMAP') utils.mark_socket_context_type(mod_info, 'Socket_3', 'UVMAP')
utils.mark_socket_context_type(mod_info, 'Socket_9', 'RANDOM')
def init_draw(self, context): def init_draw(self, context):
settings = context.scene.BSBST_settings settings = context.scene.BSBST_settings
@ -241,6 +251,7 @@ class BSBST_OT_init_preset(bpy.types.Operator):
mod_info.name = mod.name mod_info.name = mod.name
utils.mark_socket_context_type(mod_info, 'Socket_2', 'SURFACE_OBJECT') utils.mark_socket_context_type(mod_info, 'Socket_2', 'SURFACE_OBJECT')
utils.mark_socket_context_type(mod_info, 'Socket_6', 'RANDOM')
def execute(self, context): def execute(self, context):

View File

@ -103,7 +103,7 @@ def link_context_type_items(self, context):
('FLOW_OBJECT', 'Flow Object', 'Link socket preset to context flow object', 'FORCE_WIND', 11), ('FLOW_OBJECT', 'Flow Object', 'Link socket preset to context flow object', 'FORCE_WIND', 11),
('MATERIAL', 'Material', 'Link socket preset to context material', 'MATERIAL', 101), ('MATERIAL', 'Material', 'Link socket preset to context material', 'MATERIAL', 101),
('UVMAP', 'UV Map', 'Link socket preset to active context UVMap', 'UV', 201), ('UVMAP', 'UV Map', 'Link socket preset to active context UVMap', 'UV', 201),
('RANDOM', 'Random', '', icons.icon_previews['main']["RANDOM"].icon_id, 501), ('RANDOM', 'Random', 'Randomize input value', icons.icon_previews['main']["RANDOM"].icon_id, 501),
] ]
return items return items

View File

@ -53,7 +53,7 @@ def draw_panel_ui_recursive(panel, panel_name, mod, items):
input_row.prop(mod, f'["{v.identifier}"]', text=k) input_row.prop(mod, f'["{v.identifier}"]', text=k)
if not mod_info: if not mod_info:
continue continue
if type(v) in utils.linkable_sockets and (attribute_toggle or f'{v.identifier}_use_attribute' not in mod.keys()): if type(v) in utils.linkable_sockets:
s = mod_info.socket_info.get(v.identifier) s = mod_info.socket_info.get(v.identifier)
if not s: if not s:
continue continue

View File

@ -13,7 +13,9 @@ ng_list = [
linkable_sockets = [ linkable_sockets = [
bpy.types.NodeTreeInterfaceSocketObject, bpy.types.NodeTreeInterfaceSocketObject,
bpy.types.NodeTreeInterfaceSocketMaterial, bpy.types.NodeTreeInterfaceSocketMaterial,
bpy.types.NodeTreeInterfaceSocketVector bpy.types.NodeTreeInterfaceSocketVector,
bpy.types.NodeTreeInterfaceSocketFloat,
bpy.types.NodeTreeInterfaceSocketInt,
] ]
@persistent @persistent