[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47891] branches/soc-2012-bratwurst/source /blender: Rake brushes for texture paint
Antony Riakiotakis
kalast at gmail.com
Thu Jun 14 13:47:23 CEST 2012
Revision: 47891
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47891
Author: psy-fi
Date: 2012-06-14 11:47:22 +0000 (Thu, 14 Jun 2012)
Log Message:
-----------
Rake brushes for texture paint
==============================
* port brushes correctly to projection painting
* put rake state to unified settings, it's probably the most accessible
place for texpaint/sculpt/display functions. Ideally I would put these
in the paint or brush structs but since these are actually screen-space
state they can be unique for each space and common to all brushes. This
is in preparation to unifying brush draw code.
Modified Paths:
--------------
branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c
branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_cursor.c
branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c
branches/soc-2012-bratwurst/source/blender/makesdna/DNA_scene_types.h
Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c 2012-06-14 11:47:11 UTC (rev 47890)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c 2012-06-14 11:47:22 UTC (rev 47891)
@@ -801,7 +801,6 @@
double lasttime; /* time of last update */
float lastpressure;
- float rotation;
short firsttouch; /* first paint op */
@@ -1025,7 +1024,7 @@
short flt;
const int diameter = 2 * BKE_brush_size_get(scene, brush);
const float alpha = BKE_brush_alpha_get(scene, brush);
- const float rotation = painter->rotation;
+ const float rotation = scene->toolsettings->unified_paint_settings.last_angle;
if (diameter != cache->lastsize ||
alpha != cache->lastalpha ||
@@ -1113,6 +1112,7 @@
void *user, int use_color_correction)
{
Scene *scene = painter->scene;
+ UnifiedPaintSettings *unified_paint_settings = &scene->toolsettings->unified_paint_settings;
Brush *brush = painter->brush;
int totpaintops = 0;
@@ -1128,9 +1128,10 @@
painter->startpaintpos[1] = pos[1];
if(brush->flag & BRUSH_RANDOM_ROTATION)
- painter->rotation = BLI_frand()*2*M_PI;
- else
- painter->rotation = brush->mtex.rot;
+ unified_paint_settings->last_angle = BLI_frand()*2*M_PI;
+ else if(!(brush->flag & BRUSH_RAKE))
+ unified_paint_settings->last_angle = brush->mtex.rot;
+ copy_v2_v2(unified_paint_settings->last_pos, pos);
brush_pressure_apply(painter, brush, pressure);
if (painter->cache.enabled)
@@ -1193,15 +1194,25 @@
painter->accumdistance += len;
if(brush->flag & BRUSH_RAKE) {
- if(len > 0.001) {
+ float mrakediff[2];
+ sub_v2_v2v2(mrakediff, pos, unified_paint_settings->last_pos);
+
+ if(len_squared_v2(mrakediff) > RAKE_THRESHHOLD*RAKE_THRESHHOLD) {
float angle;
- angle = acos(dmousepos[0]);
- painter->rotation = (dmousepos[1] > 0)? angle : -angle;
- painter->rotation += brush->mtex.rot;
+ angle = atan2(dmousepos[1], dmousepos[0]);
+ unified_paint_settings->last_angle = angle;
+ unified_paint_settings->last_angle += brush->mtex.rot;
+
+ /* to match sculpt behaviour */
+ interp_v2_v2v2(unified_paint_settings->last_pos, unified_paint_settings->last_pos,
+ pos, 0.5);
}
} else if(brush->flag & BRUSH_RANDOM_ROTATION)
- painter->rotation = BLI_frand()*2*M_PI;
+ unified_paint_settings->last_angle = BLI_frand()*2*M_PI;
+ else
+ unified_paint_settings->last_angle = brush->mtex.rot;
+
if (brush->flag & BRUSH_SPACE) {
/* do paint op over unpainted distance */
while ((len > 0.0f) && (painter->accumdistance >= spacing)) {
Modified: branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_cursor.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_cursor.c 2012-06-14 11:47:11 UTC (rev 47890)
+++ branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_cursor.c 2012-06-14 11:47:22 UTC (rev 47891)
@@ -539,7 +539,7 @@
{
const float u = 0.5f;
const float v = 1 - u;
- const float r = 20;
+ const float r = RAKE_THRESHHOLD;
const float dx = sd->last_x - x;
const float dy = sd->last_y - y;
Modified: branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c 2012-06-14 11:47:11 UTC (rev 47890)
+++ branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c 2012-06-14 11:47:22 UTC (rev 47891)
@@ -3840,6 +3840,8 @@
const float *lastpos = ((ProjectHandle *)ph_v)->prevmval;
const float *pos = ((ProjectHandle *)ph_v)->mval;
const int thread_index = ((ProjectHandle *)ph_v)->thread_index;
+ Scene *scene = ps->scene;
+ UnifiedPaintSettings *unified_paint_settings = &scene->toolsettings->unified_paint_settings;
/* Done with args from ProjectHandle */
LinkNode *node;
@@ -3919,16 +3921,22 @@
if (falloff > 0.0f) {
if (ps->is_texbrush) {
+ float samplecos[2];
+ if(ps->brush->flag & (BRUSH_RAKE | BRUSH_RANDOM_ROTATION)) {
+ sub_v2_v2v2(samplecos, projPixel->projCoSS, pos);
+ } else {
+ copy_v2_v2(samplecos, projPixel->projCoSS);
+ }
/* note, for clone and smear, we only use the alpha, could be a special function */
- BKE_brush_sample_tex(ps->scene, ps->brush, projPixel->projCoSS, rgba, thread_index, 0);
+ BKE_brush_sample_tex(ps->scene, ps->brush, samplecos, rgba, thread_index, unified_paint_settings->last_angle);
alpha = rgba[3];
}
else {
alpha = 1.0f;
}
- if (ps->is_airbrush) {
- /* for an aurbrush there is no real mask, so just multiply the alpha by it */
+ if (ps->is_airbrush || (ps->brush->flag & (BRUSH_RANDOM_ROTATION | BRUSH_RAKE))) {
+ /* for an airbrush or rake brush there is no real mask, so just multiply the alpha by it */
alpha *= falloff * BKE_brush_alpha_get(ps->scene, ps->brush);
mask = ((float)projPixel->mask) / 65535.0f;
}
Modified: branches/soc-2012-bratwurst/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/makesdna/DNA_scene_types.h 2012-06-14 11:47:11 UTC (rev 47890)
+++ branches/soc-2012-bratwurst/source/blender/makesdna/DNA_scene_types.h 2012-06-14 11:47:22 UTC (rev 47891)
@@ -864,11 +864,19 @@
/* unified brush weight, [0, 1] */
float weight;
+ /* storage for texture rake state to avoid recalculating the angle repeatedly */
+ float last_angle;
+ float last_pos[2];
+ int lock; /* avoid recalculating in display function, rather display the result */
+
/* user preferences for sculpt and paint */
int flag;
int pad;
} UnifiedPaintSettings;
+/* threshhold to move before updating the brush rotation */
+#define RAKE_THRESHHOLD 20
+
typedef enum {
UNIFIED_PAINT_SIZE = (1<<0),
UNIFIED_PAINT_ALPHA = (1<<1),
More information about the Bf-blender-cvs
mailing list