[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56222] trunk/blender: Overlay refactor:

Antony Riakiotakis kalast at gmail.com
Mon Apr 22 22:46:22 CEST 2013


Revision: 56222
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56222
Author:   psy-fi
Date:     2013-04-22 20:46:18 +0000 (Mon, 22 Apr 2013)
Log Message:
-----------
Overlay refactor:

Allow separate control for tex/mask/cursor overlay. This commit implements
separate overlays for mask textures and cursor curves. The user can turn on
and off separate parts of the overlay by using the appropriate widgets.
The cursor overlay widgets are located at the tool selection panel

Also fixed alpha masks not getting correctly masked and mask texture mapping
not having the correct update callback

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    trunk/blender/source/blender/blenkernel/BKE_paint.h
    trunk/blender/source/blender/blenkernel/intern/paint.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image_proj.c
    trunk/blender/source/blender/makesrna/intern/rna_brush.c

Modified: trunk/blender/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-04-22 20:15:42 UTC (rev 56221)
+++ trunk/blender/release/scripts/startup/bl_ui/space_view3d_toolbar.py	2013-04-22 20:46:18 UTC (rev 56222)
@@ -670,6 +670,19 @@
                     col.prop(brush, "use_persistent")
                     col.operator("sculpt.set_persistent_base")
 
+            col = layout.column(align=True)
+            col.label(text="Overlay:")
+
+            row = col.row()
+            if brush.use_cursor_overlay:
+                row.prop(brush, "use_cursor_overlay", toggle=True, text="", icon='RESTRICT_VIEW_OFF')
+            else:
+                row.prop(brush, "use_cursor_overlay", toggle=True, text="", icon='RESTRICT_VIEW_ON')
+        
+            sub = row.row()
+            sub.prop(brush, "cursor_overlay_alpha", text="Alpha")
+            sub.prop(brush, "cursor_overlay_override", toggle=True, text="", icon='BRUSH_DATA')
+
         # Texture Paint Mode #
 
         elif context.image_paint_object and brush:
@@ -693,6 +706,20 @@
             col.active = (brush.blend not in {'ERASE_ALPHA', 'ADD_ALPHA'})
             col.prop(brush, "use_alpha")
 
+            col = layout.column(align=True)
+            col.label(text="Overlay:")
+
+            row = col.row()            
+            if brush.use_cursor_overlay:
+                row.prop(brush, "use_cursor_overlay", toggle=True, text="", icon='RESTRICT_VIEW_OFF')
+            else:
+                row.prop(brush, "use_cursor_overlay", toggle=True, text="", icon='RESTRICT_VIEW_ON')
+        
+            sub = row.row()
+            sub.prop(brush, "cursor_overlay_alpha", text="Alpha")
+            sub.prop(brush, "cursor_overlay_override", toggle=True, text="", icon='BRUSH_DATA')
+
+
         # Weight Paint Mode #
         elif context.weight_paint_object and brush:
             layout.prop(toolsettings, "use_auto_normalize", text="Auto Normalize")
@@ -736,7 +763,20 @@
 
             col.prop(brush, "vertex_tool", text="Blend")
 
+            col = layout.column(align=True)
+            col.label(text="Overlay:")
 
+            row = col.row()
+            if brush.use_cursor_overlay:
+                row.prop(brush, "use_cursor_overlay", toggle=True, text="", icon='RESTRICT_VIEW_OFF')
+            else:
+                row.prop(brush, "use_cursor_overlay", toggle=True, text="", icon='RESTRICT_VIEW_ON')
+        
+            sub = row.row()
+            sub.prop(brush, "cursor_overlay_alpha", text="Alpha")
+            sub.prop(brush, "cursor_overlay_override", toggle=True, text="", icon='BRUSH_DATA')
+
+
 class VIEW3D_PT_tools_brush_texture(Panel, View3DPaintPanel):
     bl_label = "Texture"
     bl_options = {'DEFAULT_CLOSED'}
@@ -811,7 +851,7 @@
                 row.prop(brush, "use_secondary_overlay", toggle=True, text="", icon='RESTRICT_VIEW_ON')
         
         sub = row.row()
-        sub.prop(brush, "texture_overlay_alpha", text="Alpha")
+        sub.prop(brush, "mask_overlay_alpha", text="Alpha")
         sub.prop(brush, "cursor_overlay_override", toggle=True, text="", icon='BRUSH_DATA')
 
 

