[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55679] trunk/blender/source/blender: Woot woot commit.

Antony Riakiotakis kalast at gmail.com
Sun Mar 31 01:38:51 CET 2013


Revision: 55679
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55679
Author:   psy-fi
Date:     2013-03-31 00:38:50 +0000 (Sun, 31 Mar 2013)
Log Message:
-----------
Woot woot commit.

Stencil style texture mapping. Ready for field testing and user feedback.

This commit adds stencil like brushes, like those that existed on old ptex branch.
(with the exception of clip colour)
To control the position of the stencil, you use

Q: translation
Shift - Q: scaling
Ctrl - Q: rotation

There's extra work that has been done to make this work:

* Support for coloured overlay in vertex/texture painting
* Also made A button do stroke mode selection like in sculpt mode,
when mask painting is inactive.

There are some TODOs to work on during bcon3:

* Support tiled and stencil mode in 2D painting. Support alpha textures also.
* Tidy up overlay code. There's some confusion there due
to the way we use the primary brush texture sometimes for alpha, other times
for colour control.

WIP design docs will be in

http://wiki.blender.org/index.php/User:Psy-Fi/New_Brush_Tool_Design

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_blender.h
    trunk/blender/source/blender/blenkernel/intern/brush.c
    trunk/blender/source/blender/blenlib/BLI_math_vector.h
    trunk/blender/source/blender/blenlib/intern/math_vector_inline.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h
    trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_utils.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c
    trunk/blender/source/blender/editors/sculpt_paint/sculpt.c
    trunk/blender/source/blender/makesdna/DNA_brush_types.h
    trunk/blender/source/blender/makesdna/DNA_texture_types.h
    trunk/blender/source/blender/makesrna/intern/rna_brush.c

Modified: trunk/blender/source/blender/blenkernel/BKE_blender.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_blender.h	2013-03-30 20:50:28 UTC (rev 55678)
+++ trunk/blender/source/blender/blenkernel/BKE_blender.h	2013-03-31 00:38:50 UTC (rev 55679)
@@ -42,7 +42,7 @@
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         266
-#define BLENDER_SUBVERSION      4
+#define BLENDER_SUBVERSION      5
 
 /* 262 was the last editmesh release but it has compatibility code for bmesh data */
 #define BLENDER_MINVERSION      262

Modified: trunk/blender/source/blender/blenkernel/intern/brush.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/brush.c	2013-03-30 20:50:28 UTC (rev 55678)
+++ trunk/blender/source/blender/blenkernel/intern/brush.c	2013-03-31 00:38:50 UTC (rev 55679)
@@ -121,6 +121,12 @@
 	brush->sub_col[0] = 0.39; /* subtract mode color is light blue */
 	brush->sub_col[1] = 0.39;
 	brush->sub_col[2] = 1.00;
+
+	brush->stencil_pos[0] = 256;
+	brush->stencil_pos[1] = 256;
+
+	brush->stencil_dimension[0] = 256;
+	brush->stencil_dimension[1] = 256;
 }
 
 /* Datablock add/copy/free/make_local */
@@ -518,11 +524,45 @@
 		hasrgb = externtex(mtex, point, &intensity,
 		                   rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool);
 	}
