[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55146] trunk/blender/source/blender/ editors/sculpt_paint: * Cleanup: collapse unneeded paint 2d function to the caller.
Antony Riakiotakis
kalast at gmail.com
Sun Mar 10 03:30:55 CET 2013
Revision: 55146
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55146
Author: psy-fi
Date: 2013-03-10 02:30:53 +0000 (Sun, 10 Mar 2013)
Log Message:
-----------
* Cleanup: collapse unneeded paint 2d function to the caller. Also, new
code now does not use painter_2d_paint at all. Made sure the approprate
variables of painter_2d are still initialized (They may be refactored to
become part of the ImagePaintState struct)
* Enable pressure control for new code path in texture paint. This revealed a bug, also present in blender 2.66: Size pressure is broken.
This was pretty interesting for me because it indicates that we could support
dynamic size in texture paint: (See anchored brushes)
Modified Paths:
--------------
trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c
trunk/blender/source/blender/editors/sculpt_paint/paint_image_proj.c
trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h
Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image.c 2013-03-10 00:58:09 UTC (rev 55145)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c 2013-03-10 02:30:53 UTC (rev 55146)
@@ -5058,8 +5058,7 @@
MTex *mtex = &brush->mtex;
if (mtex->tex && mtex->tex->nodetree)
ntreeTexBeginExecTree(mtex->tex->nodetree, 1); /* has internal flag to detect it only does it once */
- }
-
+ }
}
static int texture_paint_init(bContext *C, wmOperator *op)
Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c 2013-03-10 00:58:09 UTC (rev 55145)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c 2013-03-10 02:30:53 UTC (rev 55146)
@@ -179,10 +179,6 @@
BKE_brush_alpha_set(painter->scene, brush, max_ff(0.0f, painter->startalpha * pressure));
if (BKE_brush_use_size_pressure(painter->scene, brush))
BKE_brush_size_set(painter->scene, brush, max_ff(1.0f, painter->startsize * pressure));
- if (brush->flag & BRUSH_JITTER_PRESSURE)
- brush->jitter = max_ff(0.0f, painter->startjitter * pressure);
- if (brush->flag & BRUSH_SPACING_PRESSURE)
- brush->spacing = max_ff(1.0f, painter->startspacing * (1.5f - pressure));
}
@@ -892,52 +888,58 @@
BKE_image_release_ibuf(s->brush->clone.image, s->clonecanvas, NULL);
}
-static int paint_2d_sub_stroke(ImagePaintState *s, BrushPainter *painter, Image *image, float *uv, int update, float pressure)
+int paint_2d_stroke(void *ps, const int prev_mval[2], const int mval[2], int eraser)
{
- ImBuf *ibuf = BKE_image_acquire_ibuf(image, s->sima ? &s->sima->iuser : NULL, NULL);
- float pos[2];
- int is_data;
+ float newuv[2], olduv[2];
+ int redraw = 0;
+ ImagePaintState *s = ps;
+ BrushPainter *painter = s->painter;
+ ImBuf *ibuf = BKE_image_acquire_ibuf(s->image, s->sima ? &s->sima->iuser : NULL, NULL);
+ int is_data = ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA;
if (!ibuf)
return 0;
- is_data = ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA;
+ s->blend = s->brush->blend;
+ if (eraser)
+ s->blend = IMB_BLEND_ERASE_ALPHA;
- pos[0] = uv[0] * ibuf->x;
- pos[1] = uv[1] * ibuf->y;
+ UI_view2d_region_to_view(s->v2d, mval[0], mval[1], &newuv[0], &newuv[1]);
+ UI_view2d_region_to_view(s->v2d, prev_mval[0], prev_mval[1], &olduv[0], &olduv[1]);
- brush_painter_2d_require_imbuf(painter, ((ibuf->rect_float) ? 1 : 0), 0, 0);
+ newuv[0] *= ibuf->x;
+ newuv[1] *= ibuf->y;
+ olduv[0] *= ibuf->x;
+ olduv[1] *= ibuf->y;
+
+ if (painter->firsttouch) {
+ /* paint exactly once on first touch */
+ painter->startpaintpos[0] = newuv[0];
+ painter->startpaintpos[1] = newuv[1];
+
+ painter->firsttouch = 0;
+ copy_v2_v2(painter->lastpaintpos, newuv);
+ } else {
+ copy_v2_v2(painter->lastpaintpos, olduv);
+ }
/* OCIO_TODO: float buffers are now always linear, so always use color correction
* this should probably be changed when texture painting color space is supported
*/
- if (brush_painter_2d_paint(painter, paint_2d_op, pos, 0, pressure, s, is_data == FALSE)) {
- if (update)
- imapaint_image_update(s->sima, image, ibuf, false);
- BKE_image_release_ibuf(image, ibuf, NULL);
- return 1;
+ brush_painter_2d_require_imbuf(painter, ((ibuf->rect_float) ? 1 : 0), 0, 0);
+
+ if (painter->cache.enabled)
+ brush_painter_2d_refresh_cache(painter, newuv, is_data == FALSE);
+
+ if (paint_2d_op(s, painter->cache.ibuf, olduv, newuv)) {
+ imapaint_image_update(s->sima, s->image, ibuf, false);
+ BKE_image_release_ibuf(s->image, ibuf, NULL);
+ redraw |= 1;
}
else {
- BKE_image_release_ibuf(image, ibuf, NULL);
- return 0;
+ BKE_image_release_ibuf(s->image, ibuf, NULL);
}
-}
-int paint_2d_stroke(void *ps, const int mval[2], float pressure, int eraser)
-{
- float newuv[2];
- int redraw = 0;
- ImagePaintState *s = ps;
- BrushPainter *painter = s->painter;
-
- s->blend = s->brush->blend;
- if (eraser)
- s->blend = IMB_BLEND_ERASE_ALPHA;
-
- UI_view2d_region_to_view(s->v2d, mval[0], mval[1], &newuv[0], &newuv[1]);
- redraw |= paint_2d_sub_stroke(s, painter, s->image, newuv,
- 1, pressure);
-
if (redraw)
imapaint_clear_partial_redraw();
Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image_proj.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image_proj.c 2013-03-10 00:58:09 UTC (rev 55145)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image_proj.c 2013-03-10 02:30:53 UTC (rev 55146)
@@ -4463,6 +4463,13 @@
static void paint_stroke_update_step(bContext *C, struct PaintStroke *stroke, PointerRNA *itemptr)
{
PaintOperation *pop = paint_stroke_mode_data(stroke);
+ Scene *scene = CTX_data_scene(C);
+ Brush *brush = paint_brush(&scene->toolsettings->imapaint.paint);
+
+ /* initial brush values. Maybe it should be considered moving these to stroke system */
+ float startsize = BKE_brush_size_get(scene, brush);
+ float startalpha = BKE_brush_alpha_get(scene, brush);
+
float mousef[2];
float pressure;
int mouse[2], redraw, eraser;
@@ -4473,6 +4480,11 @@
pressure = RNA_float_get(itemptr, "pressure");
eraser = RNA_boolean_get(itemptr, "pen_flip");
+ if (BKE_brush_use_alpha_pressure(scene, brush))
+ BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * pressure));
+ if (BKE_brush_use_size_pressure(scene, brush))
+ BKE_brush_size_set(scene, brush, max_ff(1.0f, startsize * pressure));
+
if (pop->mode == PAINT_MODE_3D_PROJECT) {
if (pop->first)
project_paint_begin_clone(&pop->ps, mouse);
@@ -4483,11 +4495,16 @@
}
else {
- redraw = paint_2d_stroke(pop->custom_paint, mouse, pressure, eraser);
+ redraw = paint_2d_stroke(pop->custom_paint, pop->prevmouse, mouse, eraser);
pop->prevmouse[0] = mouse[0];
pop->prevmouse[1] = mouse[1];
}
+ /* restore brush values */
+ BKE_brush_alpha_set(scene, brush, startalpha);
+ BKE_brush_size_set(scene, brush, startsize);
+
+
if (redraw)
paint_redraw(C, pop, 0);
Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h 2013-03-10 00:58:09 UTC (rev 55145)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_intern.h 2013-03-10 02:30:53 UTC (rev 55146)
@@ -127,7 +127,7 @@
void *paint_2d_new_stroke(struct bContext *, struct wmOperator *);
void paint_2d_redraw(const bContext *C, void *ps, int final);
void paint_2d_stroke_done(void *ps);
-int paint_2d_stroke(void *ps, const int mval[2], float pressure, int eraser);
+int paint_2d_stroke(void *ps, const int prev_mval[2], const int mval[2], int eraser);
void paint_brush_init_tex(struct Brush *brush);
void paint_brush_exit_tex(struct Brush *brush);
More information about the Bf-blender-cvs
mailing list