[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56042] trunk/blender/source/blender/ editors/sculpt_paint/paint_ops.c: Texture stencil:

Antony Riakiotakis kalast at gmail.com
Sun Apr 14 11:43:13 CEST 2013


Revision: 56042
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56042
Author:   psy-fi
Date:     2013-04-14 09:43:12 +0000 (Sun, 14 Apr 2013)
Log Message:
-----------
Texture stencil:

Robustness: Avoid translating the stencil outside the active area. Helps
to avoid losing the stencil somewhere in bitspace.

Usability: Take image repeat mapping and scaling into account when
fitting stencil aspect. Togglable by operator properties.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c	2013-04-14 09:34:59 UTC (rev 56041)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c	2013-04-14 09:43:12 UTC (rev 56042)
@@ -468,6 +468,7 @@
 	float init_rot;
 	float init_angle;
 	float lenorig;
+	float area_size[2];
 	StencilControlMode mode;
 	StencilConstraint constrain_mode;
 	Brush *br;
@@ -480,6 +481,7 @@
 	Brush *br = BKE_paint_brush(paint);
 	float mdiff[2];
 	float mvalf[2] = {event->mval[0], event->mval[1]};
+	ARegion *ar = CTX_wm_region(C);
 
 	StencilControlData *scd = MEM_mallocN(sizeof(StencilControlData), "stencil_control");
 
@@ -493,6 +495,8 @@
 	scd->init_angle = atan2(mdiff[1], mdiff[0]);
 	scd->mode = RNA_enum_get(op->ptr, "mode");
 	scd->event_type = event->type;
+	scd->area_size[0] = ar->winx;
+	scd->area_size[1] = ar->winy;
 
 	op->customdata = scd;
 	WM_event_add_modal_handler(C, op);
@@ -515,6 +519,8 @@
 
 static void stencil_control_calculate(StencilControlData *scd, const int *mval)
 {
+	#define PIXEL_MARGIN 5
+
 	float mdiff[2];
 	float mvalf[2] = {mval[0], mval[1]};
 	switch (scd->mode) {
@@ -522,6 +528,14 @@
 			sub_v2_v2v2(mdiff, mvalf, scd->init_mouse);
 			add_v2_v2v2(scd->br->stencil_pos, scd->init_spos,
 			            mdiff);
+			CLAMP(scd->br->stencil_pos[0],
+			      -scd->br->stencil_dimension[0] + PIXEL_MARGIN,
+			      scd->area_size[0] + scd->br->stencil_dimension[0] - PIXEL_MARGIN);
+
+			CLAMP(scd->br->stencil_pos[1],
+			      -scd->br->stencil_dimension[1] + PIXEL_MARGIN,
+			      scd->area_size[1] + scd->br->stencil_dimension[1] - PIXEL_MARGIN);
+
 			break;
 		case STENCIL_SCALE:
 		{
@@ -637,11 +651,13 @@
 }
 
 
-static int stencil_fit_image_aspect_exec(bContext *C, wmOperator *UNUSED(op))
+static int stencil_fit_image_aspect_exec(bContext *C, wmOperator *op)
 {
 	Paint *paint = BKE_paint_get_active_from_context(C);
 	Brush *br = BKE_paint_brush(paint);
 	Tex *tex = (br)? br->mtex.tex : NULL;
+	bool use_scale = RNA_boolean_get(op->ptr, "use_scale");
+	bool use_repeat = RNA_boolean_get(op->ptr, "use_repeat");
 
 	if (tex && tex->type == TEX_IMAGE && tex->ima) {
 		float aspx, aspy;
@@ -649,6 +665,16 @@
 		float orig_area, stencil_area, factor;
 		ED_image_get_uv_aspect(ima, NULL, &aspx, &aspy);
 
+		if (use_scale) {
+			aspx *= br->mtex.size[0];
+			aspy *= br->mtex.size[1];
+		}
+
+		if (use_repeat && tex->extend == TEX_REPEAT) {
+			aspx *= tex->xrepeat;
+			aspy *= tex->yrepeat;
+		}
+
 		orig_area = aspx * aspy;
 		stencil_area = br->stencil_dimension[0] * br->stencil_dimension[1];
 
@@ -658,6 +684,8 @@
 		br->stencil_dimension[1] = factor * aspy;
 	}
 
+	WM_event_add_notifier(C, NC_WINDOW, NULL);
+
 	return OPERATOR_FINISHED;
 }
 
@@ -674,7 +702,10 @@
 	ot->poll = stencil_control_poll;
 
 	/* flags */
-	ot->flag = 0;
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+	RNA_def_boolean(ot->srna, "use_repeat", 1, "Use Repeat", "Use repeat mapping values");
+	RNA_def_boolean(ot->srna, "use_scale", 1, "Use Scale", "Use texture scale values");
 }
 
 




More information about the Bf-blender-cvs mailing list