[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36893] branches/soc-2010-jwilkins/source/ blender/editors/sculpt_paint/paint_stroke.c: Hand merged from trunk paint_stroke.c revisions 30641-36811.

Jason Wilkins Jason.A.Wilkins at gmail.com
Wed May 25 12:42:36 CEST 2011


Revision: 36893
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36893
Author:   jwilkins
Date:     2011-05-25 10:42:36 +0000 (Wed, 25 May 2011)
Log Message:
-----------
Hand merged from trunk paint_stroke.c revisions 30641-36811.
Doing it this way means there is no precise history of changes in my branch, but history should be preserved in trunk.
Not compiled or tested yet, just committing to get it saved separately from the rest of this merge.

Modified Paths:
--------------
    branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.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	2011-05-25 10:29:24 UTC (rev 36892)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c	2011-05-25 10:42:36 UTC (rev 36893)
@@ -26,8 +26,15 @@
  *
  */
 
+/** \file blender/editors/sculpt_paint/paint_stroke.c
+ *  \ingroup edsculpt
+ */
+
 #include "MEM_guardedalloc.h"
 
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_brush_types.h"
@@ -42,9 +49,6 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
-#include "BLI_math.h"
-
-
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
@@ -52,6 +56,8 @@
 #include "ED_view3d.h"
 
 #include "paint_intern.h"
+/* still needed for sculpt_stroke_get_location, should be
+   removed eventually (TODO) */
 #include "sculpt_intern.h" // XXX, for expedience in getting this working, refactor later (or this just shows that this needs unification)
 
 #include "BKE_DerivedMesh.h"
@@ -76,6 +82,9 @@
 	   passes over the mesh */
 	int stroke_started;
 
+	/* event that started stroke, for modal() return */
+	int event_type;
+
 	StrokeGetLocation get_location;
 	StrokeTestStart test_start;
 	StrokeUpdateStep update_step;
@@ -203,8 +212,6 @@
 
 #endif
 
-extern float get_tex_pixel(Brush* br, float u, float v);
-
 typedef struct Snapshot {
 	float size[3];
 	float ofs[3];
@@ -256,7 +263,7 @@
 	snap->winy = ar->winy;
 }
 
-static int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
+static int paint_load_overlay_tex(Sculpt *sd, Brush* br, ViewContext* vc)
 {
 	static GLuint overlay_texture = 0;
 	static int init = 0;
@@ -265,7 +272,7 @@
 	static Snapshot snap;
 	static int old_size = -1;
 
-	GLubyte* buffer = 0;
+	GLubyte* buffer = NULL;
 
 	int size;
 	int j;
@@ -365,12 +372,12 @@
 					   atan2, sqrtf, sin, and cos. */
 					if ((br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED) &&
 						 br->mtex.tex &&
-						 (rotation > 0.001 || rotation < -0.001))
+						 (rotation > 0.001f || rotation < -0.001f))
 					{
 						const float angle= atan2(y, x) + rotation;
 
-						x = len * cos(angle);
-						y = len * sin(angle);
+						x = len * cosf(angle);
+						y = len * sinf(angle);
 					}
 
 					x *= br->mtex.size[0];
@@ -379,7 +386,7 @@
 					x += br->mtex.ofs[0];
 					y += br->mtex.ofs[1];
 
-					avg = br->mtex.tex ? get_tex_pixel(br, x, y) : 1;
+					avg = br->mtex.tex ? paint_get_tex_pixel(br, x, y) : 1;
 
 					avg += br->texture_sample_bias;
 
@@ -473,17 +480,17 @@
 				brush->texture_overlay_alpha / 100.0f);
 
 			glBegin(GL_QUADS);
-				glTexCoord2f(0, 0);
-				glVertex2f(0, 0);
+				glTexCoord2f(0.0f, 0.0f);
+				glVertex2f(0.0f, 0.0f);
 
-				glTexCoord2f(1, 0);
-				glVertex2f(ar->winx, 0);
+				glTexCoord2f(1.0f, 0.0f);
+				glVertex2f(ar->winx, 0.0f);
 
-				glTexCoord2f(1, 1);
+				glTexCoord2f(1.0f, 1.0f);
 				glVertex2f(ar->winx, ar->winy);
 
-				glTexCoord2f(0, 1);
-				glVertex2f(0, ar->winy);
+				glTexCoord2f(0.0f, 1.0f);
+				glVertex2f(0.0f, ar->winy);
 			glEnd();
 
 			glPopMatrix();
@@ -495,40 +502,28 @@
 	}
 }
 
