From 427fbc879e18608cc24e448b37e39c8413df988a Mon Sep 17 00:00:00 2001 From: Antony Riakiotakis Date: Mon, 29 Dec 2014 11:35:22 +0100 Subject: Move average stroke from sculpt session to unified paint settings so it can be reused by other paint systems too. --- source/blender/blenkernel/BKE_paint.h | 10 ++--- source/blender/blenkernel/intern/paint.c | 17 +++++++- source/blender/editors/include/ED_sculpt.h | 2 +- source/blender/editors/sculpt_paint/paint_image.c | 4 +- source/blender/editors/sculpt_paint/paint_vertex.c | 4 +- source/blender/editors/sculpt_paint/sculpt.c | 45 ++++++++-------------- source/blender/editors/sculpt_paint/sculpt_uv.c | 2 +- source/blender/editors/space_view3d/view3d_edit.c | 4 +- source/blender/makesdna/DNA_scene_types.h | 7 +++- 9 files changed, 49 insertions(+), 46 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index ff1305b9182..9ad99f726ff 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -109,7 +109,7 @@ void BKE_palette_cleanup(struct Palette *palette); struct PaintCurve *BKE_paint_curve_add(struct Main *bmain, const char *name); void BKE_paint_curve_free(struct PaintCurve *pc); -void BKE_paint_init(struct Paint *p, const char col[3]); +void BKE_paint_init(struct UnifiedPaintSettings *ups, struct Paint *p, const char col[3]); void BKE_paint_free(struct Paint *p); void BKE_paint_copy(struct Paint *src, struct Paint *tar); @@ -145,6 +145,8 @@ float paint_grid_paint_mask(const struct GridPaintMask *gpm, unsigned level, /* stroke related */ void paint_calculate_rake_rotation(struct UnifiedPaintSettings *ups, struct Brush *brush, const float mouse_pos[2]); +void BKE_paint_stroke_get_average(struct Scene *scene, struct Object *ob, float stroke[3]); + /* Session data (mode-specific) */ typedef struct SculptSession { @@ -191,12 +193,6 @@ typedef struct SculptSession { struct SculptStroke *stroke; struct StrokeCache *cache; - - /* last paint/sculpt stroke location */ - bool last_stroke_valid; - - float average_stroke_accum[3]; - int average_stroke_counter; } SculptSession; void BKE_free_sculptsession(struct Object *ob); diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 5f3b9f04bf2..2cd779a120c 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -395,7 +395,7 @@ bool BKE_paint_select_elem_test(Object *ob) BKE_paint_select_face_test(ob)); } -void BKE_paint_init(Paint *p, const char col[3]) +void BKE_paint_init(UnifiedPaintSettings *ups, Paint *p, const char col[3]) { Brush *brush; @@ -407,6 +407,9 @@ void BKE_paint_init(Paint *p, const char col[3]) memcpy(p->paint_cursor_col, col, 3); p->paint_cursor_col[3] = 128; + ups->last_stroke_valid = false; + zero_v3(ups->average_stroke_accum); + ups->average_stroke_counter = 0; } void BKE_paint_free(Paint *paint) @@ -426,6 +429,18 @@ void BKE_paint_copy(Paint *src, Paint *tar) id_us_plus((ID *)tar->palette); } +void BKE_paint_stroke_get_average(Scene *scene, Object *ob, float stroke[3]) +{ + UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; + if (ups->last_stroke_valid && ups->average_stroke_counter > 0) { + float fac = 1.0f / ups->average_stroke_counter; + mul_v3_v3fl(stroke, ups->average_stroke_accum, fac); + } + else { + copy_v3_v3(stroke, ob->obmat[3]); + } +} + /* returns non-zero if any of the face's vertices * are hidden, zero otherwise */ bool paint_is_face_hidden(const MFace *f, const MVert *mvert) diff --git a/source/blender/editors/include/ED_sculpt.h b/source/blender/editors/include/ED_sculpt.h index 60c7dc8b8c7..d3b1a824104 100644 --- a/source/blender/editors/include/ED_sculpt.h +++ b/source/blender/editors/include/ED_sculpt.h @@ -34,6 +34,7 @@ struct ARegion; struct bContext; struct Object; struct RegionView3D; +struct Scene; struct ViewContext; struct rcti; @@ -41,7 +42,6 @@ struct rcti; void ED_operatortypes_sculpt(void); void ED_sculpt_redraw_planes_get(float planes[4][4], struct ARegion *ar, struct RegionView3D *rv3d, struct Object *ob); -void ED_sculpt_stroke_get_average(struct Object *ob, float stroke[3]); int ED_sculpt_mask_box_select(struct bContext *C, struct ViewContext *vc, const struct rcti *rect, bool select, bool extend); #endif /* __ED_SCULPT_H__ */ diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index a13a2f2773f..82d71304cc5 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -1056,7 +1056,7 @@ void ED_space_image_paint_update(wmWindowManager *wm, ToolSettings *settings) enabled = true; if (enabled) { - BKE_paint_init(&imapaint->paint, PAINT_CURSOR_TEXTURE_PAINT); + BKE_paint_init(&settings->unified_paint_settings, &imapaint->paint, PAINT_CURSOR_TEXTURE_PAINT); paint_cursor_start_explicit(&imapaint->paint, wm, image_paint_poll); } @@ -1413,7 +1413,7 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) ob->mode |= mode_flag; - BKE_paint_init(&scene->toolsettings->imapaint.paint, PAINT_CURSOR_TEXTURE_PAINT); + BKE_paint_init(&scene->toolsettings->unified_paint_settings, &imapaint->paint, PAINT_CURSOR_TEXTURE_PAINT); if (U.glreslimit != 0) GPU_free_images(); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index fe38fd4806c..644d394f194 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -2072,7 +2072,7 @@ static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op) paint_cursor_start(C, weight_paint_poll); - BKE_paint_init(&wp->paint, PAINT_CURSOR_WEIGHT_PAINT); + BKE_paint_init(&scene->toolsettings->unified_paint_settings, &wp->paint, PAINT_CURSOR_WEIGHT_PAINT); /* weight paint specific */ ED_mesh_mirror_spatial_table(ob, NULL, NULL, 's'); @@ -2680,7 +2680,7 @@ static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op) paint_cursor_start(C, vertex_paint_poll); - BKE_paint_init(&vp->paint, PAINT_CURSOR_VERTEX_PAINT); + BKE_paint_init(&scene->toolsettings->unified_paint_settings, &vp->paint, PAINT_CURSOR_VERTEX_PAINT); } /* update modifier stack for mapping requirements */ diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 50587c87bea..a6e1a198d61 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -115,17 +115,6 @@ static int system_physical_thread_count(void) } #endif /* __APPLE__ */ -void ED_sculpt_stroke_get_average(Object *ob, float stroke[3]) -{ - if (ob->sculpt->last_stroke_valid && ob->sculpt->average_stroke_counter > 0) { - float fac = 1.0f / ob->sculpt->average_stroke_counter; - mul_v3_v3fl(stroke, ob->sculpt->average_stroke_accum, fac); - } - else { - copy_v3_v3(stroke, ob->obmat[3]); - } -} - /* Check if there are any active modifiers in stack (used for flushing updates at enter/exit sculpt mode) */ static bool sculpt_has_active_modifiers(Scene *scene, Object *ob) { @@ -2940,7 +2929,7 @@ void sculpt_vertcos_to_key(Object *ob, KeyBlock *kb, float (*vertCos)[3]) /* Note: we do the topology update before any brush actions to avoid * issues with the proxies. The size of the proxy can't change, so * topology must be updated first. */ -static void sculpt_topology_update(Sculpt *sd, Object *ob, Brush *brush) +static void sculpt_topology_update(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *UNUSED(ups)) { SculptSession *ss = ob->sculpt; SculptSearchSphereData data; @@ -3001,13 +2990,10 @@ static void sculpt_topology_update(Sculpt *sd, Object *ob, Brush *brush) /* update average stroke position */ copy_v3_v3(location, ss->cache->true_location); mul_m4_v3(ob->obmat, location); - - add_v3_v3(ob->sculpt->average_stroke_accum, location); - ob->sculpt->average_stroke_counter++; } } -static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush) +static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups) { SculptSession *ss = ob->sculpt; SculptSearchSphereData data; @@ -3121,8 +3107,8 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush) copy_v3_v3(location, ss->cache->true_location); mul_m4_v3(ob->obmat, location); - add_v3_v3(ob->sculpt->average_stroke_accum, location); - ob->sculpt->average_stroke_counter++; + add_v3_v3(ups->average_stroke_accum, location); + ups->average_stroke_counter++; } } @@ -3331,9 +3317,9 @@ static void calc_brushdata_symm(Sculpt *sd, StrokeCache *cache, const char symm, } } -typedef void (*BrushActionFunc)(Sculpt *sd, Object *ob, Brush *brush); +typedef void (*BrushActionFunc)(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups); -static void do_radial_symmetry(Sculpt *sd, Object *ob, Brush *brush, +static void do_radial_symmetry(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSettings *ups, BrushActionFunc action, const char symm, const int axis, const float feather) @@ -3345,7 +3331,7 @@ static void do_radial_symmetry(Sculpt *sd, Object *ob, Brush *brush, const float angle = 2 * M_PI * i / sd->radial_symm[axis - 'X']; ss->cache->radial_symmetry_pass = i; calc_brushdata_symm(sd, ss->cache, symm, axis, angle, feather); - action(sd, ob, brush); + action(sd, ob, brush, ups); } } @@ -3383,11 +3369,11 @@ static void do_symmetrical_brush_actions(Sculpt *sd, Object *ob, cache->radial_symmetry_pass = 0; calc_brushdata_symm(sd, cache, i, 0, 0, feather); - action(sd, ob, brush); + action(sd, ob, brush, ups); - do_radial_symmetry(sd, ob, brush, action, i, 'X', feather); - do_radial_symmetry(sd, ob, brush, action, i, 'Y', feather); - do_radial_symmetry(sd, ob, brush, action, i, 'Z', feather); + do_radial_symmetry(sd, ob, brush, ups, action, i, 'X', feather); + do_radial_symmetry(sd, ob, brush, ups, action, i, 'Y', feather); + do_radial_symmetry(sd, ob, brush, ups, action, i, 'Z', feather); } } } @@ -4121,6 +4107,7 @@ static void sculpt_brush_init_tex(const Scene *scene, Sculpt *sd, SculptSession static bool sculpt_brush_stroke_init(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); + UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; Object *ob = CTX_data_active_object(C); Sculpt *sd = CTX_data_tool_settings(C)->sculpt; SculptSession *ss = CTX_data_active_object(C)->sculpt; @@ -4139,8 +4126,8 @@ static bool sculpt_brush_stroke_init(bContext *C, wmOperator *op) is_smooth = sculpt_any_smooth_mode(brush, NULL, mode); BKE_sculpt_update_mesh_elements(scene, sd, ob, is_smooth, need_mask); - zero_v3(ob->sculpt->average_stroke_accum); - ob->sculpt->average_stroke_counter = 0; + zero_v3(ups->average_stroke_accum); + ups->average_stroke_counter = 0; return 1; } @@ -4349,7 +4336,7 @@ static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(str } /* update last stroke position */ - ob->sculpt->last_stroke_valid = 1; + ups->last_stroke_valid = true; sculpt_cache_free(ss->cache); ss->cache = NULL; @@ -4967,7 +4954,7 @@ static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op) "Object has negative scale, sculpting may be unpredictable"); } - BKE_paint_init(&ts->sculpt->paint, PAINT_CURSOR_SCULPT); + BKE_paint_init(&ts->unified_paint_settings, &ts->sculpt->paint, PAINT_CURSOR_SCULPT); paint_cursor_start(C, sculpt_poll_view3d); } diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c index 7122b374462..92a9112b6e5 100644 --- a/source/blender/editors/sculpt_paint/sculpt_uv.c +++ b/source/blender/editors/sculpt_paint/sculpt_uv.c @@ -236,7 +236,7 @@ void ED_space_image_uv_sculpt_update(wmWindowManager *wm, ToolSettings *settings settings->uvsculpt->paint.flags |= PAINT_SHOW_BRUSH; } - BKE_paint_init(&settings->uvsculpt->paint, PAINT_CURSOR_SCULPT); + BKE_paint_init(&settings->unified_paint_settings, &settings->uvsculpt->paint, PAINT_CURSOR_SCULPT); settings->uvsculpt->paint.paint_cursor = WM_paint_cursor_activate(wm, uv_sculpt_brush_poll, brush_drawcursor_uvsculpt, NULL); diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 2f4502eddcd..af9b0ed0593 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -627,7 +627,7 @@ static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3]) */ if (ob->mode & OB_MODE_SCULPT) { float stroke[3]; - ED_sculpt_stroke_get_average(ob, stroke); + BKE_paint_stroke_get_average(scene, ob, stroke); copy_v3_v3(lastofs, stroke); } else { @@ -2976,7 +2976,7 @@ static int viewselected_exec(bContext *C, wmOperator *op) ok = PE_minmax(scene, min, max); } else if (ob && (ob->mode & OB_MODE_SCULPT)) { - ED_sculpt_stroke_get_average(ob, min); + BKE_paint_stroke_get_average(scene, ob, min); copy_v3_v3(max, min); ok = true; ok_dist = 0; /* don't zoom */ diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 5f21e5473e4..49f8b3cd4d0 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -985,7 +985,12 @@ typedef struct UnifiedPaintSettings { /* record movement of mouse so that rake can start at an intuitive angle */ float last_rake[2]; - float last_rake_angle, pad; + float last_rake_angle; + + int last_stroke_valid; + float average_stroke_accum[3]; + int average_stroke_counter; + float brush_rotation; float brush_rotation_sec; -- cgit v1.2.3