Woot! Thank you, sah!
On Fri, Apr 5, 2013 at 3:00 PM, Antony Riakiotakis <[email protected]> wrote: > Revision: 55810 > > http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55810 > Author: psy-fi > Date: 2013-04-05 13:00:16 +0000 (Fri, 05 Apr 2013) > Log Message: > ----------- > Stencil dimension control: > > * Shift-Rclick and holding right click, x or y will trigger constrained > scaling of overlay. Pressing again will revert to uniform scaling. > * Added operator, visible under the mapping drop menu, to fit stencil > aspect ratio to brush image aspect ratio. > * Made it possible to access stencil attributes from python as vec.x, > vec.y. Thanks to kgeogeo for pointing out! > > Modified Paths: > -------------- > trunk/blender/release/scripts/startup/bl_ui/properties_paint_common.py > trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c > trunk/blender/source/blender/makesrna/intern/rna_brush.c > > Modified: > trunk/blender/release/scripts/startup/bl_ui/properties_paint_common.py > =================================================================== > --- trunk/blender/release/scripts/startup/bl_ui/properties_paint_common.py > 2013-04-05 12:37:48 UTC (rev 55809) > +++ trunk/blender/release/scripts/startup/bl_ui/properties_paint_common.py > 2013-04-05 13:00:16 UTC (rev 55810) > @@ -82,6 +82,9 @@ > else: > layout.row().prop(tex_slot, "tex_paint_map_mode", text="") > layout.separator() > + > + if tex_slot.map_mode == 'STENCIL': > + layout.operator("brush.stencil_fit_image_aspect") > > # angle and texture_angle_source > col = layout.column() > > Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c > =================================================================== > --- trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c > 2013-04-05 12:37:48 UTC (rev 55809) > +++ trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c > 2013-04-05 13:00:16 UTC (rev 55810) > @@ -38,9 +38,11 @@ > #include "BKE_context.h" > #include "BKE_paint.h" > #include "BKE_main.h" > +#include "BKE_image.h" > > #include "ED_sculpt.h" > #include "ED_screen.h" > +#include "ED_image.h" > #include "UI_resources.h" > > #include "WM_api.h" > @@ -447,12 +449,17 @@ > > /***** Stencil Control *****/ > > -enum { > +typedef enum { > STENCIL_TRANSLATE, > STENCIL_SCALE, > STENCIL_ROTATE > } StencilControlMode; > > +typedef enum { > +STENCIL_CONSTRAINT_X = 1, > +STENCIL_CONSTRAINT_Y = 2 > +} StencilConstraint; > + > typedef struct { > float init_mouse[2]; > float init_spos[2]; > @@ -460,7 +467,8 @@ > float init_rot; > float init_angle; > float lenorig; > - int mode; > + StencilControlMode mode; > + StencilConstraint constrain_mode; > Brush *br; > } StencilControlData; > > @@ -523,8 +531,11 @@ > sub_v2_v2v2(mdiff, mvalf, > scd->br->stencil_pos); > len = len_v2(mdiff); > factor = len / > scd->lenorig; > - mdiff[0] = factor * > scd->init_sdim[0]; > - mdiff[1] = factor * > scd->init_sdim[1]; > + copy_v2_v2(mdiff, > scd->init_sdim); > + if (scd->constrain_mode != > STENCIL_CONSTRAINT_Y) > + mdiff[0] = factor > * scd->init_sdim[0]; > + if (scd->constrain_mode != > STENCIL_CONSTRAINT_X) > + mdiff[1] = factor > * scd->init_sdim[1]; > > copy_v2_v2(scd->br->stencil_dimension, mdiff); > break; > } > @@ -557,6 +568,23 @@ > WM_event_add_notifier(C, NC_WINDOW, NULL); > return OPERATOR_CANCELLED; > } > + case XKEY: > + if (event->val == KM_PRESS) { > + > + if (scd->constrain_mode == > STENCIL_CONSTRAINT_X) > + scd->constrain_mode = 0; > + else > + scd->constrain_mode = > STENCIL_CONSTRAINT_X; > + } > + break; > + case YKEY: > + if (event->val == KM_PRESS) { > + if (scd->constrain_mode == > STENCIL_CONSTRAINT_Y) > + scd->constrain_mode = 0; > + else > + scd->constrain_mode = > STENCIL_CONSTRAINT_Y; > + } > + break; > default: > break; > } > @@ -599,6 +627,48 @@ > RNA_def_enum(ot->srna, "mode", stencil_control_items, 0, "Tool", > ""); > } > > + > +static int stencil_fit_image_aspect_exec(bContext *C, wmOperator > *UNUSED(op)) > +{ > + Paint *paint = paint_get_active_from_context(C); > + Brush *br = paint_brush(paint); > + Tex *tex = (br)? br->mtex.tex : NULL; > + > + if (tex && tex->type == TEX_IMAGE && tex->ima) { > + float aspx, aspy; > + Image *ima = tex->ima; > + float orig_area, stencil_area, factor; > + ED_image_get_uv_aspect(ima, NULL, &aspx, &aspy); > + > + orig_area = aspx*aspy; > + stencil_area = > br->stencil_dimension[0]*br->stencil_dimension[1]; > + > + factor = sqrt(stencil_area/orig_area); > + > + br->stencil_dimension[0] = factor*aspx; > + br->stencil_dimension[1] = factor*aspy; > + } > + > + return OPERATOR_FINISHED; > +} > + > + > +static void BRUSH_OT_stencil_fit_image_aspect(wmOperatorType *ot) > +{ > + /* identifiers */ > + ot->name = "Image Aspect"; > + ot->description = "Adjust the stencil size to fit image aspect > ratio"; > + ot->idname = "BRUSH_OT_stencil_fit_image_aspect"; > + > + /* api callbacks */ > + ot->exec = stencil_fit_image_aspect_exec; > + ot->poll = stencil_control_poll; > + > + /* flags */ > + ot->flag = 0; > +} > + > + > static void ed_keymap_stencil(wmKeyMap *keymap) > { > wmKeyMapItem *kmi; > @@ -622,6 +692,7 @@ > WM_operatortype_append(BRUSH_OT_curve_preset); > WM_operatortype_append(BRUSH_OT_reset); > WM_operatortype_append(BRUSH_OT_stencil_control); > + WM_operatortype_append(BRUSH_OT_stencil_fit_image_aspect); > > /* note, particle uses a different system, can be added with > existing operators in wm.py */ > WM_operatortype_append(PAINT_OT_brush_select); > > Modified: trunk/blender/source/blender/makesrna/intern/rna_brush.c > =================================================================== > --- trunk/blender/source/blender/makesrna/intern/rna_brush.c 2013-04-05 > 12:37:48 UTC (rev 55809) > +++ trunk/blender/source/blender/makesrna/intern/rna_brush.c 2013-04-05 > 13:00:16 UTC (rev 55810) > @@ -793,13 +793,13 @@ > RNA_def_property_ui_text(prop, "Autosmooth", "Amount of smoothing > to automatically apply to each stroke"); > RNA_def_property_update(prop, 0, "rna_Brush_update"); > > - prop = RNA_def_property(srna, "stencil_pos", PROP_FLOAT, > PROP_DISTANCE); > + prop = RNA_def_property(srna, "stencil_pos", PROP_FLOAT, PROP_XYZ); > RNA_def_property_float_sdna(prop, NULL, "stencil_pos"); > RNA_def_property_array(prop, 2); > RNA_def_property_ui_text(prop, "Stencil Position", "Position of > stencil in viewport"); > RNA_def_property_update(prop, 0, "rna_Brush_update"); > > - prop = RNA_def_property(srna, "stencil_dimension", PROP_FLOAT, > PROP_DISTANCE); > + prop = RNA_def_property(srna, "stencil_dimension", PROP_FLOAT, > PROP_XYZ); > RNA_def_property_float_sdna(prop, NULL, "stencil_dimension"); > RNA_def_property_array(prop, 2); > RNA_def_property_ui_text(prop, "Stencil Dimensions", "Dimensions > of stencil in viewport"); > > _______________________________________________ > Bf-blender-cvs mailing list > [email protected] > http://lists.blender.org/mailman/listinfo/bf-blender-cvs > _______________________________________________ Bf-committers mailing list [email protected] http://lists.blender.org/mailman/listinfo/bf-committers
