Brushstroke Tools: Initial Version #328
@ -181,26 +181,8 @@ class BSBST_OT_new_brushstrokes(bpy.types.Operator):
|
|||||||
settings.active_context_brushstrokes_index = i
|
settings.active_context_brushstrokes_index = i
|
||||||
break
|
break
|
||||||
|
|
||||||
# set active/selected objects
|
if settings.edit_toggle:
|
||||||
active_object = brushstrokes_object
|
utils.edit_active_brushstrokes(context)
|
||||||
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")
|
|
||||||
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
class BSBST_OT_edit_brushstrokes(bpy.types.Operator):
|
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)
|
return bool(settings.context_brushstrokes)
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
|
return utils.edit_active_brushstrokes(context)
|
||||||
settings = context.scene.BSBST_settings
|
|
||||||
# TODO: refactor entering edit
|
|
||||||
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
class BSBST_OT_init_preset(bpy.types.Operator):
|
class BSBST_OT_init_preset(bpy.types.Operator):
|
||||||
"""
|
"""
|
||||||
|
@ -96,6 +96,7 @@ def get_active_context_brushstrokes_index(self):
|
|||||||
return self["active_context_brushstrokes_index"]
|
return self["active_context_brushstrokes_index"]
|
||||||
|
|
||||||
def set_active_context_brushstrokes_index(self, value):
|
def set_active_context_brushstrokes_index(self, value):
|
||||||
|
settings = bpy.context.scene.BSBST_settings
|
||||||
prev = self.get('active_context_brushstrokes_index')
|
prev = self.get('active_context_brushstrokes_index')
|
||||||
self["active_context_brushstrokes_index"] = value
|
self["active_context_brushstrokes_index"] = value
|
||||||
if prev == value:
|
if prev == value:
|
||||||
@ -104,14 +105,15 @@ def set_active_context_brushstrokes_index(self, value):
|
|||||||
if not bs_ob:
|
if not bs_ob:
|
||||||
return
|
return
|
||||||
bpy.context.view_layer.objects.active = bs_ob
|
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:
|
for ob in bpy.data.objects:
|
||||||
ob.select_set(False)
|
ob.select_set(False)
|
||||||
if utils.is_brushstrokes_object(ob):
|
if utils.is_brushstrokes_object(ob):
|
||||||
ob['BSBST_active'] = False
|
ob['BSBST_active'] = False
|
||||||
bs_ob.select_set(True)
|
bs_ob.select_set(True)
|
||||||
bs_ob['BSBST_active'] = True
|
bs_ob['BSBST_active'] = True
|
||||||
|
if settings.edit_toggle:
|
||||||
|
utils.edit_active_brushstrokes(bpy.context)
|
||||||
|
|
||||||
def link_context_type_items(self, context):
|
def link_context_type_items(self, context):
|
||||||
items = [
|
items = [
|
||||||
|
@ -223,11 +223,11 @@ class BSBST_PT_brushstroke_tools_panel(bpy.types.Panel):
|
|||||||
style_panel.label(text='No Brushstroke Context Found', icon='ERROR')
|
style_panel.label(text='No Brushstroke Context Found', icon='ERROR')
|
||||||
return
|
return
|
||||||
if not is_preset and len(settings.context_brushstrokes)>0:
|
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 = style_panel.row(align=True)
|
||||||
row.operator('brushstroke_tools.edit_brushstrokes', icon='GREASEPENCIL')
|
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)
|
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')
|
style_panel.prop(settings, 'preset_material', icon='MATERIAL')
|
||||||
if not settings.preset_object and is_preset:
|
if not settings.preset_object and is_preset:
|
||||||
style_panel.operator("brushstroke_tools.init_preset", icon='MODIFIER')
|
style_panel.operator("brushstroke_tools.init_preset", icon='MODIFIER')
|
||||||
|
@ -181,6 +181,37 @@ def context_brushstrokes(context):
|
|||||||
def flow_name(name):
|
def flow_name(name):
|
||||||
return f'{name}-FLOW'
|
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():
|
def register():
|
||||||
bpy.app.handlers.depsgraph_update_post.append(refresh_preset)
|
bpy.app.handlers.depsgraph_update_post.append(refresh_preset)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user