[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30192] branches/soc-2010-jwilkins/source/ blender: * fkey resize can now be done with on-surface brush

Jason Wilkins Jason.A.Wilkins at gmail.com
Sun Jul 11 00:17:56 CEST 2010


Revision: 30192
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30192
Author:   jwilkins
Date:     2010-07-11 00:17:56 +0200 (Sun, 11 Jul 2010)

Log Message:
-----------
* fkey resize can now be done with on-surface brush
* the old style fkey resize now uses the brush and overlay colors
* the opacity of the overlay during resize is based on strength, not on the overlay alpha setting

This raises the question, should opacity of normal overlay be based on strength for the regular brush?  I would have done this but the overlay is already very light and difficult to see under some circumstances.

Modified Paths:
--------------
    branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c
    branches/soc-2010-jwilkins/source/blender/windowmanager/intern/wm_operators.c

Modified: branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c	2010-07-10 21:47:40 UTC (rev 30191)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c	2010-07-10 22:17:56 UTC (rev 30192)
@@ -243,7 +243,7 @@
 	snap->brush_map_mode = brush->mtex.brush_map_mode;
 }
 
-static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
+int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
 {
 	static GLuint overlay_texture = 0;
 	static int init = 0;
@@ -461,7 +461,7 @@
 	return len_v2v2(p1, p2);
 }
 
-static int sculpt_get_brush_geometry(bContext* C, int x, int y, int* pixel_radius, float location[3], float modelview[16], float projection[16], int viewport[4])
+int sculpt_get_brush_geometry(bContext* C, int x, int y, int* pixel_radius, float location[3], float modelview[16], float projection[16], int viewport[4])
 {
 	struct PaintStroke *stroke;
 	float window[2];
@@ -500,7 +500,7 @@
 }
 
 // XXX duplicated from sculpt.c
-static float unproject_brush_radius(Object *ob, ViewContext *vc, float center[3], float offset)
+float unproject_brush_radius(Object *ob, ViewContext *vc, float center[3], float offset)
 {
 	float delta[3], scale, loc[3];
 

Modified: branches/soc-2010-jwilkins/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/windowmanager/intern/wm_operators.c	2010-07-10 21:47:40 UTC (rev 30191)
+++ branches/soc-2010-jwilkins/source/blender/windowmanager/intern/wm_operators.c	2010-07-10 22:17:56 UTC (rev 30192)
@@ -61,6 +61,7 @@
 #include "BKE_scene.h"
 #include "BKE_screen.h" /* BKE_ST_MAXNAME */
 #include "BKE_utildefines.h"
+#include "BKE_brush.h" // JW
 
 #include "BIF_gl.h"
 #include "BIF_glutil.h" /* for paint cursor */
@@ -69,6 +70,7 @@
 
 #include "ED_screen.h"
 #include "ED_util.h"
+#include "ED_view3d.h" // JW
 
 #include "RNA_access.h"
 #include "RNA_define.h"
@@ -2595,20 +2597,113 @@
 	GLuint tex;
 } wmRadialControl;
 