Modified: trunk/blender/source/blender/blenkernel/BKE_paint.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_paint.h	2013-04-22 20:15:42 UTC (rev 56221)
+++ trunk/blender/source/blender/blenkernel/BKE_paint.h	2013-04-22 20:46:18 UTC (rev 56222)
@@ -79,7 +79,7 @@
 void BKE_paint_invalidate_cursor_overlay(struct Scene *scene, struct CurveMapping *curve);
 void BKE_paint_invalidate_overlay_all(void);
 OverlayControlFlags BKE_paint_get_overlay_flags(void);
-void BKE_paint_reset_overlay_invalid(void);
+void BKE_paint_reset_overlay_invalid(OverlayControlFlags flag);
 void BKE_paint_set_overlay_override(bool flag);
 bool BKE_paint_get_overlay_override(void);
 

Modified: trunk/blender/source/blender/blenkernel/intern/paint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/paint.c	2013-04-22 20:15:42 UTC (rev 56221)
+++ trunk/blender/source/blender/blenkernel/intern/paint.c	2013-04-22 20:46:18 UTC (rev 56222)
@@ -108,11 +108,9 @@
 }
 
 
-void BKE_paint_reset_overlay_invalid(void)
+void BKE_paint_reset_overlay_invalid(OverlayControlFlags flag)
 {
-	overlay_flags &= ~(PAINT_INVALID_OVERLAY_TEXTURE_PRIMARY |
-	                   PAINT_INVALID_OVERLAY_TEXTURE_SECONDARY |
-	                   PAINT_INVALID_OVERLAY_CURVE);
+	overlay_flags &= ~(flag);
 }
 
 

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c	2013-04-22 20:15:42 UTC (rev 56221)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c	2013-04-22 20:46:18 UTC (rev 56222)
@@ -69,9 +69,13 @@
  */
 
 typedef struct TexSnapshot {
+	GLuint overlay_texture;
 	int winx;
 	int winy;
 	bool init;
+	int old_size;
+	int old_zoom;
+	bool old_col;
 } TexSnapshot;
 
 typedef struct CurveSnapshot {
@@ -80,35 +84,35 @@
 	bool init;
 } CurveSnapshot;
 
-static int same_tex_snap(TexSnapshot *snap, Brush *brush, ViewContext *vc)
+static int same_tex_snap(TexSnapshot *snap, MTex *mtex, ViewContext *vc, bool col, float zoom)
 {
-	MTex *mtex = &brush->mtex;
-
 	return (/* make brush smaller shouldn't cause a resample */
 	        //(mtex->brush_map_mode != MTEX_MAP_MODE_VIEW ||
 	        //(BKE_brush_size_get(vc->scene, brush) <= snap->BKE_brush_size_get)) &&
 
 	        (mtex->brush_map_mode != MTEX_MAP_MODE_TILED ||
 	        (vc->ar->winx == snap->winx &&
-	        vc->ar->winy == snap->winy))
+	        vc->ar->winy == snap->winy)) &&
+	        snap->old_zoom == zoom &&
+			snap->old_col == col
 	        );
 }
 
-static void make_tex_snap(TexSnapshot *snap, ViewContext *vc)
+static void make_tex_snap(TexSnapshot *snap, ViewContext *vc, float zoom)
 {
+	snap->old_zoom = zoom;
 	snap->winx = vc->ar->winx;
 	snap->winy = vc->ar->winy;
 }
 
