diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index 5e23a144408..5f241f0d9cc 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -116,7 +116,7 @@ static void make_snap(Snapshot *snap, Brush *brush, ViewContext *vc) snap->winy = vc->ar->winy; } -static int load_tex(Sculpt *sd, Brush *br, ViewContext *vc) +static int load_tex(Brush *br, ViewContext *vc) { static GLuint overlay_texture = 0; static int init = 0; @@ -130,10 +130,6 @@ static int load_tex(Sculpt *sd, Brush *br, ViewContext *vc) int size; int j; int refresh; - -#ifndef _OPENMP - (void)sd; /* quied unused warning */ -#endif if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED && !br->mtex.tex) return 0; @@ -186,7 +182,7 @@ static int load_tex(Sculpt *sd, Brush *br, ViewContext *vc) buffer = MEM_mallocN(sizeof(GLubyte) * size * size, "load_tex"); - #pragma omp parallel for schedule(static) if (sd->flags & SCULPT_USE_OPENMP) + #pragma omp parallel for schedule(static) for (j = 0; j < size; j++) { int i; float y; @@ -376,7 +372,7 @@ static int sculpt_get_brush_geometry(bContext *C, ViewContext *vc, /* Draw an overlay that shows what effect the brush's texture will * have on brush strength */ /* TODO: sculpt only for now */ -static void paint_draw_alpha_overlay(Sculpt *sd, Brush *brush, +static void paint_draw_alpha_overlay(UnifiedPaintSettings *ups, Brush *brush, ViewContext *vc, int x, int y) { rctf quad; @@ -401,7 +397,7 @@ static void paint_draw_alpha_overlay(Sculpt *sd, Brush *brush, GL_VIEWPORT_BIT | GL_TEXTURE_BIT); - if (load_tex(sd, brush, vc)) { + if (load_tex(brush, vc)) { glEnable(GL_BLEND); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); @@ -416,24 +412,24 @@ static void paint_draw_alpha_overlay(Sculpt *sd, Brush *brush, /* brush rotation */ glTranslatef(0.5, 0.5, 0); glRotatef((double)RAD2DEGF((brush->flag & BRUSH_RAKE) ? - sd->last_angle : sd->special_rotation), + ups->last_angle : ups->special_rotation), 0.0, 0.0, 1.0); glTranslatef(-0.5f, -0.5f, 0); /* scale based on tablet pressure */ - if (sd->draw_pressure && BKE_brush_use_size_pressure(vc->scene, brush)) { + if (ups->draw_pressure && BKE_brush_use_size_pressure(vc->scene, brush)) { glTranslatef(0.5f, 0.5f, 0); - glScalef(1.0f / sd->pressure_value, 1.0f / sd->pressure_value, 1); + glScalef(1.0f / ups->pressure_value, 1.0f / ups->pressure_value, 1); glTranslatef(-0.5f, -0.5f, 0); } - if (sd->draw_anchored) { - const float *aim = sd->anchored_initial_mouse; + if (ups->draw_anchored) { + const float *aim = ups->anchored_initial_mouse; const rcti *win = &vc->ar->winrct; - quad.xmin = aim[0] - sd->anchored_size - win->xmin; - quad.ymin = aim[1] - sd->anchored_size - win->ymin; - quad.xmax = aim[0] + sd->anchored_size - win->xmin; - quad.ymax = aim[1] + sd->anchored_size - win->ymin; + quad.xmin = aim[0] - ups->anchored_size - win->xmin; + quad.ymin = aim[1] - ups->anchored_size - win->ymin; + quad.xmax = aim[0] + ups->anchored_size - win->xmin; + quad.ymax = aim[1] + ups->anchored_size - win->ymin; } else { const int radius = BKE_brush_size_get(vc->scene, brush); @@ -476,7 +472,7 @@ static void paint_draw_alpha_overlay(Sculpt *sd, Brush *brush, /* Special actions taken when paint cursor goes over mesh */ /* TODO: sculpt only for now */ -static void paint_cursor_on_hit(Sculpt *sd, Brush *brush, ViewContext *vc, +static void paint_cursor_on_hit(UnifiedPaintSettings *ups, Brush *brush, ViewContext *vc, const float location[3]) { float unprojected_radius, projected_radius; @@ -484,8 +480,8 @@ static void paint_cursor_on_hit(Sculpt *sd, Brush *brush, ViewContext *vc, /* update the brush's cached 3D radius */ if (!BKE_brush_use_locked_size(vc->scene, brush)) { /* get 2D brush radius */ - if (sd->draw_anchored) - projected_radius = sd->anchored_size; + if (ups->draw_anchored) + projected_radius = ups->anchored_size; else { if (brush->flag & BRUSH_ANCHORED) projected_radius = 8; @@ -498,8 +494,8 @@ static void paint_cursor_on_hit(Sculpt *sd, Brush *brush, ViewContext *vc, projected_radius); /* scale 3D brush radius by pressure */ - if (sd->draw_pressure && BKE_brush_use_size_pressure(vc->scene, brush)) - unprojected_radius *= sd->pressure_value; + if (ups->draw_pressure && BKE_brush_use_size_pressure(vc->scene, brush)) + unprojected_radius *= ups->pressure_value; /* set cached value in either Brush or UnifiedPaintSettings */ BKE_brush_unprojected_radius_set(vc->scene, brush, unprojected_radius); @@ -509,6 +505,7 @@ static void paint_cursor_on_hit(Sculpt *sd, Brush *brush, ViewContext *vc, static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) { Scene *scene = CTX_data_scene(C); + UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; Paint *paint = paint_get_active_from_context(C); Brush *brush = paint_brush(paint); ViewContext vc; @@ -534,7 +531,6 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) /* TODO: as sculpt and other paint modes are unified, this * special mode of drawing will go away */ if (vc.obact->sculpt) { - Sculpt *sd = CTX_data_tool_settings(C)->sculpt; float location[3]; int pixel_radius, hit; @@ -547,14 +543,14 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) const float v = 1 - u; const float r = 20; - const float dx = sd->last_x - x; - const float dy = sd->last_y - y; + const float dx = ups->last_x - x; + const float dy = ups->last_y - y; if (dx * dx + dy * dy >= r * r) { - sd->last_angle = atan2(dx, dy); + ups->last_angle = atan2(dx, dy); - sd->last_x = u * sd->last_x + v * x; - sd->last_y = u * sd->last_y + v * y; + ups->last_x = u * ups->last_x + v * x; + ups->last_y = u * ups->last_y + v * y; } } @@ -562,7 +558,7 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) hit = sculpt_get_brush_geometry(C, &vc, x, y, &pixel_radius, location); /* draw overlay */ - paint_draw_alpha_overlay(sd, brush, &vc, x, y); + paint_draw_alpha_overlay(ups, brush, &vc, x, y); if (BKE_brush_use_locked_size(scene, brush)) BKE_brush_size_set(scene, brush, pixel_radius); @@ -581,12 +577,12 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused)) /* only do if brush is over the mesh */ if (hit) - paint_cursor_on_hit(sd, brush, &vc, location); + paint_cursor_on_hit(ups, brush, &vc, location); - if (sd->draw_anchored) { - final_radius = sd->anchored_size; - translation[0] = sd->anchored_initial_mouse[0] - vc.ar->winrct.xmin; - translation[1] = sd->anchored_initial_mouse[1] - vc.ar->winrct.ymin; + if (ups->draw_anchored) { + final_radius = ups->anchored_size; + translation[0] = ups->anchored_initial_mouse[0] - vc.ar->winrct.xmin; + translation[1] = ups->anchored_initial_mouse[1] - vc.ar->winrct.ymin; } } diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 2dc4176dde3..4ddae3f82d3 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -3654,6 +3654,7 @@ static void sculpt_omp_done(SculptSession *ss) static void sculpt_update_cache_invariants(bContext *C, Sculpt *sd, SculptSession *ss, wmOperator *op, const float mouse[2]) { StrokeCache *cache = MEM_callocN(sizeof(StrokeCache), "stroke cache"); + UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings; Brush *brush = paint_brush(&sd->paint); ViewContext *vc = paint_stroke_view_context(op->customdata); Object *ob = CTX_data_active_object(C); @@ -3762,7 +3763,7 @@ static void sculpt_update_cache_invariants(bContext *C, Sculpt *sd, SculptSessio } } - cache->special_rotation = (brush->flag & BRUSH_RAKE) ? sd->last_angle : 0; + cache->special_rotation = (brush->flag & BRUSH_RAKE) ? ups->last_angle : 0; cache->first_time = 1; @@ -3771,7 +3772,7 @@ static void sculpt_update_cache_invariants(bContext *C, Sculpt *sd, SculptSessio sculpt_omp_start(sd, ss); } -static void sculpt_update_brush_delta(Sculpt *sd, Object *ob, Brush *brush) +static void sculpt_update_brush_delta(UnifiedPaintSettings *ups, Object *ob, Brush *brush) { SculptSession *ss = ob->sculpt; StrokeCache *cache = ss->cache; @@ -3836,17 +3837,17 @@ static void sculpt_update_brush_delta(Sculpt *sd, Object *ob, Brush *brush) copy_v3_v3(cache->old_grab_location, grab_location); if (tool == SCULPT_TOOL_GRAB) - copy_v3_v3(sd->anchored_location, cache->true_location); + copy_v3_v3(ups->anchored_location, cache->true_location); else if (tool == SCULPT_TOOL_THUMB) - copy_v3_v3(sd->anchored_location, cache->orig_grab_location); + copy_v3_v3(ups->anchored_location, cache->orig_grab_location); if (ELEM(tool, SCULPT_TOOL_GRAB, SCULPT_TOOL_THUMB)) { /* location stays the same for finding vertices in brush radius */ copy_v3_v3(cache->true_location, cache->orig_grab_location); - sd->draw_anchored = 1; - copy_v2_v2(sd->anchored_initial_mouse, cache->initial_mouse); - sd->anchored_size = cache->pixel_radius; + ups->draw_anchored = 1; + copy_v2_v2(ups->anchored_initial_mouse, cache->initial_mouse); + ups->anchored_size = cache->pixel_radius; } } } @@ -3857,6 +3858,7 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob, PointerRNA *ptr) { Scene *scene = CTX_data_scene(C); + UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; SculptSession *ss = ob->sculpt; StrokeCache *cache = ss->cache; Brush *brush = paint_brush(&sd->paint); @@ -3885,8 +3887,8 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob, /* Truly temporary data that isn't stored in properties */ - sd->draw_pressure = 1; - sd->pressure_value = cache->pressure; + ups->draw_pressure = 1; + ups->pressure_value = cache->pressure; cache->previous_pixel_radius = cache->pixel_radius; cache->pixel_radius = BKE_brush_size_get(scene, brush); @@ -3932,7 +3934,7 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob, const float dx = cache->mouse[0] - cache->initial_mouse[0]; const float dy = cache->mouse[1] - cache->initial_mouse[1]; - sd->anchored_size = cache->pixel_radius = sqrt(dx * dx + dy * dy); + ups->anchored_size = cache->pixel_radius = sqrt(dx * dx + dy * dy); cache->special_rotation = atan2(dx, dy) + M_PI; @@ -3944,27 +3946,27 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob, halfway[1] = dy * 0.5f + cache->initial_mouse[1]; if (sculpt_stroke_get_location(C, out, halfway)) { - copy_v3_v3(sd->anchored_location, out); - copy_v2_v2(sd->anchored_initial_mouse, halfway); + copy_v3_v3(ups->anchored_location, out); + copy_v2_v2(ups->anchored_initial_mouse, halfway); copy_v2_v2(cache->tex_mouse, halfway); - copy_v3_v3(cache->true_location, sd->anchored_location); - sd->anchored_size /= 2.0f; + copy_v3_v3(cache->true_location, ups->anchored_location); + ups->anchored_size /= 2.0f; cache->pixel_radius /= 2.0f; hit = 1; } } if (!hit) - copy_v2_v2(sd->anchored_initial_mouse, cache->initial_mouse); + copy_v2_v2(ups->anchored_initial_mouse, cache->initial_mouse); cache->radius = paint_calc_object_space_radius(paint_stroke_view_context(stroke), cache->true_location, cache->pixel_radius); cache->radius_squared = cache->radius * cache->radius; - copy_v3_v3(sd->anchored_location, cache->true_location); + copy_v3_v3(ups->anchored_location, cache->true_location); - sd->draw_anchored = 1; + ups->draw_anchored = 1; } else if (brush->flag & BRUSH_RAKE) { const float u = 0.5f; @@ -3985,7 +3987,7 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob, } } - sculpt_update_brush_delta(sd, ob, brush); + sculpt_update_brush_delta(ups, ob, brush); if (brush->sculpt_tool == SCULPT_TOOL_ROTATE) { const float dx = cache->mouse[0] - cache->initial_mouse[0]; @@ -3993,13 +3995,13 @@ static void sculpt_update_cache_variants(bContext *C, Sculpt *sd, Object *ob, cache->vertex_rotation = -atan2f(dx, dy) * cache->bstrength; - sd->draw_anchored = 1; - copy_v2_v2(sd->anchored_initial_mouse, cache->initial_mouse); - copy_v3_v3(sd->anchored_location, cache->true_location); - sd->anchored_size = cache->pixel_radius; + ups->draw_anchored = 1; + copy_v2_v2(ups->anchored_initial_mouse, cache->initial_mouse); + copy_v3_v3(ups->anchored_location, cache->true_location); + ups->anchored_size = cache->pixel_radius; } - sd->special_rotation = cache->special_rotation; + ups->special_rotation = cache->special_rotation; } /* Returns true iff any of the smoothing modes are active (currently @@ -4289,6 +4291,7 @@ static void sculpt_brush_exit_tex(Sculpt *sd) static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(stroke)) { + UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings; Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; Sculpt *sd = CTX_data_tool_settings(C)->sculpt; @@ -4296,9 +4299,9 @@ static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(str sculpt_omp_done(ss); /* reset values used to draw brush after completing the stroke */ - sd->draw_anchored = 0; - sd->draw_pressure = 0; - sd->special_rotation = 0; + ups->draw_anchored = 0; + ups->draw_pressure = 0; + ups->special_rotation = 0; /* Finished */ if (ss->cache) { diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index c8175461c1d..b093239c714 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -814,29 +814,11 @@ typedef struct Sculpt { //char tablet_size, tablet_strength; XXX not used? int radial_symm[3]; - // all this below is used to communicate with the cursor drawing routine - - /* record movement of mouse so that rake can start at an intuitive angle */ - float last_x, last_y; - float last_angle; - - int draw_anchored; - int anchored_size; - float anchored_location[3]; - float anchored_initial_mouse[2]; - - int draw_pressure; - float pressure_value; - - float special_rotation; - /* Maximum edge length for dynamic topology sculpting (in pixels) */ int detail_size; /* Direction used for SCULPT_OT_symmetrize operator */ int symmetrize_direction; - - int pad; } Sculpt; typedef struct UvSculpt { @@ -899,7 +881,24 @@ typedef struct UnifiedPaintSettings { /* user preferences for sculpt and paint */ int flag; - int pad; + + /* rake rotation */ + + /* record movement of mouse so that rake can start at an intuitive angle */ + float last_x, last_y; + float last_angle; + + float special_rotation; + + // all this below is used to communicate with the cursor drawing routine + int draw_anchored; + int anchored_size; + float anchored_location[3]; + float anchored_initial_mouse[2]; + + /* drawing pressure */ + int draw_pressure; + float pressure_value; } UnifiedPaintSettings; typedef enum {