Commit: 427fbc879e18608cc24e448b37e39c8413df988a
Author: Antony Riakiotakis
Date:   Mon Dec 29 11:35:22 2014 +0100
Branches: master
https://developer.blender.org/rB427fbc879e18608cc24e448b37e39c8413df988a

Move average stroke from sculpt session to unified paint settings so it
can be reused by other paint systems too.

===================================================================

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

===================================================================

diff --git a/source/blender/blenkernel/BKE_paint.h 
b/source/blender/blenkernel/BKE_paint.h
index ff1305b..9ad99f7 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 5f3b9f0..2cd779a 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 60c7dc8..d3b1a82 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 a13a2f2..82d7130 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 fe38fd4..644d394 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 50587c8..a6e1a19 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->avera

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to