Brushstroke Tools: Initial Version #328
@ -3,20 +3,26 @@ from . import utils
|
||||
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', ]
|
||||
if restore:
|
||||
draw_settings_dict = context.scene['BSBST-TMP-draw_settings_dict']
|
||||
for k, v in draw_settings_dict.items():
|
||||
setattr(context.tool_settings.curve_paint_settings, k, v)
|
||||
del context.scene['BSBST-TMP-draw_settings_dict']
|
||||
else:
|
||||
draw_settings_dict = dict()
|
||||
for item in props_list:
|
||||
draw_settings_dict[item] = getattr(context.tool_settings.curve_paint_settings, item)
|
||||
context.scene['BSBST-TMP-draw_settings_dict'] = draw_settings_dict
|
||||
|
||||
def node_group_settings(ng_settings, op_settings):
|
||||
|
||||
ng_settings.nodes['Color'].value = [*op_settings.brush_color, 1.]
|
||||
ng_settings.nodes['Smear'].outputs[0].default_value = op_settings.brush_smear
|
||||
#ng_settings.nodes["Object Info"].inputs[0].default_value = surface_object
|
||||
|
||||
class BSBST_OT_draw(bpy.types.Operator):
|
||||
"""
|
||||
Custom draw operation for hair curves
|
||||
"""
|
||||
bl_idname = "brushstroke_tools.draw"
|
||||
bl_label = "Custom Draw"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
class BSBST_tool_settings(bpy.types.PropertyGroup):
|
||||
brush_color: bpy.props.FloatVectorProperty(name='Brush Color',
|
||||
size=3,
|
||||
subtype='COLOR',
|
||||
@ -25,6 +31,38 @@ class BSBST_OT_draw(bpy.types.Operator):
|
||||
soft_max=1,
|
||||
update=None,
|
||||
)
|
||||
|
||||
class BSBST_OT_draw(bpy.types.Macro):
|
||||
"""
|
||||
Custom draw operation for hair curves
|
||||
"""
|
||||
bl_idname = "brushstroke_tools.draw"
|
||||
bl_label = "Custom Draw"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
class BSBST_OT_pre_process_brushstroke(bpy.types.Operator):
|
||||
"""
|
||||
Set up custom draw tool for curve drawing
|
||||
"""
|
||||
bl_idname = "brushstroke_tools.pre_process_brushstroke"
|
||||
bl_label = "Custom Draw Pre Process"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def execute(self, context):
|
||||
preserve_draw_settings(context)
|
||||
|
||||
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
|
||||
context.tool_settings.curve_paint_settings.use_project_only_selected = True
|
||||
return {'FINISHED'}
|
||||
|
||||
class BSBST_OT_post_process_brushstroke(bpy.types.Operator):
|
||||
"""
|
||||
"""
|
||||
bl_idname = "brushstroke_tools.post_process_brushstroke"
|
||||
bl_label = "Custom Draw Post Process"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
brush_smear: bpy.props.FloatProperty(name='Smear',
|
||||
subtype='FACTOR',
|
||||
default=0,
|
||||
@ -34,45 +72,36 @@ class BSBST_OT_draw(bpy.types.Operator):
|
||||
)
|
||||
|
||||
ng_process = None
|
||||
|
||||
init = True
|
||||
gp = None
|
||||
|
||||
def modal(self, context, event):
|
||||
if self.init:
|
||||
#bpy.ops.grease_pencil.brush_stroke('INVOKE_DEFAULT')
|
||||
bpy.ops.curves.draw('INVOKE_DEFAULT', wait_for_input=False)
|
||||
self.init = False
|
||||
else:
|
||||
self.ng_process.nodes['settings.color'].value = [*self.brush_color, 1.]
|
||||
self.ng_process.nodes['view_vector'].vector = context.space_data.region_3d.view_rotation @ Vector((0.0, 0.0, 1.0))
|
||||
self.ng_process.nodes['new_key'].boolean = context.scene.tool_settings.use_keyframe_insert_auto
|
||||
if 'BSBST_surface_object' in context.object.keys():
|
||||
if context.object['BSBST_surface_object']:
|
||||
self.ng_process.nodes['surface_object'].inputs[0].default_value = context.object['BSBST_surface_object']
|
||||
#node_group_settings(self.ng_settings, self)
|
||||
bpy.ops.geometry.execute_node_group(name="set_brush_stroke_color", session_uid=self.ng_process.session_uid)
|
||||
return {'FINISHED'}
|
||||
return {'RUNNING_MODAL'}
|
||||
def execute(self, context):
|
||||
if not self.ng_process:
|
||||
preserve_draw_settings(context, restore=True)
|
||||
return {'CANCELLED'}
|
||||
tool_settings = context.scene.BSBST_tool_settings
|
||||
|
||||
self.ng_process.nodes['settings.color'].value = [*tool_settings.brush_color, 1.]
|
||||
self.ng_process.nodes['view_vector'].vector = context.space_data.region_3d.view_rotation @ Vector((0.0, 0.0, 1.0))
|
||||
self.ng_process.nodes['new_key'].boolean = context.scene.tool_settings.use_keyframe_insert_auto
|
||||
if 'BSBST_surface_object' in context.object.keys():
|
||||
if context.object['BSBST_surface_object']:
|
||||
self.ng_process.nodes['surface_object'].inputs[0].default_value = context.object['BSBST_surface_object']
|
||||
bpy.ops.geometry.execute_node_group(name="set_brush_stroke_color", session_uid=self.ng_process.session_uid)
|
||||
|
||||
preserve_draw_settings(context, restore=True)
|
||||
return {'FINISHED'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
utils.ensure_resources()
|
||||
if True:
|
||||
BSBST_OT_draw.gp = None
|
||||
BSBST_OT_draw.ng_process = bpy.data.node_groups['.brushstroke_tools.processing']
|
||||
|
||||
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.use_pressure_radius = True # TODO: restore later
|
||||
context.tool_settings.curve_paint_settings.use_project_only_selected = True # TODO: restore later
|
||||
|
||||
context.window_manager.modal_handler_add(self)
|
||||
return {'RUNNING_MODAL'}
|
||||
else:
|
||||
self.report({'WARNING'}, "Not editable")
|
||||
return {'CANCELLED'}
|
||||
self.gp = None
|
||||
self.ng_process = bpy.data.node_groups['.brushstroke_tools.processing']
|
||||
return self.execute(context)
|
||||
|
||||
def register_custom_draw_macro():
|
||||
op = BSBST_OT_draw.define("brushstroke_tools.pre_process_brushstroke")
|
||||
op = BSBST_OT_draw.define("curves.draw")
|
||||
op.properties.wait_for_input = False
|
||||
op = BSBST_OT_draw.define("brushstroke_tools.post_process_brushstroke")
|
||||
|
||||
class BrushstrokesCurves(WorkSpaceTool):
|
||||
bl_space_type = 'VIEW_3D'
|
||||
@ -92,20 +121,27 @@ class BrushstrokesCurves(WorkSpaceTool):
|
||||
|
||||
def draw_settings(context, layout, tool):
|
||||
props = tool.operator_properties("brushstroke_tools.draw")
|
||||
tool_settings = context.scene.BSBST_tool_settings
|
||||
layout.prop(context.tool_settings.curve_paint_settings , "radius_max")
|
||||
layout.prop(context.tool_settings.curve_paint_settings , "surface_offset")
|
||||
layout.prop(props, "brush_color")
|
||||
layout.prop(tool_settings, "brush_color")
|
||||
|
||||
classes = [
|
||||
BSBST_tool_settings,
|
||||
BSBST_OT_pre_process_brushstroke,
|
||||
BSBST_OT_post_process_brushstroke,
|
||||
BSBST_OT_draw,
|
||||
]
|
||||
|
||||
def register():
|
||||
for c in classes:
|
||||
bpy.utils.register_class(c)
|
||||
bpy.types.Scene.BSBST_tool_settings = bpy.props.PointerProperty(type=BSBST_tool_settings)
|
||||
register_custom_draw_macro()
|
||||
bpy.utils.register_tool(BrushstrokesCurves, after={"builtin.draw"}, group=True)
|
||||
|
||||
def unregister():
|
||||
for c in reversed(classes):
|
||||
bpy.utils.unregister_class(c)
|
||||
bpy.utils.unregister_tool(BrushstrokesCurves)
|
||||
bpy.utils.unregister_tool(BrushstrokesCurves)
|
||||
del bpy.types.Scene.BSBST_tool_settings
|
Loading…
Reference in New Issue
Block a user