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 27 additions and 10 deletions
Showing only changes of commit 9df8627513 - Show all commits

View File

@ -14,7 +14,10 @@ class BSBST_OT_new_brushstrokes(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
return context.mode == 'OBJECT' object = context.object
if not object:
return False
return object.type in ['MESH', 'CURVE', 'CURVES', 'GREASEPENCIL']
def new_brushstrokes_object(self, context, name): def new_brushstrokes_object(self, context, name):
settings = context.scene.BSBST_settings settings = context.scene.BSBST_settings
@ -31,10 +34,6 @@ class BSBST_OT_new_brushstrokes(bpy.types.Operator):
brushstrokes_data = bpy.data.hair_curves.new(name) brushstrokes_data = bpy.data.hair_curves.new(name)
brushstrokes_object = bpy.data.objects.new(name, brushstrokes_data) brushstrokes_object = bpy.data.objects.new(name, brushstrokes_data)
context.collection.objects.link(brushstrokes_object) context.collection.objects.link(brushstrokes_object)
context.view_layer.objects.active = brushstrokes_object
for ob in bpy.data.objects:
ob.select_set(False)
brushstrokes_object.select_set(True)
return brushstrokes_object return brushstrokes_object
def new_flow_object(self, context, name): def new_flow_object(self, context, name):
@ -52,10 +51,6 @@ class BSBST_OT_new_brushstrokes(bpy.types.Operator):
flow_data = bpy.data.hair_curves.new(name) flow_data = bpy.data.hair_curves.new(name)
flow_object = bpy.data.objects.new(name, flow_data) flow_object = bpy.data.objects.new(name, flow_data)
context.collection.objects.link(flow_object) context.collection.objects.link(flow_object)
context.view_layer.objects.active = flow_object
for ob in bpy.data.objects:
ob.select_set(False)
flow_object.select_set(True)
return flow_object return flow_object
def execute(self, context): def execute(self, context):
@ -63,6 +58,7 @@ class BSBST_OT_new_brushstrokes(bpy.types.Operator):
settings = context.scene.BSBST_settings settings = context.scene.BSBST_settings
utils.ensure_resources() utils.ensure_resources()
bpy.ops.object.mode_set(mode='OBJECT')
context_object = context.object context_object = context.object
surf_ob = utils.get_surface_object(context_object) surf_ob = utils.get_surface_object(context_object)
@ -147,8 +143,26 @@ class BSBST_OT_new_brushstrokes(bpy.types.Operator):
for mod in brushstrokes_object.modifiers: for mod in brushstrokes_object.modifiers:
mod.show_group_selector = False mod.show_group_selector = False
# enter mode and tool context # update brushstroke context
context.view_layer.depsgraph.update()
print([bs.name for bs in settings.context_brushstrokes])
for i, name in enumerate([bs.name for bs in settings.context_brushstrokes]):
if name == brushstrokes_object.name:
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': if settings.curve_mode == 'GP':
bpy.ops.object.mode_set(mode='PAINT_GREASE_PENCIL') bpy.ops.object.mode_set(mode='PAINT_GREASE_PENCIL')
bpy.ops.wm.tool_set_by_id(name="builtin.draw") bpy.ops.wm.tool_set_by_id(name="builtin.draw")

View File

@ -98,7 +98,10 @@ def set_active_context_brushstrokes_index(self, value):
bpy.context.view_layer.objects.active = bs_ob bpy.context.view_layer.objects.active = bs_ob
for ob in bpy.data.objects: for ob in bpy.data.objects:
ob.select_set(False) ob.select_set(False)
if utils.is_brushstrokes_object(ob):
ob['BSBST_active'] = False
bs_ob.select_set(True) bs_ob.select_set(True)
bs_ob['BSBST_active'] = True
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='')