-static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col)
+static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool primary)
 {
-	static GLuint overlay_texture = 0;
 	static int init = 0;
-	static TexSnapshot snap;
-	static int old_size = -1;
-	static int old_zoom = -1;
-	static bool old_col = -1;
+	static TexSnapshot primary_snap = {0};
+	static TexSnapshot secondary_snap  = {0};
+	TexSnapshot *target;
 
+	MTex *mtex = (primary) ? &br->mtex : &br->mask_mtex;
 	OverlayControlFlags overlay_flags = BKE_paint_get_overlay_flags();
 	GLubyte *buffer = NULL;
 
@@ -116,29 +120,29 @@
 	int j;
 	int refresh;
 	GLenum format = col ? GL_RGBA : GL_ALPHA;
+	OverlayControlFlags invalid = (primary) ? (overlay_flags & PAINT_INVALID_OVERLAY_TEXTURE_PRIMARY) :
+	                           (overlay_flags & PAINT_INVALID_OVERLAY_TEXTURE_SECONDARY);
+
+	target = (primary) ? &primary_snap : &secondary_snap;
 	
-	if (br->mtex.brush_map_mode != MTEX_MAP_MODE_VIEW && !br->mtex.tex) return 0;
+	if (mtex->brush_map_mode != MTEX_MAP_MODE_VIEW && !mtex->tex) return 0;
 	
 	refresh = 
-	    !overlay_texture ||
-	    (overlay_flags & PAINT_INVALID_OVERLAY_TEXTURE_PRIMARY) ||
-	    (overlay_flags & PAINT_INVALID_OVERLAY_CURVE) ||
-	    old_zoom != zoom ||
-	    old_col != col ||
-	    !same_tex_snap(&snap, br, vc);
+	    !target->overlay_texture ||
+	    (invalid != 0) ||
+	    !same_tex_snap(target, mtex, vc, col, zoom);
 
 	if (refresh) {
 		struct ImagePool *pool = NULL;
 		/* stencil is rotated later */
-		const float rotation = (br->mtex.brush_map_mode != MTEX_MAP_MODE_STENCIL) ?
-		                       -br->mtex.rot : 0;
+		const float rotation = (mtex->brush_map_mode != MTEX_MAP_MODE_STENCIL) ?
+		                       -mtex->rot : 0;
 
 		float radius = BKE_brush_size_get(vc->scene, br) * zoom;
 
-		old_zoom = zoom;
-		make_tex_snap(&snap, vc);
+		make_tex_snap(target, vc, zoom);
 
-		if (br->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW) {
+		if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) {
 			int s = BKE_brush_size_get(vc->scene, br);
 			int r = 1;
 
@@ -150,32 +154,30 @@
 			if (size < 256)
 				size = 256;
 
-			if (size < old_size)
-				size = old_size;
+			if (size < target->old_size)
+				size = target->old_size;
 		}
 		else
 			size = 512;
 
-		if (old_size != size) {
-			if (overlay_texture) {
-				glDeleteTextures(1, &overlay_texture);
-				overlay_texture = 0;
+		if (target->old_size != size) {
+			if (target->overlay_texture) {
+				glDeleteTextures(1, &target->overlay_texture);
+				target->overlay_texture = 0;
 			}
 
 			init = 0;
 
-			old_size = size;
+			target->old_size = size;
 		}
 		if (col)
 			buffer = MEM_mallocN(sizeof(GLubyte) * size * size * 4, "load_tex");
 		else
 			buffer = MEM_mallocN(sizeof(GLubyte) * size * size, "load_tex");
 
-		if (br->mtex.tex)
+		if (mtex->tex)
 			pool = BKE_image_pool_new();
 
-		curvemapping_initialize(br->curve);
-
 		#pragma omp parallel for schedule(static)
 		for (j = 0; j < size; j++) {
 			int i;
@@ -192,7 +194,7 @@
 				x = (float)i / size;
 				y = (float)j / size;
 
-				if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED) {
+				if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) {
 					x *= vc->ar->winx / radius;
 					y *= vc->ar->winy / radius;
 				}
@@ -206,47 +208,39 @@
 
 				len = sqrtf(x * x + y * y);
 
-				if (ELEM(br->mtex.brush_map_mode, MTEX_MAP_MODE_TILED, MTEX_MAP_MODE_STENCIL) || len <= 1) {
+				if (ELEM(mtex->brush_map_mode, MTEX_MAP_MODE_TILED, MTEX_MAP_MODE_STENCIL) || len <= 1) {
 					/* it is probably worth optimizing for those cases where 
 					 * the texture is not rotated by skipping the calls to
 					 * atan2, sqrtf, sin, and cos. */
-					if (br->mtex.tex && (rotation > 0.001f || rotation < -0.001f)) {
-						const float angle    = atan2f(y, x) + rotation;
+					if (mtex->tex && (rotation > 0.001f || rotation < -0.001f)) {
+						const float angle = atan2f(y, x) + rotation;
 
 						x = len * cosf(angle);
 						y = len * sinf(angle);
 					}
 
-					x *= br->mtex.size[0];
-					y *= br->mtex.size[1];
+					x *= mtex->size[0];
+					y *= mtex->size[1];
 
-					x += br->mtex.ofs[0];
-					y += br->mtex.ofs[1];
+					x += mtex->ofs[0];
+					y += mtex->ofs[1];
 
 					if (col) {
 						float rgba[4];
 
-						if (br->mtex.tex)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list