== Sculpt ==
authorNicholas Bishop <nicholasbishop@gmail.com>
Sat, 9 Jan 2010 17:15:02 +0000 (17:15 +0000)
committerNicholas Bishop <nicholasbishop@gmail.com>
Sat, 9 Jan 2010 17:15:02 +0000 (17:15 +0000)
* Added a new property to sculpting, ignore_background_click. If this is on, clicks that don't hit the mesh are passed through, so you can set up the keymap to do ZBrush-like rotation with the tablet.

source/blender/editors/sculpt_paint/paint_intern.h
source/blender/editors/sculpt_paint/paint_stroke.c
source/blender/editors/sculpt_paint/sculpt.c

index 108be50267d125f9787763954779b66b4f6d919e..6bb5f432b0df33ae91197cbc4d82f4c0e04e8271 100644 (file)
@@ -52,6 +52,8 @@ typedef void (*StrokeDone)(struct bContext *C, struct PaintStroke *stroke);
 struct PaintStroke *paint_stroke_new(struct bContext *C,
                                     StrokeGetLocation get_location, StrokeTestStart test_start,
                                     StrokeUpdateStep update_step, StrokeDone done);
+void paint_stroke_free(struct PaintStroke *stroke);
+
 int paint_stroke_modal(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
 int paint_stroke_exec(struct bContext *C, struct wmOperator *op);
 struct ViewContext *paint_stroke_view_context(struct PaintStroke *stroke);
index e26b1945e7f3cde8bb62f73a686ae460ee7055c9..89c5443bf999724869c3c8b922689fb70b3ea66b 100644 (file)
@@ -237,6 +237,11 @@ PaintStroke *paint_stroke_new(bContext *C,
        return stroke;
 }
 
+void paint_stroke_free(PaintStroke *stroke)
+{
+       MEM_freeN(stroke);
+}
+
 int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
        PaintStroke *stroke = op->customdata;
index 11ce41c5ff8fc187deade5663bffe98501d28f7a..6671fec783e6645c4a2a2bbf1592661b71a45aa7 100644 (file)
@@ -2010,15 +2010,20 @@ static void sculpt_flush_update(bContext *C)
        }
 }
 
-static int sculpt_stroke_test_start(bContext *C, struct wmOperator *op, wmEvent *event)
+/* Returns whether the mouse/stylus is over the mesh (1)
+   or over the background (0) */
+static int over_mesh(bContext *C, struct wmOperator *op, float x, float y)
 {
-       float mouse[2] = {event->x, event->y}, location[3];
-       int over_mesh;
-       
-       over_mesh = sculpt_stroke_get_location(C, op->customdata, location, mouse);
+       float mouse[2] = {x, y}, co[3];
        
+       return (int)sculpt_stroke_get_location(C, op->customdata, co, mouse);
+}
+
+static int sculpt_stroke_test_start(bContext *C, struct wmOperator *op,
+                                   wmEvent *event)
+{
        /* Don't start the stroke until mouse goes over the mesh */
-       if(over_mesh) {
+       if(over_mesh(C, op, event->x, event->y)) {
                Object *ob = CTX_data_active_object(C);
                SculptSession *ss = ob->sculpt;
                Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
@@ -2076,14 +2081,27 @@ static void sculpt_stroke_done(bContext *C, struct PaintStroke *stroke)
 
 static int sculpt_brush_stroke_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
+       struct PaintStroke *stroke;
+       int ignore_background_click;
+
        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);
+       stroke = paint_stroke_new(C, sculpt_stroke_get_location,
+                                 sculpt_stroke_test_start,
+                                 sculpt_stroke_update_step,
+                                 sculpt_stroke_done);
 
+       op->customdata = stroke;
+
+       /* For tablet rotation */
+       ignore_background_click = RNA_boolean_get(op->ptr,
+                                                 "ignore_background_click"); 
+       if(ignore_background_click && !over_mesh(C, op, event->x, event->y)) {
+               paint_stroke_free(stroke);
+               return OPERATOR_PASS_THROUGH;
+       }
+       
        /* add modal handler */
        WM_event_add_modal_handler(C, op);
 
@@ -2144,6 +2162,10 @@ static void SCULPT_OT_brush_stroke(wmOperatorType *ot)
 
        /* The initial 2D location of the mouse */
        RNA_def_float_vector(ot->srna, "initial_mouse", 2, NULL, INT_MIN, INT_MAX, "initial_mouse", "", INT_MIN, INT_MAX);
+
+       RNA_def_boolean(ot->srna, "ignore_background_click", 0,
+                       "Ignore Background Click",
+                       "Clicks on the background don't start the stroke");
 }
 
 /**** Reset the copy of the mesh that is being sculpted on (currently just for the layer brush) ****/