Add curve mode setting for different types of data #3
12
draw_tool.py
12
draw_tool.py
@ -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():
|
||||||
|
36
ops.py
36
ops.py
@ -24,12 +24,24 @@ 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')
|
||||||
|
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
|
||||||
@ -38,7 +50,7 @@ class SCRIB_OT_new_scribble(bpy.types.Operator):
|
|||||||
surface_object.add_rest_position_attribute = True # TODO report if library data
|
surface_object.add_rest_position_attribute = True # TODO report if library data
|
||||||
constraint = scribble_object.constraints.new('COPY_TRANSFORMS')
|
constraint = scribble_object.constraints.new('COPY_TRANSFORMS')
|
||||||
constraint.target = surface_object
|
constraint.target = surface_object
|
||||||
|
|
||||||
# assign preset material
|
# assign preset material
|
||||||
if settings.preset_material:
|
if settings.preset_material:
|
||||||
override = context.copy()
|
override = context.copy()
|
||||||
@ -91,8 +103,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_curves")
|
||||||
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
13
settings.py
13
settings.py
@ -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 = [
|
||||||
|
3
ui.py
3
ui.py
@ -72,7 +72,8 @@ 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.operator("scribble_buddy.new_scribble", icon='GREASEPENCIL')
|
layout.prop(settings, 'curve_mode', expand=True)
|
||||||
|
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")
|
||||||
|
Loading…
Reference in New Issue
Block a user