Move average stroke from sculpt session to unified paint settings so it
authorAntony Riakiotakis <kalast@gmail.com>
Mon, 29 Dec 2014 10:35:22 +0000 (11:35 +0100)
committerAntony Riakiotakis <kalast@gmail.com>
Mon, 29 Dec 2014 10:35:43 +0000 (11:35 +0100)
can be reused by other paint systems too.

source/blender/blenkernel/BKE_paint.h
source/blender/blenkernel/intern/paint.c
source/blender/editors/include/ED_sculpt.h
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/sculpt_paint/sculpt_uv.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/makesdna/DNA_scene_types.h

index ff1305b918261019da09e49b7e1bafde34870083..9ad99f726ffe39628ef049e5c636a4f7c9c4b061 100644 (file)
@@ -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);
index 5f3b9f04bf22ae1e51864b60274f5e4032a0bed3..2cd779a120c86c71b4281d51271c60642d5ea5aa 100644 (file)
@@ -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)
index 60c7dc8b8c7f24fa65b1b5d459391a99121cf247..d3b1a824104634f700d87834b8e8fa5bee9b7d2c 100644 (file)
@@ -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__ */
index a13a2f2773f47a6231d7a6bf690e432c85dc5f4d..82d71304cc5467e32667a130dfe053a6d6e74a15 100644 (file)
@@ -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();
index fe38fd4806c602b054ec0e118909813e55119a5e..644d394f194153718dffa67b21ce307956015928 100644 (file)
@@ -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 */
index 50587c87bea5a75600b262612479b8f1a36d586b..a6e1a198d61f91d44bd9be902f006bc84f6617cc 100644 (file)
@@ -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);
        }
index 7122b37446213183cb911e9b4cd5d436ccd6767e..92a9112b6e5dbbb6bb45b3684999ed1bca9e1be7 100644 (file)
@@ -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);
index 2f4502eddcd959f097253c134a05dbb3b1997981..af9b0ed0593e65a9a72cd61c47e8c6bcdef9c6f8 100644 (file)
@@ -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 */
index 5f21e5473e4441f4b94260cf2076797b02c0afc5..49f8b3cd4d03612c741d912f41257c88a3311bdb 100644 (file)
@@ -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;