[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34169] trunk/blender/source/blender: Sculpt/Paint:

Nicholas Bishop nicholasbishop at gmail.com
Sat Jan 8 02:45:03 CET 2011


Revision: 34169
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=34169
Author:   nicholasbishop
Date:     2011-01-08 01:45:02 +0000 (Sat, 08 Jan 2011)
Log Message:
-----------
Sculpt/Paint:

More cleanups: moved a function declaration to the correct module,
removed old/incorrect comments, marked more things with TODO where
appropriate, refactored copy-pasted function, de-duplicated code.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_brush.h
    trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h
    trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_utils.c
    trunk/blender/source/blender/editors/sculpt_paint/sculpt.c
    trunk/blender/source/blender/editors/sculpt_paint/sculpt_intern.h

Modified: trunk/blender/source/blender/blenkernel/BKE_brush.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_brush.h	2011-01-08 01:16:35 UTC (rev 34168)
+++ trunk/blender/source/blender/blenkernel/BKE_brush.h	2011-01-08 01:45:02 UTC (rev 34169)
@@ -56,6 +56,9 @@
 int brush_clone_image_set_nr(struct Brush *brush, int nr);
 int brush_clone_image_delete(struct Brush *brush);
 
+/* jitter */
+void brush_jitter_pos(struct Brush *brush, float *pos, float *jitterpos);
+
 /* brush curve */
 void brush_curve_preset(struct Brush *b, /*enum CurveMappingPreset*/int preset);
 float brush_curve_strength_clamp(struct Brush *br, float p, const float len);

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h	2011-01-08 01:16:35 UTC (rev 34168)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h	2011-01-08 01:45:02 UTC (rev 34169)
@@ -31,6 +31,7 @@
 
 struct ARegion;
 struct bContext;
+struct bglMats;
 struct Brush;
 struct ListBase;
 struct Mesh;
@@ -99,6 +100,7 @@
 
 
 /* paint_utils.c */
+void projectf(struct bglMats *mats, const float v[3], float p[2]);
 float paint_calc_object_space_radius(struct ViewContext *vc, float center[3], float pixel_radius);
 float paint_get_tex_pixel(struct Brush* br, float u, float v);
 int imapaint_pick_face(struct ViewContext *vc, struct Mesh *me, int *mval, unsigned int *index);

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c	2011-01-08 01:16:35 UTC (rev 34168)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c	2011-01-08 01:45:02 UTC (rev 34169)
@@ -51,9 +51,10 @@
 #include "ED_view3d.h"
 
 #include "paint_intern.h"
-#include "sculpt_intern.h" // XXX, for expedience in getting this working, refactor later (or this just shows that this needs unification)
+/* still needed for sculpt_stroke_get_location, should be
+   removed eventually (TODO) */
+#include "sculpt_intern.h"
 
-
 #include <float.h>
 #include <math.h>
 
@@ -321,18 +322,6 @@
 	return 1;
 }
 
