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
3 changed files with 64 additions and 14 deletions
Showing only changes of commit 1b93000d5d - Show all commits

View File

@ -495,6 +495,46 @@ class BSBST_OT_select_surface(bpy.types.Operator):
return {"FINISHED"} return {"FINISHED"}
class BSBST_OT_assign_surface(bpy.types.Operator):
"""
Assign a surface object for the active context brushstrokes.
"""
bl_idname = "brushstroke_tools.assign_surface"
bl_label = "Assign Surface"
bl_description = "Assign a surface object for the active context brushstrokes"
bl_options = {"REGISTER", "UNDO"}
surface_object: bpy.props.StringProperty()
@classmethod
def poll(cls, context):
settings = context.scene.BSBST_settings
return bool(settings.context_brushstrokes)
def execute(self, context):
bs_ob = utils.get_active_context_brushstrokes_object(context)
if not bs_ob:
return {"CANCELLED"}
surface_object = bpy.data.objects.get(self.surface_object)
if not surface_object:
return {"CANCELLED"}
utils.set_surface_object(bs_ob, surface_object)
return {"FINISHED"}
def draw(self, context):
layout = self.layout
layout.prop_search(self, 'surface_object', bpy.data, 'objects')
def invoke(self, context, event):
bs_ob = utils.get_active_context_brushstrokes_object(context)
surf_ob = utils.get_surface_object(bs_ob)
if surf_ob:
self.surface_object = surf_ob.name
return context.window_manager.invoke_props_dialog(self)
def set_brushstrokes_deformable(bs_ob, deformable): def set_brushstrokes_deformable(bs_ob, deformable):
flow_ob = utils.get_flow_object(bs_ob) flow_ob = utils.get_flow_object(bs_ob)
@ -1039,6 +1079,7 @@ classes = [
BSBST_OT_copy_flow, BSBST_OT_copy_flow,
BSBST_OT_switch_deformable, BSBST_OT_switch_deformable,
BSBST_OT_select_surface, BSBST_OT_select_surface,
BSBST_OT_assign_surface,
BSBST_OT_init_preset, BSBST_OT_init_preset,
BSBST_OT_make_preset, BSBST_OT_make_preset,
BSBST_OT_preset_add_mod, BSBST_OT_preset_add_mod,

View File

@ -300,6 +300,8 @@ class BSBST_MT_bs_context_menu(bpy.types.Menu):
op = layout.operator('brushstroke_tools.copy_flow') op = layout.operator('brushstroke_tools.copy_flow')
op = layout.operator("brushstroke_tools.assign_surface")
class BSBST_PT_brushstroke_tools_panel(bpy.types.Panel): class BSBST_PT_brushstroke_tools_panel(bpy.types.Panel):
bl_space_type = 'VIEW_3D' bl_space_type = 'VIEW_3D'
bl_region_type = 'UI' bl_region_type = 'UI'

View File

@ -458,10 +458,15 @@ def get_surface_object(bs):
return None return None
return bs['BSBST_surface_object'] return bs['BSBST_surface_object']
def set_surface_object(bs, ob): def set_surface_object(bs, surf_ob):
if not bs: if not bs:
return return
objects = [bs]
flow_ob = get_flow_object(bs)
if flow_ob:
objects += [flow_ob]
# assign surface pointer # assign surface pointer
for ob in objects:
for mod in bs.modifiers: for mod in bs.modifiers:
mod_info = bs.modifier_info.get(mod.name) mod_info = bs.modifier_info.get(mod.name)
if not mod_info: if not mod_info:
@ -471,14 +476,16 @@ def set_surface_object(bs, ob):
continue continue
if not s.link_context_type == 'SURFACE_OBJECT': if not s.link_context_type == 'SURFACE_OBJECT':
continue continue
mod[s.name] = ob mod[s.name] = surf_ob
ob.update_tag() ob.parent = surf_ob
ob.parent_type = 'OBJECT'
surf_ob.update_tag()
if bs.type == 'CURVES': if bs.type == 'CURVES':
bs.data.surface = ob bs.data.surface = surf_ob
bs.data.surface_uv_map = ob.data.uv_layers.active.name bs.data.surface_uv_map = surf_ob.data.uv_layers.active.name
bs['BSBST_surface_object'] = ob bs['BSBST_surface_object'] = surf_ob
def get_flow_object(bs): def get_flow_object(bs):
if not bs: if not bs: