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 40 additions and 29 deletions
Showing only changes of commit 96511099d6 - Show all commits

View File

@ -181,26 +181,8 @@ class BSBST_OT_new_brushstrokes(bpy.types.Operator):
settings.active_context_brushstrokes_index = i
break
# set active/selected objects
active_object = brushstrokes_object
if flow_object:
active_object = flow_object
context.view_layer.objects.active = active_object
for ob in bpy.data.objects:
ob.select_set(False)
surface_object.select_set(True)
active_object.select_set(True)
# enter mode and tool context
if settings.curve_mode == 'GP':
bpy.ops.object.mode_set(mode='PAINT_GREASE_PENCIL')
bpy.ops.wm.tool_set_by_id(name="builtin.draw")
context.scene.tool_settings.gpencil_stroke_placement_view3d = 'SURFACE'
else:
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.wm.tool_set_by_id(name="brushstroke_tools.draw")
if settings.edit_toggle:
utils.edit_active_brushstrokes(context)
return {"FINISHED"}
class BSBST_OT_edit_brushstrokes(bpy.types.Operator):
@ -218,11 +200,7 @@ class BSBST_OT_edit_brushstrokes(bpy.types.Operator):
return bool(settings.context_brushstrokes)
def execute(self, context):
settings = context.scene.BSBST_settings
# TODO: refactor entering edit
return {"FINISHED"}
return utils.edit_active_brushstrokes(context)
class BSBST_OT_init_preset(bpy.types.Operator):
"""

View File

@ -96,6 +96,7 @@ def get_active_context_brushstrokes_index(self):
return self["active_context_brushstrokes_index"]
def set_active_context_brushstrokes_index(self, value):
settings = bpy.context.scene.BSBST_settings
prev = self.get('active_context_brushstrokes_index')
self["active_context_brushstrokes_index"] = value
if prev == value:
@ -104,14 +105,15 @@ def set_active_context_brushstrokes_index(self, value):
if not bs_ob:
return
bpy.context.view_layer.objects.active = bs_ob
if not bs_ob.hide_viewport:
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='OBJECT')
for ob in bpy.data.objects:
ob.select_set(False)
if utils.is_brushstrokes_object(ob):
ob['BSBST_active'] = False
bs_ob.select_set(True)
bs_ob['BSBST_active'] = True
if settings.edit_toggle:
utils.edit_active_brushstrokes(bpy.context)
def link_context_type_items(self, context):
items = [

View File

@ -223,11 +223,11 @@ class BSBST_PT_brushstroke_tools_panel(bpy.types.Panel):
style_panel.label(text='No Brushstroke Context Found', icon='ERROR')
return
if not is_preset and len(settings.context_brushstrokes)>0:
style_panel.template_list("BSBST_UL_brushstroke_objects", "", settings, "context_brushstrokes",
settings, "active_context_brushstrokes_index", rows=1, maxrows=5, sort_lock=True)
row = style_panel.row(align=True)
row.operator('brushstroke_tools.edit_brushstrokes', icon='GREASEPENCIL')
row.prop(settings, 'edit_toggle', icon='RESTRICT_SELECT_OFF' if settings.edit_toggle else 'RESTRICT_SELECT_ON', icon_only=True)
style_panel.template_list("BSBST_UL_brushstroke_objects", "", settings, "context_brushstrokes",
settings, "active_context_brushstrokes_index", rows=1, maxrows=5, sort_lock=True)
style_panel.prop(settings, 'preset_material', icon='MATERIAL')
if not settings.preset_object and is_preset:
style_panel.operator("brushstroke_tools.init_preset", icon='MODIFIER')

View File

@ -181,6 +181,37 @@ def context_brushstrokes(context):
def flow_name(name):
return f'{name}-FLOW'
def edit_active_brushstrokes(context):
context.view_layer.depsgraph.update()
settings = context.scene.BSBST_settings
active_bs = settings.context_brushstrokes[settings.active_context_brushstrokes_index]
bs_ob = bpy.data.objects.get(active_bs.name)
if not bs_ob:
return {"CANCELLED"}
flow_object = get_flow_object(bs_ob)
surface_object = get_surface_object(bs_ob)
active_object = bs_ob
if flow_object:
active_object = flow_object
context.view_layer.objects.active = active_object
for ob in bpy.data.objects:
ob.select_set(False)
surface_object.select_set(True)
active_object.select_set(True)
# enter mode and tool context
if active_object.type=='GREASEPENCIL':
bpy.ops.object.mode_set(mode='PAINT_GREASE_PENCIL')
bpy.ops.wm.tool_set_by_id(name="builtin.draw")
context.scene.tool_settings.gpencil_stroke_placement_view3d = 'SURFACE'
else:
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.wm.tool_set_by_id(name="brushstroke_tools.draw")
return {'FINISHED'}
def register():
bpy.app.handlers.depsgraph_update_post.append(refresh_preset)