+	else if (mtex->brush_map_mode == MTEX_MAP_MODE_STENCIL) {
+		float rotation = -mtex->rot;
+		float point_2d[2] = {point[0], point[1]};
+		float x = 0.0f, y = 0.0f; /* Quite warnings */
+		float co[3];
+
+		x = point_2d[0] - br->stencil_pos[0];
+		y = point_2d[1] - br->stencil_pos[1];
+
+		if (rotation > 0.001f || rotation < -0.001f) {
+			const float angle    = atan2f(y, x) + rotation;
+			const float flen     = sqrtf(x * x + y * y);
+
+			x = flen * cosf(angle);
+			y = flen * sinf(angle);
+		}
+
+		if (fabs(x) > br->stencil_dimension[0] || fabs(y) > br->stencil_dimension[1]) {
+			rgba[0] = rgba[1] = rgba[2] = rgba[3] = 0.0;
+			return 0.0;
+		}
+		x /= (br->stencil_dimension[0]);
+		y /= (br->stencil_dimension[1]);
+
+		x *= br->mtex.size[0];
+		y *= br->mtex.size[1];
+
+		co[0] = x + br->mtex.ofs[0];
+		co[1] = y + br->mtex.ofs[1];
+		co[2] = 0.0f;
+
+		hasrgb = externtex(mtex, co, &intensity,
+		                   rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool);
+	}
 	else {
 		float rotation = -mtex->rot;
 		float point_2d[2] = {point[0], point[1]};
 		float x = 0.0f, y = 0.0f; /* Quite warnings */
-		float radius = 1.0f; /* Quite warnings */
+		float invradius = 1.0f; /* Quite warnings */
 		float co[3];
 
 		if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) {
@@ -534,13 +574,13 @@
 			y = point_2d[1] - ups->tex_mouse[1];
 
 			/* use pressure adjusted size for fixed mode */
-			radius = ups->pixel_radius;
+			invradius = 1.0/ups->pixel_radius;
 		}
 		else if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) {
 			/* leave the coordinates relative to the screen */
 
 			/* use unadjusted size for tiled mode */
-			radius = BKE_brush_size_get(scene, br);
+			invradius = 1.0/BKE_brush_size_get(scene, br);
 
 			x = point_2d[0];
 			y = point_2d[1];
@@ -551,11 +591,11 @@
 			x = point_2d[0] - ups->tex_mouse[0];
 			y = point_2d[1] - ups->tex_mouse[1];
 
-			radius = ups->pixel_radius;
+			invradius = 1.0/ups->pixel_radius;
 		}
 
-		x /= radius;
-		y /= radius;
+		x *= invradius;
+		y *= invradius;
 
 		/* it is probably worth optimizing for those cases where
 		 * the texture is not rotated by skipping the calls to

Modified: trunk/blender/source/blender/blenlib/BLI_math_vector.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_vector.h	2013-03-30 20:50:28 UTC (rev 55678)
+++ trunk/blender/source/blender/blenlib/BLI_math_vector.h	2013-03-31 00:38:50 UTC (rev 55679)
@@ -92,6 +92,7 @@
 MINLINE void add_v4_fl(float r[4], float f);
 MINLINE void add_v2_v2(float r[2], const float a[2]);
 MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2]);
+MINLINE void add_v2_v2v2_int(int r[2], const int a[2], const int b[2]);
 MINLINE void add_v3_v3(float r[3], const float a[3]);
 MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3]);
 MINLINE void add_v4_v4(float r[4], const float a[4]);
@@ -99,6 +100,7 @@
 
 MINLINE void sub_v2_v2(float r[2], const float a[2]);
 MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2]);
+MINLINE void sub_v2_v2v2_int(int r[2], const int a[2], const int b[2]);
 MINLINE void sub_v3_v3(float r[3], const float a[3]);
 MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3]);
 MINLINE void sub_v4_v4(float r[4], const float a[4]);

Modified: trunk/blender/source/blender/blenlib/intern/math_vector_inline.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_vector_inline.c	2013-03-30 20:50:28 UTC (rev 55678)
+++ trunk/blender/source/blender/blenlib/intern/math_vector_inline.c	2013-03-31 00:38:50 UTC (rev 55679)
@@ -271,6 +271,12 @@
 	r[1] = a[1] + b[1];
 }
 
+MINLINE void add_v2_v2v2_int(int r[2], const int a[2], const int b[2])
+{
+	r[0] = a[0] + b[0];
+	r[1] = a[1] + b[1];
+}
+
 MINLINE void add_v3_v3(float r[3], const float a[3])
 {
 	r[0] += a[0];
@@ -313,6 +319,12 @@
 	r[1] = a[1] - b[1];
 }
 
+MINLINE void sub_v2_v2v2_int(int r[2], const int a[2], const int b[2])
+{
+	r[0] = a[0] - b[0];
+	r[1] = a[1] - b[1];
+}
+
 MINLINE void sub_v3_v3(float r[3], const float a[3])
 {
 	r[0] -= a[0];

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2013-03-30 20:50:28 UTC (rev 55678)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2013-03-31 00:38:50 UTC (rev 55679)
@@ -9077,7 +9077,18 @@
 	}
 
 	if (main->versionfile < 267) {
-		
+		//if(!DNA_struct_elem_find(fd->filesdna, "Brush", "int", "stencil_pos")) {
+		Brush *brush;
+
+		for (brush = main->brush.first; brush; brush = brush->id.next) {
+			if (brush->stencil_dimension[0] == 0) {
+				brush->stencil_dimension[0] = 256;
+				brush->stencil_dimension[1] = 256;
+				brush->stencil_pos[0] = 256;
+				brush->stencil_pos[1] = 256;
+			}
+		}
+
 		/* TIP: to initialize new variables added, use the new function
 		   DNA_struct_elem_find(fd->filesdna, "structname", "typename", "varname")
 		   example: 

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c	2013-03-30 20:50:28 UTC (rev 55678)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c	2013-03-31 00:38:50 UTC (rev 55679)
@@ -117,7 +117,7 @@
 	snap->winy = vc->ar->winy;
 }
 
-static int load_tex(Brush *br, ViewContext *vc, float zoom)
+static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col)
 {
 	static GLuint overlay_texture = 0;
 	static int init = 0;
@@ -126,12 +126,14 @@
 	static Snapshot snap;
 	static int old_size = -1;
 	static int old_zoom = -1;
+	static bool old_col = -1;
 
 	GLubyte *buffer = NULL;
 
 	int size;
 	int j;
 	int refresh;
+	int format = col? GL_RGBA : GL_ALPHA;
 	
 	if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED && !br->mtex.tex) return 0;
 	
@@ -143,11 +145,15 @@
 	    !br->curve ||
 	    br->curve->changed_timestamp != curve_changed_timestamp ||
 	    old_zoom != zoom ||
+	    old_col != col ||
 	    !same_snap(&snap, br, vc);
 
 	if (refresh) {
 		struct ImagePool *pool = NULL;
-		const float rotation = -br->mtex.rot;
+		/* stencil is rotated later */
+		const float rotation = (br->mtex.brush_map_mode != MTEX_MAP_MODE_STENCIL)?
+		                       -br->mtex.rot : 0;
+
 		float radius = BKE_brush_size_get(vc->scene, br) * zoom;
 
 		if (br->mtex.tex && br->mtex.tex->preview)
