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
Showing only changes of commit c0744229de - Show all commits

View File

@ -4,7 +4,17 @@ from mathutils import Vector
from bpy.types import WorkSpaceTool
def preserve_draw_settings(context, restore=False):
props_list = ['curve_type', 'depth_mode', 'use_pressure_radius', 'use_project_only_selected', 'radius_max', 'surface_offset']
props_list = ['curve_type',
'depth_mode',
'use_pressure_radius',
'use_project_only_selected',
'radius_taper_start',
'radius_taper_end',
'radius_min',
'radius_max',
'surface_offset',
'use_offset_absolute',
'use_stroke_endpoints',]
if restore:
draw_settings_dict = context.scene['BSBST-TMP-draw_settings_dict']
for k, v in draw_settings_dict.items():
@ -25,8 +35,20 @@ class BSBST_tool_settings(bpy.types.PropertyGroup):
soft_max=1,
update=None,
)
radius_max: bpy.props.FloatProperty(name='Radius', default=1, min=0)
surface_offset: bpy.props.FloatProperty(name='Surface Offset', default=0)
radius_taper_start: bpy.props.FloatProperty(name='Taper Start', default=0, min=0, max=1, subtype='FACTOR')
radius_taper_end: bpy.props.FloatProperty(name='Taper End', default=0, min=0, max=1, subtype='FACTOR')
radius_min: bpy.props.FloatProperty(name='Radius Min', default=0, min=0, soft_max=10)
radius_max: bpy.props.FloatProperty(name='Radius Max', default=1, min=0, soft_max=10)
surface_offset: bpy.props.FloatProperty(name='Surface Offset', default=0, soft_max=10)
use_project_only_selected: bpy.props.BoolProperty(name='Project Onto Selected',
default=True,
description='Project the strokes only on selected objects if applicable.')
use_pressure_radius: bpy.props.BoolProperty(name='Use Pressure',
default=True,
description='Map tablet pressure to curve radius',)
use_offset_absolute: bpy.props.BoolProperty(name='Absolute Offset',
default=False,
description="Apply a fixed offset. (Don't scale by the radius.)")
class BSBST_OT_draw(bpy.types.Macro):
"""
@ -49,14 +71,24 @@ class BSBST_OT_pre_process_brushstroke(bpy.types.Operator):
preserve_draw_settings(context)
# fix some settings
context.tool_settings.curve_paint_settings.curve_type = 'POLY'
context.tool_settings.curve_paint_settings.depth_mode = 'SURFACE'
context.tool_settings.curve_paint_settings.use_pressure_radius = True
is_other_object_selected = len(set(context.selected_objects) - {context.object}) > 0
context.tool_settings.curve_paint_settings.use_project_only_selected = is_other_object_selected
context.tool_settings.curve_paint_settings.use_stroke_endpoints = False
context.tool_settings.curve_paint_settings.radius_max = tool_settings.radius_max
context.tool_settings.curve_paint_settings.surface_offset = tool_settings.surface_offset
is_other_object_selected = len(set(context.selected_objects) - {context.object}) > 0
context.tool_settings.curve_paint_settings.use_project_only_selected = is_other_object_selected and tool_settings.use_project_only_selected
# propagate some settings from custom tool
props_list = ['use_pressure_radius',
'radius_taper_start',
'radius_taper_end',
'radius_min',
'radius_max',
'surface_offset',
'use_offset_absolute',]
for prop in props_list:
setattr(context.tool_settings.curve_paint_settings, prop, getattr(tool_settings, prop))
return {'FINISHED'}
@ -116,12 +148,36 @@ class BrushstrokesCurves(WorkSpaceTool):
{"properties": []}),
)
def draw_settings(context, layout, tool):
def draw_settings(context, layout, tool, *, extra=False):
props = tool.operator_properties("brushstroke_tools.draw")
tool_settings = context.scene.BSBST_tool_settings
region_type = context.region.type
if region_type == 'TOOL_HEADER':
if not extra:
layout.prop(tool_settings , "radius_max")
layout.prop(tool_settings , "surface_offset")
layout.prop(tool_settings, "brush_color")
layout.popover("TOPBAR_PT_tool_settings_extra", text="...")
return
layout.use_property_split = True
layout.use_property_decorate = False
col = layout.column(align=True)
col.prop(tool_settings, "radius_taper_start", text="Taper Start", slider=True)
col.prop(tool_settings, "radius_taper_end", text="End", slider=True)
col = layout.column(align=True)
col.prop(tool_settings, "radius_min", text="Radius Min")
col.prop(tool_settings, "radius_max", text="Max")
col.prop(tool_settings, "use_pressure_radius", icon='STYLUS_PRESSURE', emboss=True)
layout.separator()
col = layout.column()
col.prop(tool_settings, "use_project_only_selected")
col.prop(tool_settings, "surface_offset")
col.prop(tool_settings, "use_offset_absolute")
classes = [
BSBST_tool_settings,