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 54 additions and 19 deletions

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'}
@ -48,8 +48,8 @@ class SCRIB_OT_draw_curves(bpy.types.Operator):
def invoke(self, context, event): def invoke(self, context, event):
utils.ensure_resources() utils.ensure_resources()
if True: if True:
SCRIB_OT_draw_curves.gp = None SCRIB_OT_draw.gp = None
SCRIB_OT_draw_curves.ng_process = bpy.data.node_groups['.scribble-buddy.processing'] SCRIB_OT_draw.ng_process = bpy.data.node_groups['.scribble-buddy.processing']
context.tool_settings.curve_paint_settings.curve_type = 'POLY' # TODO: restore later context.tool_settings.curve_paint_settings.curve_type = 'POLY' # TODO: restore later
context.tool_settings.curve_paint_settings.depth_mode = 'SURFACE' # TODO: restore later context.tool_settings.curve_paint_settings.depth_mode = 'SURFACE' # TODO: restore later
@ -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():

35
ops.py
View File

@ -24,12 +24,25 @@ 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'
context.collection.objects.link(scribble_object)
context.view_layer.objects.active = scribble_object if settings.curve_mode == 'GP':
for ob in bpy.data.objects: bpy.ops.object.grease_pencil_add(type='EMPTY')
ob.select_set(False) context.object.name = name
scribble_object.select_set(True) context.object.data.name = name
scribble_object = context.object
else:
if settings.curve_mode == 'CURVE':
scribble_data = bpy.data.curves.new(name, type='CURVE')
scribble_data.dimensions = '3D'
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.view_layer.objects.active = scribble_object
for ob in bpy.data.objects:
ob.select_set(False)
scribble_object.select_set(True)
# attach surface object pointer # attach surface object pointer
scribble_object['SCRIB_surface_object'] = surface_object scribble_object['SCRIB_surface_object'] = surface_object
@ -91,8 +104,14 @@ 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
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.wm.tool_set_by_id(name="scribble_buddy.draw_curves") 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="scribble_buddy.draw")
return {"FINISHED"} return {"FINISHED"}

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='CURVES',
items= [('CURVE', 'Legacy', 'Use legacy curve type (Limited Support)', 'CURVE_DATA', 0),\
('CURVES', 'Hair', 'Use hair curves (Fully supported)', 'CURVES_DATA', 1),
('GP', 'Grease Pencil', 'Use Grease Pencil (Limited Support)', 'OUTLINER_OB_GREASEPENCIL', 2),
] if gpv3 else
[('CURVE', 'Legacy', 'Use legacy curve type (Limited Support)', 'CURVE_DATA', 0),\
('CURVES', 'Hair', 'Use hair curves (Full Support)', 'CURVES_DATA', 1),
])
#preset_mode #preset_mode
classes = [ classes = [

7
ui.py
View File

@ -71,8 +71,11 @@ class SCRIB_PT_scribble_buddy_panel(bpy.types.Panel):
else: else:
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:
layout.operator("scribble_buddy.new_scribble", icon='GREASEPENCIL') layout.prop(settings, 'curve_mode', expand=True)
if settings.curve_mode in ['CURVE', 'GP']:
layout.label(text='Curve mode does not support drawing on deformed geometry', icon='ERROR')
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)
settings_header.label(text="Settings") settings_header.label(text="Settings")