@@ -187,9 +193,11 @@
 
 			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");
 
-		buffer = MEM_mallocN(sizeof(GLubyte) * size * size, "load_tex");
-
 		if (br->mtex.tex)
 			pool = BKE_image_pool_new();
 
@@ -205,7 +213,6 @@
 
 				int index = j * size + i;
 				float x;
-				float avg;
 
 				x = (float)i / size;
 				y = (float)j / size;
@@ -224,7 +231,7 @@
 
 				len = sqrtf(x * x + y * y);
 
-				if ((br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED) || len <= 1) {
+				if (ELEM(br->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. */
@@ -241,17 +248,40 @@
 					x += br->mtex.ofs[0];
 					y += br->mtex.ofs[1];
 
-					avg = br->mtex.tex ? paint_get_tex_pixel(br, x, y, pool) : 1;
+					if (col) {
+						float rgba[4];
 
-					avg += br->texture_sample_bias;
+						if (br->mtex.tex)
+							paint_get_tex_pixel_col(&br->mtex, x, y, rgba, pool);
 
-					if (br->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW)
-						avg *= BKE_brush_curve_strength(br, len, 1);  /* Falloff curve */
+						if (br->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW)
+							mul_v4_fl(rgba, BKE_brush_curve_strength(br, len, 1));  /* Falloff curve */
 
-					buffer[index] = 255 - (GLubyte)(255 * avg);
+						buffer[index*4] = rgba[0]*255;
+						buffer[index*4 + 1] = rgba[1]*255;
+						buffer[index*4 + 2] = rgba[2]*255;
+						buffer[index*4 + 3] = rgba[3]*255;
+					}
+					else {
+						float avg = br->mtex.tex ? paint_get_tex_pixel(&br->mtex, x, y, pool) : 1;
+
+						avg += br->texture_sample_bias;
+
+						if (br->mtex.brush_map_mode == MTEX_MAP_MODE_VIEW)
+							avg *= BKE_brush_curve_strength(br, len, 1);  /* Falloff curve */
+
+						buffer[index] = 255 - (GLubyte)(255 * avg);
+					}
 				}
 				else {
-					buffer[index] = 0;
+					if (col) {
+						buffer[index*4] = 0;
+						buffer[index*4 + 1] = 0;
+						buffer[index*4 + 2] = 0;
+						buffer[index*4 + 3] = 0;
+					}
+					else
+						buffer[index] = 0;
 				}
 			}
 		}
@@ -269,16 +299,18 @@
 	glBindTexture(GL_TEXTURE_2D, overlay_texture);
 
 	if (refresh) {
-		if (!init) {
-			glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, size, size, 0, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list