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
2 changed files with 60 additions and 0 deletions
Showing only changes of commit a43dc9f3ad - Show all commits

View File

@ -308,6 +308,61 @@ class BSBST_OT_duplicate_brushstrokes(bpy.types.Operator):
return {'FINISHED'}
class BSBST_OT_copy_brushstrokes(bpy.types.Operator):
"""
Copy the active context brushstrokes to the selected surface objects
"""
bl_idname = "brushstroke_tools.copy_brushstrokes"
bl_label = "Copy Brushstrokes to Selected"
bl_description = "Copy the active context brushstrokes to the selected surface objects"
bl_options = {"REGISTER", "UNDO"}
copy_all: bpy.props.BoolProperty(default=False)
@classmethod
def poll(cls, context):
settings = context.scene.BSBST_settings
return bool(settings.context_brushstrokes)
def execute(self, context):
settings = context.scene.BSBST_settings
surface_objects = [ob for ob in context.selected_objects if ob.type=='MESH' and not utils.is_brushstrokes_object(ob)]
if not surface_objects:
return {"CANCELLED"}
print(surface_objects)
if self.copy_all:
bs_objects = [bpy.data.objects.get(bs.name) for bs in settings.context]
bs_objects = [bs for bs in bs_objects if bs]
else:
bs_objects = [utils.get_active_context_brushstrokes_object(context)]
if not bs_objects:
return {"CANCELLED"}
bpy.ops.object.mode_set(mode='OBJECT')
for surface_object in surface_objects:
for bs_ob in bs_objects:
flow_object = utils.get_flow_object(bs_ob)
bpy.context.view_layer.objects.active = bs_ob
for ob in bpy.data.objects:
ob.select_set(False)
bs_ob.select_set(True)
flow_object.select_set(True)
bpy.ops.object.duplicate_move()
# remap surface pointers and context linked data
bs_ob.parent = surface_object
utils.set_surface_object(bs_ob, surface_object)
# TODO
# enable rest position
surface_object.add_rest_position_attribute = True
return {'FINISHED'}
class BSBST_OT_select_surface(bpy.types.Operator):
"""
Select the surface object for the active context brushstrokes.
@ -649,6 +704,7 @@ classes = [
BSBST_OT_edit_brushstrokes,
BSBST_OT_delete_brushstrokes,
BSBST_OT_duplicate_brushstrokes,
BSBST_OT_copy_brushstrokes,
BSBST_OT_select_surface,
BSBST_OT_init_preset,
BSBST_OT_make_preset,

View File

@ -282,6 +282,10 @@ class BSBST_PT_brushstroke_tools_panel(bpy.types.Panel):
column = row.column(align=True)
column.operator('brushstroke_tools.delete_brushstrokes', text='', icon='TRASH')
column.operator('brushstroke_tools.duplicate_brushstrokes', text='', icon='DUPLICATE')
column.operator('brushstroke_tools.copy_brushstrokes', text='', icon='DUPLICATE')
op = column.operator('brushstroke_tools.copy_brushstrokes', text='', icon='DUPLICATE')
op.copy_all = True
# TODO make nice
row = style_panel.row()
row_edit = row.row(align=True)