-/* Convert a point in model coordinates to 2D screen coordinates. */
-// XXX duplicated from sculpt.c, deal with this later.
-static void projectf(bglMats *mats, const float v[3], float p[2])
-{
-	double ux, uy, uz;
-
-	gluProject(v[0],v[1],v[2], mats->modelview, mats->projection,
-		   (GLint *)mats->viewport, &ux, &uy, &uz);
-	p[0]= ux;
-	p[1]= uy;
-}
-
 static int project_brush_radius(RegionView3D* rv3d, float radius, float location[3], bglMats* mats)
 {
 	float view[3], nonortho[3], ortho[3], offset[3], p1[2], p2[2];
 
-	viewvector(rv3d, location, view);
+	ED_view3d_global_to_vector(rv3d, location, view);
 
 	// create a vector that is not orthogonal to view
 
-	if (fabsf(view[0]) < 0.1) {
-		nonortho[0] = view[0] + 1;
+	if (fabsf(view[0]) < 0.1f) {
+		nonortho[0] = view[0] + 1.0f;
 		nonortho[1] = view[1];
 		nonortho[2] = view[2];
 	}
-	else if (fabsf(view[1]) < 0.1) {
+	else if (fabsf(view[1]) < 0.1f) {
 		nonortho[0] = view[0];
-		nonortho[1] = view[1] + 1;
+		nonortho[1] = view[1] + 1.0f;
 		nonortho[2] = view[2];
 	}
 	else {
 		nonortho[0] = view[0];
 		nonortho[1] = view[1];
-		nonortho[2] = view[2] + 1;
+		nonortho[2] = view[2] + 1.0f;
 	}
 
 	// get a vector in the plane of the view
@@ -547,13 +542,21 @@
 	return len_v2v2(p1, p2);
 }
 
-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])
+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])
 {
 	struct PaintStroke *stroke;
 	float window[2];
 	int hit;
 
-	stroke = paint_stroke_new(C, NULL, NULL, NULL, NULL);
+	stroke = paint_stroke_new(C, NULL, NULL, NULL, NULL, 0);
 
 	window[0] = x + stroke->vc.ar->winrct.xmin;
 	window[1] = y + stroke->vc.ar->winrct.ymin;
@@ -562,13 +565,21 @@
 	memcpy(projection, stroke->vc.rv3d->winmat, sizeof(float[16]));
 	memcpy(viewport, stroke->mats.viewport, sizeof(int[4]));
 
-	if (stroke->vc.obact->sculpt && stroke->vc.obact->sculpt->pbvh && sculpt_stroke_get_location(C, stroke, location, window)) {
-		*pixel_radius = project_brush_radius(stroke->vc.rv3d, brush_unprojected_radius(stroke->brush), location, &stroke->mats);
+	if (stroke->vc.obact->sculpt &&
+		stroke->vc.obact->sculpt->pbvh &&
+		sculpt_stroke_get_location(C, stroke, location, window)) 
+	{
+		*pixel_radius = 
+			project_brush_radius(
+				stroke->vc.rv3d,
+				brush_unprojected_radius(stroke->brush),
+				location,
+				&stroke->mats);
 
 		if (*pixel_radius == 0)
 			*pixel_radius = brush_size(stroke->brush);
 
-		mul_m4_v3(stroke->vc.obact->sculpt->ob->obmat, location);
+		mul_m4_v3(stroke->vc.obact->obmat, location);
 
 		hit = 1;
 	}
@@ -585,22 +596,6 @@
 	return hit;
 }
 
-// XXX duplicated from sculpt.c
-float unproject_brush_radius(Object *ob, ViewContext *vc, float center[3], float offset)
-{
-	float delta[3], scale, loc[3];
-
-	mul_v3_m4v3(loc, ob->obmat, center);
-
-	initgrabz(vc->rv3d, loc[0], loc[1], loc[2]);
-	window_to_3d_delta(vc->ar, delta, offset, 0);
-
-	scale= fabsf(mat4_to_scale(ob->obmat));
-	scale= (scale == 0.0f)? 1.0f: scale;
-
-	return len_v3(delta)/scale;
-}
-
 static void set_brush_dot_location(float *modelview, float location[3], const char symm, const char axis, float angle)
 {
 	glLoadMatrixf(modelview);
@@ -609,15 +604,15 @@
 
 	switch (axis) {
 		case 'X':
-			glRotatef(angle, 1, 0, 0);
+			glRotatef(angle, 1.0f, 0.0f, 0.0f);
 			break;
 
 		case 'Y':
-			glRotatef(angle, 0, 1, 0);
+			glRotatef(angle, 0.0f, 1.0f, 0.0f);
 			break;
 
 		case 'Z':
-			glRotatef(angle, 0, 0, 1);
+			glRotatef(angle, 0.0f, 0.0f, 1.0f);
 			break;
 	}
 
@@ -702,18 +697,14 @@
 	glPopAttrib();
 }
 
-static void draw_fixed_overlay(Sculpt *sd, Brush *brush, ViewContext *vc, float t, float b, float l, float r, float angle)
+static void draw_fixed_overlay(Sculpt *sd, Brush *brush, ViewContext *vc, rctf* quad, float angle)
 {
 	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_CURRENT_BIT|
 		GL_TEXTURE_BIT);
 
 	if (paint_load_overlay_tex(sd, brush, vc->ar)) {
@@ -731,16 +722,16 @@
 		glPushMatrix();
 		glLoadIdentity();
 
-		glTranslatef(0.5f, 0.5f, 0);
+		glTranslatef(0.5f, 0.5f, 0.0f);
 
-		glRotatef(angle, 0, 0, 1);
+		glRotatef(angle, 0.0f, 0.0f, 1.0f);
 
-		glTranslatef(-0.5f, -0.5f, 0);
+		glTranslatef(-0.5f, -0.5f, 0.0f);
 
 		if (sd->draw_pressure && (brush->flag & BRUSH_SIZE_PRESSURE)) {
-			glTranslatef(0.5f, 0.5f, 0);
+			glTranslatef(0.5f, 0.5f, 0.0f);
 			glScalef(1.0f/sd->pressure_value, 1.0f/sd->pressure_value, 1);
-			glTranslatef(-0.5f, -0.5f, 0);
+			glTranslatef(-0.5f, -0.5f, 0.0f);
 		}
 
 		glColor4f(
@@ -750,17 +741,17 @@
 			brush->texture_overlay_alpha / 100.0f);
 
 		glBegin(GL_QUADS);
-			glTexCoord2f(0, 0);
-			glVertex2f(l, b);
+			glTexCoord2f(0.0f, 0.0f);
+			glVertex2f(quad->xmin, quad->ymin);
 
-			glTexCoord2f(1, 0);
-			glVertex2f(r, b);
+			glTexCoord2f(1.0f, 0.0f);
+			glVertex2f(quad->xmax, quad->ymin);
 
-			glTexCoord2f(1, 1);
-			glVertex2f(r, t);
+			glTexCoord2f(1.0f, 1.0f);
+			glVertex2f(quad->xmax, quad->ymax);
 
-			glTexCoord2f(0, 1);
-			glVertex2f(l, t);
+			glTexCoord2f(0.0f, 1.0f);
+			glVertex2f(quad->xmin, quad->ymax);
 		glEnd();
 
 		glPopMatrix();
@@ -913,7 +904,7 @@
 	glPopAttrib();
 }
 
-void ED_draw_fixed_overlay_on_surface(float modelview[16], float projection[16], float size[3], int viewport[4], float location[3], float outer_radius, Sculpt *sd, Brush *brush, ViewContext *vc, float t, float b, float l, float r, float angle)
+void ED_draw_fixed_overlay_on_surface(float modelview[16], float projection[16], float size[3], int viewport[4], float location[3], float outer_radius, Sculpt *sd, Brush *brush, ViewContext *vc, rctf* quad, float angle)
 {
 	stencil_brush_on_surface(modelview, projection, size, viewport, location, outer_radius);
 
@@ -923,7 +914,7 @@
 	glStencilFunc(GL_EQUAL, 2, 0xFF);
 	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
 
-	draw_fixed_overlay(sd, brush, vc, t, b, l, r, angle);
+	draw_fixed_overlay(sd, brush, vc, quad, angle);
 
 	glPopAttrib();
 }
@@ -1242,18 +1233,25 @@
 // Functions should be refactored so that they can be used between sculpt.c and
 // paint_stroke.c clearly and optimally and the lines of communication between the
 // two modules should be more clearly defined.
-static void paint_draw_cursor(bContext *C, int x, int y, void *unused)
+static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
 {
+	Paint *paint = paint_get_active(CTX_data_scene(C));
+	Brush *brush = paint_brush(paint);
+
 	ViewContext vc;
 
-	(void)unused;
+	/* sd->last_angle, sd->last_y, sd->last_x, and set_brush_size need to be
+       updated even if we are not drawing the cursor, so we cannot return
+	   until they are updated. */
 
+	/* can't use stroke vc here because this will be called during
+	   mouse over too, not just during a stroke */	
 	view3d_set_viewcontext(C, &vc);
 
+	/* TODO: as sculpt and other paint modes are unified, this
+	   special mode of drawing will go away */
 	if (vc.obact->sculpt) {
-		Paint *paint = paint_get_active(CTX_data_scene(C));

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list