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 32 additions and 3 deletions
Showing only changes of commit 0742269206 - Show all commits

View File

@ -75,7 +75,7 @@ class BSBST_OT_new_brushstrokes(bpy.types.Operator):
brushstrokes_object = self.new_brushstrokes_object(context, name) brushstrokes_object = self.new_brushstrokes_object(context, name)
flow_is_required = settings.brushstroke_method == 'SURFACE_FILL' flow_is_required = settings.brushstroke_method == 'SURFACE_FILL'
if flow_is_required: if flow_is_required:
flow_object = self.new_flow_object(context, f'{name}-FLOW') flow_object = self.new_flow_object(context, utils.flow_name(name))
# attach surface object pointer # attach surface object pointer
if surface_object: if surface_object:

View File

@ -6,6 +6,9 @@ from bpy.app.handlers import persistent
def find_context_brushstrokes(dummy): def find_context_brushstrokes(dummy):
context = bpy.context context = bpy.context
settings = context.scene.BSBST_settings settings = context.scene.BSBST_settings
len_prev = len(settings.context_brushstrokes)
name_prev = settings.context_brushstrokes[settings.active_context_brushstrokes_index].name if len_prev else ''
idx = settings.active_context_brushstrokes_index
# identify context brushstrokes # identify context brushstrokes
for el in range(len(settings.context_brushstrokes)): for el in range(len(settings.context_brushstrokes)):
settings.context_brushstrokes.remove(0) settings.context_brushstrokes.remove(0)
@ -27,6 +30,11 @@ def find_context_brushstrokes(dummy):
bs = settings.context_brushstrokes.add() bs = settings.context_brushstrokes.add()
bs.name = ob.name bs.name = ob.name
bs.method = ob['BSBST_method'] bs.method = ob['BSBST_method']
if name_prev == ob.name:
idx = len(settings.context_brushstrokes)-1
if len_prev == len(settings.context_brushstrokes):
settings.active_context_brushstrokes_index = idx
settings.active_context_brushstrokes_index = max(min(settings.active_context_brushstrokes_index, len(settings.context_brushstrokes)-1), 0) settings.active_context_brushstrokes_index = max(min(settings.active_context_brushstrokes_index, len(settings.context_brushstrokes)-1), 0)
return return
@ -45,6 +53,24 @@ def update_brushstroke_method(self, context):
preset_object = bpy.data.objects.get(preset_name) preset_object = bpy.data.objects.get(preset_name)
settings.preset_object = preset_object settings.preset_object = preset_object
return return
def get_brushstroke_name(self):
return self["name"]
def set_brushstroke_name(self, value):
prev_name = self.get('name')
self["name"] = value
if not prev_name:
return
ob = bpy.data.objects.get(prev_name)
if not ob:
return
ob.name = value
flow_ob = utils.get_flow_object(ob)
if flow_ob:
flow_ob.name = utils.flow_name(value)
return
class BSBST_link_context_setting(bpy.types.PropertyGroup): class BSBST_link_context_setting(bpy.types.PropertyGroup):
name: bpy.props.StringProperty(default='') name: bpy.props.StringProperty(default='')
link_context: bpy.props.BoolProperty(default=False) link_context: bpy.props.BoolProperty(default=False)
@ -54,7 +80,7 @@ class BSBST_socket_info(bpy.types.PropertyGroup):
socket_info: bpy.props.CollectionProperty(type=BSBST_link_context_setting) socket_info: bpy.props.CollectionProperty(type=BSBST_link_context_setting)
class BSBST_context_brushstrokes(bpy.types.PropertyGroup): class BSBST_context_brushstrokes(bpy.types.PropertyGroup):
name: bpy.props.StringProperty(default='') name: bpy.props.StringProperty(default='', get=get_brushstroke_name, set=set_brushstroke_name)
method: bpy.props.StringProperty(default='') method: bpy.props.StringProperty(default='')
class BSBST_Settings(bpy.types.PropertyGroup): class BSBST_Settings(bpy.types.PropertyGroup):

View File

@ -64,7 +64,7 @@ class BSBST_UL_brushstroke_objects(bpy.types.UIList):
method_icon = 'OUTLINER_OB_FORCE_FIELD' method_icon = 'OUTLINER_OB_FORCE_FIELD'
elif context_brushstroke.method == 'SURFACE_DRAW': elif context_brushstroke.method == 'SURFACE_DRAW':
method_icon = 'OUTLINER_DATA_GP_LAYER' method_icon = 'OUTLINER_DATA_GP_LAYER'
layout.label(text=context_brushstroke.name, icon=method_icon) layout.prop(context_brushstroke, 'name', text='', emboss=False, icon=method_icon)
else: else:
layout.label(text="", translate=False, icon_value=icon) layout.label(text="", translate=False, icon_value=icon)
elif self.layout_type == 'GRID': elif self.layout_type == 'GRID':

View File

@ -119,6 +119,9 @@ def context_brushstrokes(context):
settings = context.scene.BSBST_settings settings = context.scene.BSBST_settings
return settings.context_brushstrokes return settings.context_brushstrokes
def flow_name(name):
return f'{name}-FLOW'
def register(): def register():
bpy.app.handlers.depsgraph_update_post.append(refresh_preset) bpy.app.handlers.depsgraph_update_post.append(refresh_preset)