Commit: 71f0e59b2e348c7376b5ec9e92c783c7def3b0ec Author: Antonio Vazquez Date: Fri Feb 23 23:55:27 2018 +0100 Branches: greasepencil-object https://developer.blender.org/rB71f0e59b2e348c7376b5ec9e92c783c7def3b0ec
Apply Smooth and Random sculpt to UV rotation Now it's possible apply the sculpt to the rotation of the UV texture. =================================================================== M release/scripts/startup/bl_ui/properties_grease_pencil_common.py M source/blender/blenkernel/BKE_gpencil.h M source/blender/blenkernel/intern/gpencil.c M source/blender/editors/gpencil/gpencil_brush.c M source/blender/makesdna/DNA_scene_types.h M source/blender/makesrna/intern/rna_sculpt_paint.c =================================================================== diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py index 2d46f6f05e3..0149a1922fe 100644 --- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py +++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py @@ -280,6 +280,7 @@ class GreasePencilStrokeSculptPanel: row.prop(settings, "affect_position", text="Position", icon='MESH_DATA', toggle=True) row.prop(settings, "affect_strength", text="Strength", icon='COLOR', toggle=True) row.prop(settings, "affect_thickness", text="Thickness", icon='LINE_DATA', toggle=True) + row.prop(settings, "affect_uv", text="UV", icon='MOD_UVPROJECT', toggle=True) layout.separator() diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h index 7458ce502f2..8c9f9f9c338 100644 --- a/source/blender/blenkernel/BKE_gpencil.h +++ b/source/blender/blenkernel/BKE_gpencil.h @@ -223,6 +223,7 @@ void BKE_gpencil_transform(struct bGPdata *gpd, float mat[4][4]); bool BKE_gp_smooth_stroke(struct bGPDstroke *gps, int i, float inf, bool affect_pressure); bool BKE_gp_smooth_stroke_strength(struct bGPDstroke *gps, int i, float inf); bool BKE_gp_smooth_stroke_thickness(struct bGPDstroke *gps, int i, float inf); +bool BKE_gp_smooth_stroke_uv(struct bGPDstroke *gps, int i, float inf); void BKE_gp_get_range_selected(struct bGPDlayer *gpl, int *r_initframe, int *r_endframe); float BKE_gpencil_multiframe_falloff_calc(struct bGPDframe *gpf, int actnum, int f_init, int f_end, struct CurveMapping *cur_falloff); diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 05f3560a779..7b45190e78f 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -2633,6 +2633,45 @@ bool BKE_gp_smooth_stroke_thickness(bGPDstroke *gps, int i, float inf) return true; } +/** +* Apply smooth for UV rotation to stroke point (use pressure) +* \param gps Stroke to smooth +* \param i Point index +* \param inf Amount of smoothing to apply +*/ +bool BKE_gp_smooth_stroke_uv(bGPDstroke *gps, int i, float inf) +{ + bGPDspoint *ptb = &gps->points[i]; + + /* Do nothing if not enough points */ + if (gps->totpoints <= 2) { + return false; + } + + /* Compute theoretical optimal value */ + bGPDspoint *pta, *ptc; + int before = i - 1; + int after = i + 1; + + CLAMP_MIN(before, 0); + CLAMP_MAX(after, gps->totpoints - 1); + + pta = &gps->points[before]; + ptc = &gps->points[after]; + + /* the optimal value is the corresponding to the interpolation of the pressure + * at the distance of point b + */ + float fac = line_point_factor_v3(&ptb->x, &pta->x, &ptc->x); + float optimal = interpf(ptc->uv_rot, pta->uv_rot, fac); + + /* Based on influence factor, blend between original and optimal */ + ptb->uv_rot = interpf(optimal, ptb->uv_rot, inf); + CLAMP(ptb->uv_rot, -M_PI_2, M_PI_2); + + return true; +} + /** * Get range of selected frames in layer. * Always the active frame is considered as selected, so if no more selected the range diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c index 401e2566a78..3713d748646 100644 --- a/source/blender/editors/gpencil/gpencil_brush.c +++ b/source/blender/editors/gpencil/gpencil_brush.c @@ -283,7 +283,8 @@ static bool gp_brush_smooth_apply( /* need one flag enabled by default */ if ((gso->settings->flag & (GP_BRUSHEDIT_FLAG_APPLY_POSITION | GP_BRUSHEDIT_FLAG_APPLY_STRENGTH | - GP_BRUSHEDIT_FLAG_APPLY_THICKNESS)) == 0) + GP_BRUSHEDIT_FLAG_APPLY_THICKNESS | + GP_BRUSHEDIT_FLAG_APPLY_UV)) == 0) { gso->settings->flag |= GP_BRUSHEDIT_FLAG_APPLY_POSITION; } @@ -298,7 +299,10 @@ static bool gp_brush_smooth_apply( if (gso->settings->flag & GP_BRUSHEDIT_FLAG_APPLY_THICKNESS) { BKE_gp_smooth_stroke_thickness(gps, pt_index, inf); } - + if (gso->settings->flag & GP_BRUSHEDIT_FLAG_APPLY_UV) { + BKE_gp_smooth_stroke_uv(gps, pt_index, inf); + } + return true; } @@ -741,7 +745,8 @@ static bool gp_brush_randomize_apply( /* need one flag enabled by default */ if ((gso->settings->flag & (GP_BRUSHEDIT_FLAG_APPLY_POSITION | GP_BRUSHEDIT_FLAG_APPLY_STRENGTH | - GP_BRUSHEDIT_FLAG_APPLY_THICKNESS)) == 0) + GP_BRUSHEDIT_FLAG_APPLY_THICKNESS | + GP_BRUSHEDIT_FLAG_APPLY_UV)) == 0) { gso->settings->flag |= GP_BRUSHEDIT_FLAG_APPLY_POSITION; } @@ -825,6 +830,16 @@ static bool gp_brush_randomize_apply( /* only limit lower value */ CLAMP_MIN(pt->pressure, 0.0f); } + /* apply random to UV (use pressure) */ + if (gso->settings->flag & GP_BRUSHEDIT_FLAG_APPLY_UV) { + if (BLI_frand() > 0.5f) { + pt->uv_rot += fac; + } + else { + pt->uv_rot -= fac; + } + CLAMP(pt->uv_rot, -M_PI_2, M_PI_2); + } /* done */ return true; diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 188a6cc9186..7266653e5b5 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -1236,6 +1236,8 @@ typedef enum eGP_BrushEdit_SettingsFlag { GP_BRUSHEDIT_FLAG_WEIGHT_MODE = (1 << 4), /* enable falloff for multiframe editing */ GP_BRUSHEDIT_FLAG_FRAME_FALLOFF = (1 << 5), + /* apply brush to uv data */ + GP_BRUSHEDIT_FLAG_APPLY_UV = (1 << 6), } eGP_BrushEdit_SettingsFlag; diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c index 32b9ba1a218..a76f66dcac5 100644 --- a/source/blender/makesrna/intern/rna_sculpt_paint.c +++ b/source/blender/makesrna/intern/rna_sculpt_paint.c @@ -1119,6 +1119,11 @@ static void rna_def_gpencil_sculpt(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Affect Thickness", "The brush affects the thickness of the point"); RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); + prop = RNA_def_property(srna, "affect_uv", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSHEDIT_FLAG_APPLY_UV); + RNA_def_property_ui_text(prop, "Affect UV", "The brush affects the UV rotation of the point"); + RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); + prop = RNA_def_property(srna, "selection_alpha", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "alpha"); RNA_def_property_range(prop, 0.0f, 1.0f); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs