From 0d5ec990a9844e639fa6ab989b14b2e051ac8c42 Mon Sep 17 00:00:00 2001 From: Pablo Dobarro Date: Thu, 8 Oct 2020 00:00:36 +0200 Subject: Sculpt: Experimental Pen Tilt Support This adds support for pen tilt in sculpt mode. For now, pen tilt is used by tweaking the tilt strength property, which controls how much the pen angle affects the sculpt normal. This is available in Draw, Draw Sharp, Flatten, Fill, Scrape and Clay Strips brushes, but it can be enabled in more tools later. The purpose of this patch is to have a usable implementation of pen tilt in a painting mode, so users can test and see in which hardware and platforms this feature is supported and how well it works. If it works ok, more tools and features that rely on pen tilt can be implemented, like brushes that blend between two deformations depending on the angle. Reviewed By: sergey Differential Revision: https://developer.blender.org/D8893 --- source/blender/makesrna/intern/rna_brush.c | 33 ++++++++++++++++++++++++++++ source/blender/makesrna/intern/rna_userdef.c | 5 +++++ 2 files changed, 38 insertions(+) (limited to 'source/blender/makesrna/intern') diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c index 70d613f8b21..eed278c3980 100644 --- a/source/blender/makesrna/intern/rna_brush.c +++ b/source/blender/makesrna/intern/rna_brush.c @@ -557,6 +557,19 @@ static bool rna_BrushCapabilitiesSculpt_has_gravity_get(PointerRNA *ptr) return !ELEM(br->sculpt_tool, SCULPT_TOOL_MASK, SCULPT_TOOL_SMOOTH); } +static bool rna_BrushCapabilitiesSculpt_has_tilt_get(PointerRNA *ptr) +{ + Brush *br = (Brush *)ptr->data; + return ELEM(br->sculpt_tool, + SCULPT_TOOL_DRAW, + SCULPT_TOOL_DRAW_SHARP, + SCULPT_TOOL_FLATTEN, + SCULPT_TOOL_FILL, + SCULPT_TOOL_SCRAPE, + SCULPT_TOOL_CLAY_STRIPS, + SCULPT_TOOL_CLAY_THUMB); +} + static bool rna_TextureCapabilities_has_texture_angle_source_get(PointerRNA *ptr) { MTex *mtex = (MTex *)ptr->data; @@ -1137,6 +1150,7 @@ static void rna_def_sculpt_capabilities(BlenderRNA *brna) SCULPT_TOOL_CAPABILITY(has_strength_pressure, "Has Strength Pressure"); SCULPT_TOOL_CAPABILITY(has_direction, "Has Direction"); SCULPT_TOOL_CAPABILITY(has_gravity, "Has Gravity"); + SCULPT_TOOL_CAPABILITY(has_tilt, "Has Tilt"); # undef SCULPT_CAPABILITY } @@ -2796,6 +2810,15 @@ static void rna_def_brush(BlenderRNA *brna) "Best used on low-poly meshes as it has a performance impact"); RNA_def_property_update(prop, 0, "rna_Brush_update"); + prop = RNA_def_property(srna, "tilt_strength_factor", PROP_FLOAT, PROP_FACTOR); + RNA_def_property_float_sdna(prop, NULL, "tilt_strength_factor"); + RNA_def_property_float_default(prop, 0); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.001, 3); + RNA_def_property_ui_text( + prop, "Tilt Strength", "How much the tilt of the pen will affect the brush"); + RNA_def_property_update(prop, 0, "rna_Brush_update"); + prop = RNA_def_property(srna, "normal_radius_factor", PROP_FLOAT, PROP_FACTOR); RNA_def_property_float_sdna(prop, NULL, "normal_radius_factor"); RNA_def_property_range(prop, 0.0f, 2.0f); @@ -3417,6 +3440,16 @@ static void rna_def_operator_stroke_element(BlenderRNA *brna) RNA_def_property_flag(prop, PROP_IDPROPERTY); RNA_def_property_ui_text(prop, "Flip", ""); + prop = RNA_def_property(srna, "x_tilt", PROP_FLOAT, PROP_FACTOR); + RNA_def_property_flag(prop, PROP_IDPROPERTY); + RNA_def_property_range(prop, -1.0f, 1.0f); + RNA_def_property_ui_text(prop, "Tilt X", ""); + + prop = RNA_def_property(srna, "y_tilt", PROP_FLOAT, PROP_FACTOR); + RNA_def_property_flag(prop, PROP_IDPROPERTY); + RNA_def_property_range(prop, -1.0f, 1.0f); + RNA_def_property_ui_text(prop, "Tilt Y", ""); + /* used in uv painting */ prop = RNA_def_property(srna, "time", PROP_FLOAT, PROP_UNSIGNED); RNA_def_property_flag(prop, PROP_IDPROPERTY); diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 633611b9e50..6698e0ff237 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -6178,6 +6178,11 @@ static void rna_def_userdef_experimental(BlenderRNA *brna) prop = RNA_def_property(srna, "use_tools_missing_icons", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "use_tools_missing_icons", 1); RNA_def_property_ui_text(prop, "Tools with Missing Icons", "Show tools with missing icons"); + + prop = RNA_def_property(srna, "use_sculpt_tools_tilt", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "use_sculpt_tools_tilt", 1); + RNA_def_property_ui_text( + prop, "Sculpt Mode Tilt Support", "Support for pen tablet tilt events in Sculpt Mode"); } static void rna_def_userdef_addon_collection(BlenderRNA *brna, PropertyRNA *cprop) -- cgit v1.2.3