+extern Paint *paint_get_active(Scene *sce);
+extern struct Brush *paint_brush(struct Paint *paint);
+extern int sculpt_get_brush_geometry(bContext* C, int x, int y, int* pixel_radius, float location[3], float modelview[16], float projection[16], int viewport[4]);
+extern float unproject_brush_radius(Object *ob, ViewContext *vc, float center[3], float offset);
+
+
+static void draw_on_surface_cursor(float modelview[16], float projection[16], float col[3], float alpha, float size[3], int viewport[4], float location[3], float inner_radius, float outer_radius, int brush_size)
+{
+	GLUquadric* sphere;
+
+	glPushAttrib(
+		GL_COLOR_BUFFER_BIT|
+		GL_CURRENT_BIT|
+		GL_DEPTH_BUFFER_BIT|
+		GL_ENABLE_BIT|
+		GL_LINE_BIT|
+		GL_POLYGON_BIT|
+		GL_STENCIL_BUFFER_BIT|
+		GL_TRANSFORM_BIT|
+		GL_VIEWPORT_BIT|
+		GL_TEXTURE_BIT);
+
+	glColor4f(col[0], col[1], col[2], alpha);
+
+	glEnable(GL_BLEND);
+
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix();
+	glLoadMatrixf(modelview);
+
+	glTranslatef(location[0], location[1], location[2]);
+
+	glScalef(size[0], size[1], size[2]);
+
+	glMatrixMode(GL_PROJECTION);
+	glPushMatrix();
+	glLoadMatrixf(projection);
+
+	glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
+
+	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+	glDepthMask(GL_FALSE);
+
+	glDisable(GL_CULL_FACE);
+
+	glEnable(GL_DEPTH_TEST);
+
+	glClearStencil(0);
+	glClear(GL_STENCIL_BUFFER_BIT);
+	glEnable(GL_STENCIL_TEST);
+
+	glStencilFunc(GL_ALWAYS, 3, 0xFF);
+	glStencilOp(GL_KEEP, GL_REPLACE, GL_KEEP);
+
+	sphere = gluNewQuadric();
+
+	gluSphere(sphere, outer_radius, 40, 40);
+
+	glStencilFunc(GL_ALWAYS, 1, 0xFF);
+	glStencilOp(GL_KEEP, GL_DECR, GL_KEEP);
+
+	if (brush_size >= 8)
+		gluSphere(sphere, inner_radius, 40, 40);
+
+	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+
+	glStencilFunc(GL_EQUAL, 1, 0xFF);
+	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
+
+	gluSphere(sphere, outer_radius, 40, 40);
+
+	glStencilFunc(GL_EQUAL, 3, 0xFF);
+	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
+
+	gluSphere(sphere, outer_radius, 40, 40);
+
+	gluDeleteQuadric(sphere);
+
+	glPopMatrix();
+
+	glMatrixMode(GL_MODELVIEW);
+	glPopMatrix();
+
+	glPopAttrib();
+}
+
 static void wm_radial_control_paint(bContext *C, int x, int y, void *customdata)
 {
 	wmRadialControl *rc = (wmRadialControl*)customdata;
 	ARegion *ar = CTX_wm_region(C);
 	float r1=0.0f, r2=0.0f, r3=0.0f, angle=0.0f;
 
-	/* Keep cursor in the original place */
-	x = rc->initial_mouse[0] - ar->winrct.xmin;
-	y = rc->initial_mouse[1] - ar->winrct.ymin;
+	ViewContext vc;
 
-	glPushMatrix();
-	
-	glTranslatef((float)x, (float)y, 0.0f);
+	int hit = 0;
 
+	Paint *paint = paint_get_active(CTX_data_scene(C));
+	Brush *brush = paint_brush(paint);
+
+	int flip;
+	int sign;
+
+	float* col;
+	float  alpha;
+
+	const float str = rc->mode == WM_RADIALCONTROL_STRENGTH ? (rc->value + 0.5) : 1;
+
 	if(rc->mode == WM_RADIALCONTROL_SIZE) {
 		r1= rc->value;
 		r2= rc->initial_value;
@@ -2623,48 +2718,138 @@
 		angle = rc->value;
 	}
 
-	glColor4ub(255, 255, 255, 128);
-	glEnable( GL_LINE_SMOOTH );
-	glEnable(GL_BLEND);
+	/* Keep cursor in the original place */
+	x = rc->initial_mouse[0] - ar->winrct.xmin;
+	y = rc->initial_mouse[1] - ar->winrct.ymin;
 
-	if(rc->mode == WM_RADIALCONTROL_ANGLE)
-		fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
+	view3d_set_viewcontext(C, &vc);
 
-	if(rc->tex) {
-		const float str = rc->mode == WM_RADIALCONTROL_STRENGTH ? (rc->value + 0.5) : 1;
+	// XXX: no way currently to know state of pen flip or invert key modifier without starting a stroke
+	flip = 1;
 
-		if(rc->mode == WM_RADIALCONTROL_ANGLE) {
-			glRotatef(angle, 0, 0, 1);
-			fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
+	sign = flip * ((brush->flag & BRUSH_DIR_IN)? -1 : 1);
+
+	if (sign < 0 && ELEM4(brush->sculpt_tool, SCULPT_TOOL_DRAW, SCULPT_TOOL_INFLATE, SCULPT_TOOL_CLAY, SCULPT_TOOL_PINCH))
+		col = brush->sub_col;
+	else
+		col = brush->add_col;
+
+	if (rc->mode == WM_RADIALCONTROL_SIZE && (paint->flags & PAINT_SHOW_BRUSH_ON_SURFACE) && vc.obact->sculpt) {
+		Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
+
+		int pixel_radius, viewport[4];
+		float location[3], modelview[16], projection[16];
+
+		float visual_strength = sculpt_get_brush_alpha(brush)*sculpt_get_brush_alpha(brush);
+
+		const float min_alpha = 0.20f;
+		const float max_alpha = 0.80f;
+
+		hit = sculpt_get_brush_geometry(C, x, y, &pixel_radius, location, modelview, projection, viewport);
+
+
+		alpha = min_alpha + (visual_strength*(max_alpha-min_alpha));
+
+		if (hit) {
+			Object *ob= CTX_data_active_object(C);
+
+			glTranslatef((float)x, (float)y, 0.0f);
+
+			glEnable(GL_BLEND);
+
+			glBindTexture(GL_TEXTURE_2D, rc->tex);
+
+			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+			glEnable(GL_TEXTURE_2D);
+			glBegin(GL_QUADS);
+			glColor4f(U.sculpt_paint_overlay_col[0],U.sculpt_paint_overlay_col[1],U.sculpt_paint_overlay_col[2], str);
+			glTexCoord2f(0,0);
+			glVertex2f(-r3, -r3);
+			glTexCoord2f(1,0);
+			glVertex2f(r3, -r3);
+			glTexCoord2f(1,1);
+			glVertex2f(r3, r3);
+			glTexCoord2f(0,1);
+			glVertex2f(-r3, r3);
+			glEnd();
+			glDisable(GL_TEXTURE_2D);
+
+			glDisable(GL_BLEND);
+
+			{
+				const float unprojected_radius= unproject_brush_radius(CTX_data_active_object(C), &vc, location, r1);
+				const float max_thickness= 0.12;
+				const float min_thickness= 0.06;
+				const float thickness=     1.0 - min_thickness - visual_strength*max_thickness;
+				const float inner_radius=  unprojected_radius*thickness;
+				const float outer_radius=  unprojected_radius;
+
+				draw_on_surface_cursor(modelview, projection, col, alpha, ob->size, viewport, location, inner_radius, outer_radius, sculpt_get_brush_size(brush));
+			}
+
+			glClear(GL_STENCIL_BUFFER_BIT);
+
+			{
+				const float unprojected_radius= unproject_brush_radius(CTX_data_active_object(C), &vc, location, r2);
+				const float max_thickness= 0.12;
+				const float min_thickness= 0.06;
+				const float thickness=     1.0 - min_thickness - visual_strength*max_thickness;
+				const float inner_radius=  unprojected_radius*thickness;
+				const float outer_radius=  unprojected_radius;
+
+				draw_on_surface_cursor(modelview, projection, col, alpha, ob->size, viewport, location, inner_radius, outer_radius, sculpt_get_brush_size(brush));
+			}
 		}
+	}
 
-		glBindTexture(GL_TEXTURE_2D, rc->tex);
+	if (!hit) {
+		glPushMatrix();
+		
+		glTranslatef((float)x, (float)y, 0.0f);
 
-		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+		glColor4f(col[0], col[1], col[2], 0.5f);
+		glEnable( GL_LINE_SMOOTH );
+		glEnable(GL_BLEND);
 
-		glEnable(GL_TEXTURE_2D);
-		glBegin(GL_QUADS);
-		glColor4f(0,0,0, str);
-		glTexCoord2f(0,0);
-		glVertex2f(-r3, -r3);
-		glTexCoord2f(1,0);
-		glVertex2f(r3, -r3);
-		glTexCoord2f(1,1);
-		glVertex2f(r3, r3);
-		glTexCoord2f(0,1);
-		glVertex2f(-r3, r3);
-		glEnd();
-		glDisable(GL_TEXTURE_2D);
+		if(rc->mode == WM_RADIALCONTROL_ANGLE)
+			fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
+
+		if(rc->tex) {
+			if(rc->mode == WM_RADIALCONTROL_ANGLE) {
+				glRotatef(angle, 0, 0, 1);
+				fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
+			}
+
+			glBindTexture(GL_TEXTURE_2D, rc->tex);
+
+			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+			glEnable(GL_TEXTURE_2D);
+			glBegin(GL_QUADS);
+			glColor4f(U.sculpt_paint_overlay_col[0],U.sculpt_paint_overlay_col[1],U.sculpt_paint_overlay_col[2], str);
+			glTexCoord2f(0,0);
+			glVertex2f(-r3, -r3);
+			glTexCoord2f(1,0);
+			glVertex2f(r3, -r3);
+			glTexCoord2f(1,1);
+			glVertex2f(r3, r3);
+			glTexCoord2f(0,1);
+			glVertex2f(-r3, r3);
+			glEnd();
+			glDisable(GL_TEXTURE_2D);
+		}
+
+		glColor4f(col[0], col[1], col[2], 0.5f);
+		glutil_draw_lined_arc(0.0, M_PI*2.0, r1, 40);
+		glutil_draw_lined_arc(0.0, M_PI*2.0, r2, 40);
+		glDisable(GL_BLEND);
+		glDisable( GL_LINE_SMOOTH );
+		
+		glPopMatrix();
 	}
-
-	glColor4ub(255, 255, 255, 128);	
-	glutil_draw_lined_arc(0.0, M_PI*2.0, r1, 40);
-	glutil_draw_lined_arc(0.0, M_PI*2.0, r2, 40);
-	glDisable(GL_BLEND);
-	glDisable( GL_LINE_SMOOTH );
-	
-	glPopMatrix();
 }
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list