Add curve mode setting for different types of data #3

Merged
Simon Thommes merged 6 commits from add-curve-modes into master 2024-03-15 17:26:52 +01:00
4 changed files with 48 additions and 16 deletions
Showing only changes of commit f52e09838e - Show all commits

View File

@ -11,11 +11,11 @@ def node_group_settings(ng_settings, op_settings):
return return
class SCRIB_OT_draw_curves(bpy.types.Operator): class SCRIB_OT_draw(bpy.types.Operator):
""" """
Custom draw operation for hair curves Custom draw operation for hair curves
""" """
bl_idname = "scribble_buddy.draw_curves" bl_idname = "scribble_buddy.draw"
bl_label = "Custom Draw" bl_label = "Custom Draw"
bl_options = {'REGISTER', 'UNDO'} bl_options = {'REGISTER', 'UNDO'}
@ -66,7 +66,7 @@ class ScribbleCurves(WorkSpaceTool):
bl_space_type = 'VIEW_3D' bl_space_type = 'VIEW_3D'
bl_context_mode = 'EDIT_CURVES' bl_context_mode = 'EDIT_CURVES'
bl_idname = "scribble_buddy.draw_curves" bl_idname = "scribble_buddy.draw"
bl_label = "Scribble Draw" bl_label = "Scribble Draw"
bl_description = ( bl_description = (
"Scribble on the visible surface" "Scribble on the visible surface"
@ -74,17 +74,17 @@ class ScribbleCurves(WorkSpaceTool):
bl_icon = "brush.gpencil_draw.draw" bl_icon = "brush.gpencil_draw.draw"
bl_widget = None bl_widget = None
bl_keymap = ( bl_keymap = (
("scribble_buddy.draw_curves", {"type": 'LEFTMOUSE', "value": 'CLICK_DRAG'}, ("scribble_buddy.draw", {"type": 'LEFTMOUSE', "value": 'CLICK_DRAG'},
{"properties": [("wait_for_input", False)]}), {"properties": [("wait_for_input", False)]}),
) )
def draw_settings(context, layout, tool): def draw_settings(context, layout, tool):
props = tool.operator_properties("scribble_buddy.draw_curves") props = tool.operator_properties("scribble_buddy.draw")
layout.prop(context.tool_settings.curve_paint_settings , "radius_max") layout.prop(context.tool_settings.curve_paint_settings , "radius_max")
layout.prop(props, "brush_color") layout.prop(props, "brush_color")
classes = [ classes = [
SCRIB_OT_draw_curves, SCRIB_OT_draw,
] ]
def register(): def register():

20
ops.py
View File

@ -24,7 +24,19 @@ class SCRIB_OT_new_scribble(bpy.types.Operator):
surface_object = context.object if context.object in context.selected_objects else None surface_object = context.object if context.object in context.selected_objects else None
scribble_object = bpy.data.objects.new('Scribble', bpy.data.hair_curves.new('Scribble')) name = 'Scribble'
if settings.curve_mode == 'GP':
bpy.ops.object.grease_pencil_add(type='EMPTY')
context.object.name = name
context.object.data.name = name
scribble_object = context.object
else:
if settings.curve_mode == 'CURVE':
scribble_data = bpy.data.curves.new(name, type='CURVE')
elif settings.curve_mode == 'CURVES':
scribble_data = bpy.data.hair_curves.new(name)
scribble_object = bpy.data.objects.new(name, scribble_data)
context.collection.objects.link(scribble_object) context.collection.objects.link(scribble_object)
context.view_layer.objects.active = scribble_object context.view_layer.objects.active = scribble_object
for ob in bpy.data.objects: for ob in bpy.data.objects:
@ -91,6 +103,12 @@ class SCRIB_OT_new_scribble(bpy.types.Operator):
mod.show_group_selector = False mod.show_group_selector = False
# enter mode and tool context # 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.object.mode_set(mode='EDIT')
bpy.ops.wm.tool_set_by_id(name="scribble_buddy.draw_curves") bpy.ops.wm.tool_set_by_id(name="scribble_buddy.draw_curves")

View File

@ -18,6 +18,19 @@ class SCRIB_Settings(bpy.types.PropertyGroup):
('SCRIBBLE', 'Scribble', 'Specify the style of the currently active scribble', '', 1), ('SCRIBBLE', 'Scribble', 'Specify the style of the currently active scribble', '', 1),
('AUTO', 'Auto', 'Specify the style of either the active scribble or the preset depending on the context', '', 2), ('AUTO', 'Auto', 'Specify the style of either the active scribble or the preset depending on the context', '', 2),
]) ])
if 'experimental' in dir(bpy.context.preferences):
gpv3 = bpy.context.preferences.experimental.use_grease_pencil_version3
else:
gpv3 = False
curve_mode: bpy.props.EnumProperty(default='CURVE',
items= [('CURVE', 'Legacy', 'Use legacy curve type', 'CURVE_DATA', 0),\
('CURVES', 'Hair', 'Use hair curves', 'CURVES_DATA', 1),
('GP', 'Grease Pencil', 'Grease Pencil currently with limited support', 'OUTLINER_OB_GREASEPENCIL', 2),
] if gpv3 else
[('CURVE', 'Legacy', 'Use legacy curve type', 'CURVE_DATA', 0),\
('CURVES', 'Hair', 'Use hair curves', 'CURVES_DATA', 1),
])
#preset_mode #preset_mode
classes = [ classes = [

1
ui.py
View File

@ -72,6 +72,7 @@ class SCRIB_PT_scribble_buddy_panel(bpy.types.Panel):
surface_object = context.object surface_object = context.object
layout.label(text=surface_object.name, icon='OUTLINER_OB_SURFACE') layout.label(text=surface_object.name, icon='OUTLINER_OB_SURFACE')
if surface_object: if surface_object:
layout.prop(settings, 'curve_mode', expand=True)
layout.operator("scribble_buddy.new_scribble", icon='GREASEPENCIL') layout.operator("scribble_buddy.new_scribble", icon='GREASEPENCIL')
settings_header, settings_panel = layout.panel("scribble_settings", default_closed=True) settings_header, settings_panel = layout.panel("scribble_settings", default_closed=True)