-/* 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];
@@ -385,8 +374,11 @@
 	window[0] = x + stroke->vc.ar->winrct.xmin;
 	window[1] = y + stroke->vc.ar->winrct.ymin;
 
-	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);
@@ -646,47 +638,52 @@
 	glDisable(GL_LINE_SMOOTH);
 }
 
+/* if this is a tablet event, return tablet pressure and set *pen_flip
+   to 1 if the eraser tool is being used, 0 otherwise */
+static float event_tablet_data(wmEvent *event, int *pen_flip)
+{
+	int erasor = 0;
+	float pressure = 1;
+
+	if(event->custom == EVT_DATA_TABLET) {
+		wmTabletData *wmtab= event->customdata;
+
+		erasor = (wmtab->Active == EVT_TABLET_ERASER);
+		pressure = (wmtab->Active != EVT_TABLET_NONE) ? wmtab->Pressure : 1;
+	}
+
+	if(pen_flip)
+		(*pen_flip) = erasor;
+
+	return pressure;
+}
+
 /* Put the location of the next stroke dot into the stroke RNA and apply it to the mesh */
 static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *event, float mouse_in[2])
 {
-	Paint *paint = paint_get_active(CTX_data_scene(C)); // XXX
-	Brush *brush = paint_brush(paint); // XXX
-
+	Paint *paint = paint_get_active(CTX_data_scene(C));
+	Brush *brush = paint_brush(paint);
+	PaintStroke *stroke = op->customdata;
 	float mouse[3];
-
 	PointerRNA itemptr;
-
 	float location[3];
-
 	float pressure;
-	int   pen_flip;
+	int pen_flip;
 
-	ViewContext vc; // XXX
+	/* see if tablet affects event */
+	pressure = event_tablet_data(event, &pen_flip);
 
-	PaintStroke *stroke = op->customdata;
-
-	view3d_set_viewcontext(C, &vc); // XXX
-
-	/* Tablet */
-	if(event->custom == EVT_DATA_TABLET) {
-		wmTabletData *wmtab= event->customdata;
-
-		pressure = (wmtab->Active != EVT_TABLET_NONE) ? wmtab->Pressure : 1;
-		pen_flip = (wmtab->Active == EVT_TABLET_ERASER);
-	}
-	else {
-		pressure = 1;
-		pen_flip = 0;
-	}
-
-	// XXX: temporary check for sculpt mode until things are more unified
-	if (vc.obact->sculpt) {
+	/* TODO: as sculpt and other paint modes are unified, this
+	   separation will go away */
+	if(stroke->vc.obact->sculpt) {
 		float delta[3];
 
 		brush_jitter_pos(brush, mouse_in, mouse);
 
-		// XXX: meh, this is round about because brush_jitter_pos isn't written in the best way to be reused here
-		if (brush->flag & BRUSH_JITTER_PRESSURE) {
+		/* XXX: meh, this is round about because
+		   brush_jitter_pos isn't written in the best way to
+		   be reused here */
+		if(brush->flag & BRUSH_JITTER_PRESSURE) {
 			sub_v3_v3v3(delta, mouse, mouse_in);
 			mul_v3_fl(delta, pressure);
 			add_v3_v3v3(mouse, mouse_in, delta);
@@ -695,7 +692,7 @@
 	else
 		copy_v3_v3(mouse, mouse_in);
 
-	/* XXX: can remove the if statement once all modes have this */
+	/* TODO: can remove the if statement once all modes have this */
 	if(stroke->get_location)
 		stroke->get_location(C, stroke, location, mouse);
 	else
@@ -704,10 +701,10 @@
 	/* Add to stroke */
 	RNA_collection_add(op->ptr, "stroke", &itemptr);
 
-	RNA_float_set_array(&itemptr, "location",     location);
-	RNA_float_set_array(&itemptr, "mouse",        mouse);
-	RNA_boolean_set    (&itemptr, "pen_flip",     pen_flip);
-	RNA_float_set      (&itemptr, "pressure", pressure);
+	RNA_float_set_array(&itemptr, "location", location);
+	RNA_float_set_array(&itemptr, "mouse", mouse);
+	RNA_boolean_set(&itemptr, "pen_flip", pen_flip);
+	RNA_float_set(&itemptr, "pressure", pressure);
 
 	stroke->last_mouse_position[0] = mouse[0];
 	stroke->last_mouse_position[1] = mouse[1];
@@ -769,15 +766,9 @@
 		if(length > FLT_EPSILON) {
 			int steps;
 			int i;
-			float pressure = 1;
+			float pressure;
 
-			// XXX duplicate code
-			if(event->custom == EVT_DATA_TABLET) {
-				wmTabletData *wmtab= event->customdata;
-				if(wmtab->Active != EVT_TABLET_NONE)
-					pressure = brush_use_size_pressure(stroke->brush) ? wmtab->Pressure : 1;
-			}
-
+			pressure = event_tablet_data(event, NULL);
 			scale = (brush_size(stroke->brush)*pressure*stroke->brush->spacing/50.0f) / length;
 			mul_v2_fl(vec, scale);
 

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_utils.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_utils.c	2011-01-08 01:16:35 UTC (rev 34168)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_utils.c	2011-01-08 01:45:02 UTC (rev 34169)
@@ -21,6 +21,8 @@
 #include "RNA_define.h"
 
 #include "BIF_gl.h"
+/* TODO: remove once projectf goes away */
+#include "BIF_glutil.h"
 
 #include "RE_shader_ext.h"
 
@@ -35,6 +37,19 @@
 
 #include "paint_intern.h"
 
+/* convert a point in model coordinates to 2D screen coordinates */
+/* TODO: can be deleted once all calls are replaced with
+   view3d_project_float() */
+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;
+}
+
 float paint_calc_object_space_radius(ViewContext *vc, float center[3],
 				     float pixel_radius)
 {

Modified: trunk/blender/source/blender/editors/sculpt_paint/sculpt.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/sculpt.c	2011-01-08 01:16:35 UTC (rev 34168)
+++ trunk/blender/source/blender/editors/sculpt_paint/sculpt.c	2011-01-08 01:45:02 UTC (rev 34169)
@@ -59,7 +59,6 @@
 #include "BKE_paint.h"
 #include "BKE_report.h"
 
-#include "BIF_gl.h"
 #include "BIF_glutil.h"
 
 #include "WM_api.h"
@@ -84,10 +83,6 @@
 #include <omp.h>
 #endif
 
-/* ==== FORWARD DEFINITIONS =====
- *
- */
-
 void ED_sculpt_force_update(bContext *C)
 {
 	Object *ob= CTX_data_active_object(C);
@@ -151,10 +146,6 @@
 	return 0;
 }
 
-/* ===== STRUCTS =====
- *
- */
-
 typedef enum StrokeFlags {
 	CLIP_X = 1,
 	CLIP_Y = 2,
@@ -225,22 +216,6 @@
 	float plane_trim_squared;
 } StrokeCache;
 
-/* ===== OPENGL =====
- *
- * Simple functions to get data from the GL
- */
-
-/* Convert a point in model coordinates to 2D screen coordinates. */
-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;
-}
-
 /*** BVH Tree ***/
 
 /* Get a screen-space rectangle of the modified area */

Modified: trunk/blender/source/blender/editors/sculpt_paint/sculpt_intern.h
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/sculpt_intern.h	2011-01-08 01:16:35 UTC (rev 34168)
+++ trunk/blender/source/blender/editors/sculpt_paint/sculpt_intern.h	2011-01-08 01:45:02 UTC (rev 34169)
@@ -55,7 +55,6 @@
 struct MultiresModifierData *sculpt_multires_active(struct Scene *scene, struct Object *ob);
 
 struct Brush *sculptmode_brush(void);
-//void do_symmetrical_brush_actions(struct Sculpt *sd, struct wmOperator *wm, struct BrushAction *a, short *, short *);
 
 void sculpt(Sculpt *sd);
 
@@ -70,9 +69,6 @@
 void sculpt_stroke_apply_all(struct Sculpt *sd, struct SculptStroke *);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list