Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-11-25 20:51:16 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-11-25 20:51:16 +0300
commit55d2a56d6020a5d286d5d44f7d2d8a8d0bc9bf58 (patch)
tree959cb7abcf1ab92caa28fa5a5156520f08f9936d /source/blender/editors/sculpt_paint
parent077edbb384e3845f27cc06618046a08c7101cc4c (diff)
parentf1fa79a59554cb36ebee0a569a7b0f442fef6646 (diff)
Sculpt:
svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r24483:24889
Diffstat (limited to 'source/blender/editors/sculpt_paint')
-rw-r--r--source/blender/editors/sculpt_paint/SConscript2
-rw-r--r--source/blender/editors/sculpt_paint/paint_image.c13
-rw-r--r--source/blender/editors/sculpt_paint/paint_ops.c44
-rw-r--r--source/blender/editors/sculpt_paint/paint_stroke.c5
-rw-r--r--source/blender/editors/sculpt_paint/paint_vertex.c142
-rw-r--r--source/blender/editors/sculpt_paint/sculpt.c59
6 files changed, 180 insertions, 85 deletions
diff --git a/source/blender/editors/sculpt_paint/SConscript b/source/blender/editors/sculpt_paint/SConscript
index 3d2ea89f506..472ba361059 100644
--- a/source/blender/editors/sculpt_paint/SConscript
+++ b/source/blender/editors/sculpt_paint/SConscript
@@ -5,7 +5,7 @@ sources = env.Glob('*.c')
incs = '../include ../../blenlib ../../blenkernel ../../makesdna ../../imbuf'
incs += ' ../../windowmanager #/intern/guardedalloc #/extern/glew/include'
-incs += ' ../../render/extern/include #/intern/guardedalloc'
+incs += ' ../../render/extern/include'
incs += ' ../../gpu ../../makesrna'
if env['OURPLATFORM'] == 'linux2':
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index a411b0b021d..1f0d158ece9 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -746,8 +746,7 @@ static int project_paint_occlude_ptv_clip(
if (side) interp_v3_v3v3v3(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v3].co, ps->dm_mvert[mf->v4].co, w);
else interp_v3_v3v3v3(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v2].co, ps->dm_mvert[mf->v3].co, w);
- mul_m4_v3(ps->ob->obmat, wco);
- if(!view3d_test_clipping(ps->rv3d, wco)) {
+ if(!view3d_test_clipping(ps->rv3d, wco, 1)) {
return 1;
}
@@ -2331,8 +2330,7 @@ static void project_paint_face_init(const ProjPaintState *ps, const int thread_i
/* a pitty we need to get the worldspace pixel location here */
if(ps->rv3d->rflag & RV3D_CLIPPING) {
interp_v3_v3v3v3(wco, ps->dm_mvert[ (*(&mf->v1 + i1)) ].co, ps->dm_mvert[ (*(&mf->v1 + i2)) ].co, ps->dm_mvert[ (*(&mf->v1 + i3)) ].co, w);
- mul_m4_v3(ps->ob->obmat, wco);
- if(view3d_test_clipping(ps->rv3d, wco)) {
+ if(view3d_test_clipping(ps->rv3d, wco, 1)) {
continue; /* Watch out that no code below this needs to run */
}
}
@@ -2548,9 +2546,8 @@ static void project_paint_face_init(const ProjPaintState *ps, const int thread_i
if(ps->rv3d->rflag & RV3D_CLIPPING) {
if (side) interp_v3_v3v3v3(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v3].co, ps->dm_mvert[mf->v4].co, w);
else interp_v3_v3v3v3(wco, ps->dm_mvert[mf->v1].co, ps->dm_mvert[mf->v2].co, ps->dm_mvert[mf->v3].co, w);
-
- mul_m4_v3(ps->ob->obmat, wco);
- if(view3d_test_clipping(ps->rv3d, wco)) {
+
+ if(view3d_test_clipping(ps->rv3d, wco, 1)) {
continue; /* Watch out that no code below this needs to run */
}
}
@@ -2819,6 +2816,8 @@ static void project_paint_begin(ProjPaintState *ps)
/* ---- end defines ---- */
+ ED_view3d_local_clipping(ps->rv3d, ps->ob->obmat); /* faster clipping lookups */
+
/* paint onto the derived mesh */
/* Workaround for subsurf selection, try the display mesh first */
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index d8f13f679a5..256d114fbdc 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -140,6 +140,42 @@ void ED_operatortypes_paint(void)
WM_operatortype_append(PAINT_OT_face_deselect_all);
}
+static void ed_keymap_paint_brush_switch(wmKeyMap *keymap, const char *path)
+{
+ wmKeyMapItem *kmi;
+
+ kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", ONEKEY, KM_PRESS, 0, 0);
+ RNA_string_set(kmi->ptr, "path", path);
+ RNA_int_set(kmi->ptr, "value", 0);
+ kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", TWOKEY, KM_PRESS, 0, 0);
+ RNA_string_set(kmi->ptr, "path", path);
+ RNA_int_set(kmi->ptr, "value", 1);
+ kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", THREEKEY, KM_PRESS, 0, 0);
+ RNA_string_set(kmi->ptr, "path", path);
+ RNA_int_set(kmi->ptr, "value", 2);
+ kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", FOURKEY, KM_PRESS, 0, 0);
+ RNA_string_set(kmi->ptr, "path", path);
+ RNA_int_set(kmi->ptr, "value", 3);
+ kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", FIVEKEY, KM_PRESS, 0, 0);
+ RNA_string_set(kmi->ptr, "path", path);
+ RNA_int_set(kmi->ptr, "value", 4);
+ kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", SIXKEY, KM_PRESS, 0, 0);
+ RNA_string_set(kmi->ptr, "path", path);
+ RNA_int_set(kmi->ptr, "value", 5);
+ kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", SEVENKEY, KM_PRESS, 0, 0);
+ RNA_string_set(kmi->ptr, "path", path);
+ RNA_int_set(kmi->ptr, "value", 6);
+ kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", EIGHTKEY, KM_PRESS, 0, 0);
+ RNA_string_set(kmi->ptr, "path", path);
+ RNA_int_set(kmi->ptr, "value", 7);
+ kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", NINEKEY, KM_PRESS, 0, 0);
+ RNA_string_set(kmi->ptr, "path", path);
+ RNA_int_set(kmi->ptr, "value", 8);
+ kmi= WM_keymap_add_item(keymap, "WM_OT_context_set_int", ZEROKEY, KM_PRESS, 0, 0);
+ RNA_string_set(kmi->ptr, "path", path);
+ RNA_int_set(kmi->ptr, "value", 10);
+}
+
void ED_keymap_paint(wmKeyConfig *keyconf)
{
wmKeyMap *keymap;
@@ -155,6 +191,8 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
+ ed_keymap_paint_brush_switch(keymap, "tool_settings.sculpt.active_brush_index");
+
/* Vertex Paint mode */
keymap= WM_keymap_find(keyconf, "Vertex Paint", 0, 0);
keymap->poll= vertex_paint_poll;
@@ -167,6 +205,8 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap,
"PAINT_OT_vertex_color_set",KKEY, KM_PRESS, KM_SHIFT, 0);
+ ed_keymap_paint_brush_switch(keymap, "tool_settings.vertex_paint.active_brush_index");
+
/* Weight Paint mode */
keymap= WM_keymap_find(keyconf, "Weight Paint", 0, 0);
keymap->poll= weight_paint_poll;
@@ -179,6 +219,8 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap,
"PAINT_OT_weight_set", KKEY, KM_PRESS, KM_SHIFT, 0);
+ ed_keymap_paint_brush_switch(keymap, "tool_settings.weight_paint.active_brush_index");
+
/* Image/Texture Paint mode */
keymap= WM_keymap_find(keyconf, "Image Paint", 0, 0);
keymap->poll= image_texture_paint_poll;
@@ -190,6 +232,8 @@ void ED_keymap_paint(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "PAINT_OT_sample_color", RIGHTMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "PAINT_OT_clone_cursor_set", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
+ ed_keymap_paint_brush_switch(keymap, "tool_settings.image_paint.active_brush_index");
+
/* face-mask mode */
keymap= WM_keymap_find(keyconf, "Face Mask", 0, 0);
keymap->poll= facemask_paint_poll;
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index 35c059b6d2a..e26b1945e7f 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -125,6 +125,7 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *ev
PointerRNA itemptr;
float pressure = 1;
float center[3] = {0, 0, 0};
+ int flip= event->shift?1:0;
PaintStroke *stroke = op->customdata;
/* XXX: can remove the if statement once all modes have this */
@@ -136,13 +137,15 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *ev
wmTabletData *wmtab= event->customdata;
if(wmtab->Active != EVT_TABLET_NONE)
pressure= wmtab->Pressure;
+ if(wmtab->Active == EVT_TABLET_ERASER)
+ flip = 1;
}
/* Add to stroke */
RNA_collection_add(op->ptr, "stroke", &itemptr);
RNA_float_set_array(&itemptr, "location", center);
RNA_float_set_array(&itemptr, "mouse", mouse);
- RNA_boolean_set(&itemptr, "flip", event->shift);
+ RNA_boolean_set(&itemptr, "flip", flip);
RNA_float_set(&itemptr, "pressure", pressure);
stroke->last_mouse_position[0] = mouse[0];
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index 1e316072dd5..7021d76b1c4 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -154,12 +154,10 @@ static VPaint *new_vpaint(int wpaint)
{
VPaint *vp= MEM_callocN(sizeof(VPaint), "VPaint");
- vp->gamma= vp->mul= 1.0f;
-
- vp->flag= VP_AREA+VP_SOFT+VP_SPRAY;
+ vp->flag= VP_AREA+VP_SPRAY;
if(wpaint)
- vp->flag= VP_AREA+VP_SOFT;
+ vp->flag= VP_AREA;
return vp;
}
@@ -468,7 +466,8 @@ void wpaint_fill(VPaint *wp, Object *ob, float paintweight)
DAG_id_flush_update(&me->id, OB_RECALC_DATA);
}
-
+/* XXX: should be re-implemented as a vertex/weight paint 'colour correct' operator
+
void vpaint_dogamma(Scene *scene)
{
VPaint *vp= scene->toolsettings->vpaint;
@@ -508,6 +507,7 @@ void vpaint_dogamma(Scene *scene)
cp+= 4;
}
}
+ */
static unsigned int mcol_blend(unsigned int col1, unsigned int col2, int fac)
{
@@ -739,65 +739,83 @@ static int sample_backbuf_area(ViewContext *vc, int *indexar, int totface, int x
return tot;
}
-static int calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], float *vert_nor, float *mval)
+static float calc_vp_alpha_dl(VPaint *vp, ViewContext *vc, float vpimat[][3], float *vert_nor, float *mval, float pressure)
{
Brush *brush = paint_brush(&vp->paint);
- float fac, dx, dy;
- int alpha;
+ float fac, fac_2, size, dx, dy;
+ float alpha;
short vertco[2];
- if(vp->flag & VP_SOFT) {
- project_short_noclip(vc->ar, vert_nor, vertco);
- dx= mval[0]-vertco[0];
- dy= mval[1]-vertco[1];
+ project_short_noclip(vc->ar, vert_nor, vertco);
+ dx= mval[0]-vertco[0];
+ dy= mval[1]-vertco[1];
+
+ if (brush->flag & BRUSH_SIZE_PRESSURE)
+ size = pressure * brush->size;
+ else
+ size = brush->size;
+
+ fac_2= dx*dx + dy*dy;
+ if(fac_2 > size*size) return 0.f;
+ fac = sqrtf(fac_2);
+
+ alpha= brush->alpha * brush_curve_strength_clamp(brush, fac, size);
+
+ if (brush->flag & BRUSH_ALPHA_PRESSURE)
+ alpha *= pressure;
- fac= sqrt(dx*dx + dy*dy);
- if(fac > brush->size) return 0;
- if(vp->flag & VP_HARD)
- alpha= 255;
- else
- alpha= 255.0*brush->alpha*(1.0-fac/brush->size);
- }
- else {
- alpha= 255.0*brush->alpha;
- }
-
if(vp->flag & VP_NORMALS) {
float *no= vert_nor+3;
- /* transpose ! */
+ /* transpose ! */
fac= vpimat[2][0]*no[0]+vpimat[2][1]*no[1]+vpimat[2][2]*no[2];
if(fac>0.0) {
dx= vpimat[0][0]*no[0]+vpimat[0][1]*no[1]+vpimat[0][2]*no[2];
dy= vpimat[1][0]*no[0]+vpimat[1][1]*no[1]+vpimat[1][2]*no[2];
- alpha*= fac/sqrt(dx*dx + dy*dy + fac*fac);
+ alpha*= fac/sqrtf(dx*dx + dy*dy + fac*fac);
}
- else return 0;
+ else return 0.f;
}
return alpha;
}
-static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float alpha, float paintval)
+static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float alpha, float paintval, int flip)
{
Brush *brush = paint_brush(&wp->paint);
+ int mode = wp->mode;
if(dw==NULL || uw==NULL) return;
- if(wp->mode==VP_MIX || wp->mode==VP_BLUR)
+ if (flip) {
+ switch(mode) {
+ case VP_MIX:
+ paintval = 1.f - paintval; break;
+ case VP_ADD:
+ mode= VP_SUB; break;
+ case VP_SUB:
+ mode= VP_ADD; break;
+ case VP_LIGHTEN:
+ mode= VP_DARKEN; break;
+ case VP_DARKEN:
+ mode= VP_LIGHTEN; break;
+ }
+ }
+
+ if(mode==VP_MIX || mode==VP_BLUR)
dw->weight = paintval*alpha + dw->weight*(1.0-alpha);
- else if(wp->mode==VP_ADD)
+ else if(mode==VP_ADD)
dw->weight += paintval*alpha;
- else if(wp->mode==VP_SUB)
+ else if(mode==VP_SUB)
dw->weight -= paintval*alpha;
- else if(wp->mode==VP_MUL)
+ else if(mode==VP_MUL)
/* first mul, then blend the fac */
dw->weight = ((1.0-alpha) + alpha*paintval)*dw->weight;
- else if(wp->mode==VP_LIGHTEN) {
+ else if(mode==VP_LIGHTEN) {
if (dw->weight < paintval)
dw->weight = paintval*alpha + dw->weight*(1.0-alpha);
- } else if(wp->mode==VP_DARKEN) {
+ } else if(mode==VP_DARKEN) {
if (dw->weight > paintval)
dw->weight = paintval*alpha + dw->weight*(1.0-alpha);
}
@@ -808,21 +826,21 @@ static void wpaint_blend(VPaint *wp, MDeformWeight *dw, MDeformWeight *uw, float
float testw=0.0f;
alpha= brush->alpha;
- if(wp->mode==VP_MIX || wp->mode==VP_BLUR)
+ if(mode==VP_MIX || mode==VP_BLUR)
testw = paintval*alpha + uw->weight*(1.0-alpha);
- else if(wp->mode==VP_ADD)
+ else if(mode==VP_ADD)
testw = uw->weight + paintval*alpha;
- else if(wp->mode==VP_SUB)
+ else if(mode==VP_SUB)
testw = uw->weight - paintval*alpha;
- else if(wp->mode==VP_MUL)
+ else if(mode==VP_MUL)
/* first mul, then blend the fac */
testw = ((1.0-alpha) + alpha*paintval)*uw->weight;
- else if(wp->mode==VP_LIGHTEN) {
+ else if(mode==VP_LIGHTEN) {
if (uw->weight < paintval)
testw = paintval*alpha + uw->weight*(1.0-alpha);
else
testw = uw->weight;
- } else if(wp->mode==VP_DARKEN) {
+ } else if(mode==VP_DARKEN) {
if (uw->weight > paintval)
testw = paintval*alpha + uw->weight*(1.0-alpha);
else
@@ -1023,7 +1041,7 @@ static void do_weight_paint_auto_normalize(MDeformVert *dvert,
}
static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index,
- int alpha, float paintweight,
+ float alpha, float paintweight, int flip,
int vgroup_mirror, char *validmap)
{
Mesh *me= ob->data;
@@ -1041,7 +1059,7 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index,
if(dw==NULL || uw==NULL)
return;
- wpaint_blend(wp, dw, uw, (float)alpha/255.0, paintweight);
+ wpaint_blend(wp, dw, uw, alpha, paintweight, flip);
do_weight_paint_auto_normalize(me->dvert+index, vgroup, validmap);
if(me->editflag & ME_EDIT_MIRROR_X) { /* x mirror painting */
@@ -1423,8 +1441,9 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
float mat[4][4];
float paintweight= ts->vgroup_weight;
int *indexar= wpd->indexar;
- int totindex, index, alpha, totw;
- float mval[2];
+ int totindex, index, totw, flip;
+ float alpha;
+ float mval[2], pressure;
view3d_operator_needs_opengl(C);
@@ -1433,6 +1452,8 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
wmGetSingleMatrix(mat);
wmLoadMatrix(wpd->vc.rv3d->viewmat);
+ flip = RNA_boolean_get(itemptr, "flip");
+ pressure = RNA_float_get(itemptr, "pressure");
RNA_float_get_array(itemptr, "mouse", mval);
mval[0]-= vc->ar->winrct.xmin;
mval[1]-= vc->ar->winrct.ymin;
@@ -1457,7 +1478,7 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
if(mface->mat_nr!=ob->actcol-1) {
indexar[index]= 0;
}
- }
+ }
}
}
@@ -1519,30 +1540,30 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
MFace *mface= me->mface + (indexar[index]-1);
if((me->dvert+mface->v1)->flag) {
- alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v1, mval);
+ alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v1, mval, pressure);
if(alpha) {
do_weight_paint_vertex(wp, ob, mface->v1,
- alpha, paintweight, wpd->vgroup_mirror,
+ alpha, paintweight, flip, wpd->vgroup_mirror,
wpd->vgroup_validmap);
}
(me->dvert+mface->v1)->flag= 0;
}
if((me->dvert+mface->v2)->flag) {
- alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v2, mval);
+ alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v2, mval, pressure);
if(alpha) {
do_weight_paint_vertex(wp, ob, mface->v2,
- alpha, paintweight, wpd->vgroup_mirror,
+ alpha, paintweight, flip, wpd->vgroup_mirror,
wpd->vgroup_validmap);
}
(me->dvert+mface->v2)->flag= 0;
}
if((me->dvert+mface->v3)->flag) {
- alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v3, mval);
+ alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v3, mval, pressure);
if(alpha) {
do_weight_paint_vertex(wp, ob, mface->v3,
- alpha, paintweight, wpd->vgroup_mirror,
+ alpha, paintweight, flip, wpd->vgroup_mirror,
wpd->vgroup_validmap);
}
(me->dvert+mface->v3)->flag= 0;
@@ -1550,10 +1571,10 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
if((me->dvert+mface->v4)->flag) {
if(mface->v4) {
- alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v4, mval);
+ alpha= calc_vp_alpha_dl(wp, vc, wpd->wpimat, wpd->vertexcosnos+6*mface->v4, mval, pressure);
if(alpha) {
do_weight_paint_vertex(wp, ob, mface->v4,
- alpha, paintweight, wpd->vgroup_mirror,
+ alpha, paintweight, flip, wpd->vgroup_mirror,
wpd->vgroup_validmap);
}
(me->dvert+mface->v4)->flag= 0;
@@ -1802,14 +1823,15 @@ static int vpaint_stroke_test_start(bContext *C, struct wmOperator *op, wmEvent
return 1;
}
-static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index, float mval[2])
+static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index, float mval[2], float pressure, int flip)
{
ViewContext *vc = &vpd->vc;
Mesh *me = get_mesh(ob);
MFace *mface= ((MFace*)me->mface) + index;
unsigned int *mcol= ((unsigned int*)me->mcol) + 4*index;
unsigned int *mcolorig= ((unsigned int*)vp->vpaint_prev) + 4*index;
- int alpha, i;
+ float alpha;
+ int i;
if((vp->flag & VP_COLINDEX && mface->mat_nr!=ob->actcol-1) ||
((me->editflag & ME_EDIT_PAINT_MASK) && !(mface->flag & ME_FACE_SEL)))
@@ -1828,9 +1850,9 @@ static void vpaint_paint_face(VPaint *vp, VPaintData *vpd, Object *ob, int index
}
for(i = 0; i < (mface->v4 ? 4 : 3); ++i) {
- alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, vpd->vertexcosnos+6*(&mface->v1)[i], mval);
+ alpha= calc_vp_alpha_dl(vp, vc, vpd->vpimat, vpd->vertexcosnos+6*(&mface->v1)[i], mval, pressure);
if(alpha)
- vpaint_blend(vp, mcol+i, mcolorig+i, vpd->paintcol, alpha);
+ vpaint_blend(vp, mcol+i, mcolorig+i, vpd->paintcol, (int)(alpha*255.0));
}
}
@@ -1845,10 +1867,12 @@ static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
Mesh *me= ob->data;
float mat[4][4];
int *indexar= vpd->indexar;
- int totindex, index;
- float mval[2];
+ int totindex, index, flip;
+ float pressure, mval[2];
RNA_float_get_array(itemptr, "mouse", mval);
+ flip = RNA_boolean_get(itemptr, "flip");
+ pressure = RNA_float_get(itemptr, "pressure");
view3d_operator_needs_opengl(C);
@@ -1875,7 +1899,7 @@ static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
for(index=0; index<totindex; index++) {
if(indexar[index] && indexar[index]<=me->totface)
- vpaint_paint_face(vp, vpd, ob, indexar[index]-1, mval);
+ vpaint_paint_face(vp, vpd, ob, indexar[index]-1, mval, pressure, flip);
}
swap_m4m4(vc->rv3d->persmat, mat);
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 82893b48af0..7644751d61e 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -69,6 +69,7 @@
#include "BKE_modifier.h"
#include "BKE_multires.h"
#include "BKE_paint.h"
+#include "BKE_report.h"
#include "BKE_texture.h"
#include "BKE_utildefines.h"
#include "BKE_colortools.h"
@@ -78,6 +79,7 @@
#include "WM_api.h"
#include "WM_types.h"
+#include "ED_object.h"
#include "ED_screen.h"
#include "ED_sculpt.h"
#include "ED_space_api.h"
@@ -135,6 +137,7 @@ typedef struct StrokeCache {
float pressure;
float mouse[2];
float bstrength;
+ float tex_mouse[2];
/* The rest is temporary storage that isn't saved as a property */
@@ -662,8 +665,8 @@ static float tex_strength(SculptSession *ss, Brush *br, float *point, const floa
avg= get_texcache_pixel_bilinear(ss, ss->texcache_side*px/sx, ss->texcache_side*py/sy);
}
else if(tex->brush_map_mode == MTEX_MAP_MODE_FIXED) {
- float fx= (point_2d[0] - ss->cache->mouse[0]) / bsize;
- float fy= (point_2d[1] - ss->cache->mouse[1]) / bsize;
+ float fx= (point_2d[0] - ss->cache->tex_mouse[0]) / bsize;
+ float fy= (point_2d[1] - ss->cache->tex_mouse[1]) / bsize;
float angle= atan2(fy, fx) - rot;
float flen= sqrtf(fx*fx + fy*fy);
@@ -1303,13 +1306,7 @@ static void do_brush_action(Sculpt *sd, SculptSession *ss, StrokeCache *cache)
#if 0
/* Copy the modified vertices from mesh to the active key */
- if(keyblock && !ss->multires) {
- float *co= keyblock->data;
- if(co) {
- if(b->sculpt_tool == SCULPT_TOOL_GRAB)
- adata = grab_active_verts->first;
- else
- adata = active_verts.first;
+ if(ss->kb) mesh_to_key(ss->ob->data, ss->kb);
for(; adata; adata= adata->next)
if(adata->Index < keyblock->totelem)
@@ -1422,6 +1419,8 @@ void sculpt_update_mesh_elements(bContext *C, int need_fmap)
DerivedMesh *dm = mesh_get_derived_final(CTX_data_scene(C), ob, 0);
SculptSession *ss = ob->sculpt;
+ ss->ob= ob;
+
if((ss->multires = sculpt_multires_active(ob))) {
ss->totvert = dm->getNumVerts(dm);
ss->totface = dm->getNumFaces(dm);
@@ -1441,6 +1440,15 @@ void sculpt_update_mesh_elements(bContext *C, int need_fmap)
ss->ob = ob;
ss->tree = dm->getPBVH(ob, dm);
ss->fmap = (need_fmap)? dm->getFaceMap(dm): NULL;
+
+ if((ob->shapeflag & OB_SHAPE_LOCK) && !sculpt_multires_active(ob)) {
+ ss->kb= ob_get_keyblock(ob);
+ ss->refkb= ob_get_reference_keyblock(ob);
+ }
+ else {
+ ss->kb= NULL;
+ ss->refkb= NULL;
+ }
}
static int sculpt_mode_poll(bContext *C)
@@ -1564,8 +1572,8 @@ static void sculpt_update_cache_invariants(Sculpt *sd, SculptSession *ss, bConte
RNA_float_get_array(op->ptr, "clip_tolerance", cache->clip_tolerance);
RNA_float_get_array(op->ptr, "initial_mouse", cache->initial_mouse);
- cache->mouse[0] = cache->initial_mouse[0];
- cache->mouse[1] = cache->initial_mouse[1];
+ copy_v2_v2(cache->mouse, cache->initial_mouse);
+ copy_v2_v2(cache->tex_mouse, cache->initial_mouse);
/* Truly temporary data that isn't stored in properties */
@@ -1640,6 +1648,9 @@ static void sculpt_update_cache_variants(Sculpt *sd, SculptSession *ss, struct P
else
cache->radius = cache->initial_radius;
+ if(!(brush->flag & BRUSH_ANCHORED))
+ copy_v2_v2(cache->tex_mouse, cache->mouse);
+
if(brush->flag & BRUSH_ANCHORED) {
dx = cache->mouse[0] - cache->initial_mouse[0];
dy = cache->mouse[1] - cache->initial_mouse[1];
@@ -1774,12 +1785,18 @@ static void sculpt_brush_stroke_init_properties(bContext *C, wmOperator *op, wmE
RNA_float_set_array(op->ptr, "initial_mouse", mouse);
}
-static void sculpt_brush_stroke_init(bContext *C)
+static int sculpt_brush_stroke_init(bContext *C, ReportList *reports)
{
+ Object *ob= CTX_data_active_object(C);
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
SculptSession *ss = CTX_data_active_object(C)->sculpt;
Brush *brush = paint_brush(&sd->paint);
+ if(ob_get_key(ob) && !(ob->shapeflag & OB_SHAPE_LOCK)) {
+ BKE_report(reports, RPT_ERROR, "Shape key sculpting requires a locked shape.");
+ return 0;
+ }
+
view3d_operator_needs_opengl(C);
/* TODO: Shouldn't really have to do this at the start of every
@@ -1788,6 +1805,10 @@ static void sculpt_brush_stroke_init(bContext *C)
sculpt_update_tex(sd, ss);
sculpt_update_mesh_elements(C, brush->sculpt_tool == SCULPT_TOOL_SMOOTH);
+
+ if(ss->kb) key_to_mesh(ss->kb, ss->ob->data);
+
+ return 1;
}
static void sculpt_restore_mesh(Sculpt *sd, SculptSession *ss)
@@ -1899,7 +1920,8 @@ static void sculpt_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
static void sculpt_stroke_done(bContext *C, struct PaintStroke *stroke)
{
- SculptSession *ss = CTX_data_active_object(C)->sculpt;
+ Object *ob= CTX_data_active_object(C);
+ SculptSession *ss = ob->sculpt;
/* Finished */
if(ss->cache) {
@@ -1914,7 +1936,8 @@ static void sculpt_stroke_done(bContext *C, struct PaintStroke *stroke)
static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
- sculpt_brush_stroke_init(C);
+ if(!sculpt_brush_stroke_init(C, op->reports))
+ return OPERATOR_CANCELLED;
op->customdata = paint_stroke_new(C, sculpt_stroke_get_location,
sculpt_stroke_test_start,
@@ -1934,11 +1957,12 @@ static int sculpt_brush_stroke_exec(bContext *C, wmOperator *op)
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
SculptSession *ss = CTX_data_active_object(C)->sculpt;
+ if(!sculpt_brush_stroke_init(C, op->reports))
+ return OPERATOR_CANCELLED;
+
op->customdata = paint_stroke_new(C, sculpt_stroke_get_location, sculpt_stroke_test_start,
sculpt_stroke_update_step, sculpt_stroke_done);
- sculpt_brush_stroke_init(C);
-
sculpt_update_cache_invariants(sd, ss, C, op);
paint_stroke_exec(C, op);
@@ -2030,7 +2054,8 @@ static int sculpt_toggle_mode(bContext *C, wmOperator *op)
MultiresModifierData *mmd = sculpt_multires_active(ob);
if(ob->mode & OB_MODE_SCULPT) {
- multires_force_update(ob);
+ if(sculpt_multires_active(ob))
+ multires_force_update(ob);
if(mmd && mmd->sculptlvl != mmd->lvl)
DAG_id_flush_update(&ob->id, OB_RECALC_DATA);