[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28820] branches/soc-2010-kwk/source/ blender: First attempt to use new stroke system by nicholasbishop in *particle
Konrad Kleine
konrad at konradwilhelm.de
Tue May 18 11:53:16 CEST 2010
Revision: 28820
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28820
Author: kwk
Date: 2010-05-18 11:53:16 +0200 (Tue, 18 May 2010)
Log Message:
-----------
First attempt to use new stroke system by nicholasbishop in *particle
mode* or more specifically in *PARTICLE_OT_brush_edit*.
If a brush, e.g. *Comb* , is selected the system works but if *None* is
selected and you draw a stroke Blender crashes and won't release
mouse/tablet control.
Modified Paths:
--------------
branches/soc-2010-kwk/source/blender/editors/physics/particle_edit.c
branches/soc-2010-kwk/source/blender/makesdna/DNA_scene_types.h
Modified: branches/soc-2010-kwk/source/blender/editors/physics/particle_edit.c
===================================================================
--- branches/soc-2010-kwk/source/blender/editors/physics/particle_edit.c 2010-05-18 09:07:58 UTC (rev 28819)
+++ branches/soc-2010-kwk/source/blender/editors/physics/particle_edit.c 2010-05-18 09:53:16 UTC (rev 28820)
@@ -78,6 +78,8 @@
#include "physics_intern.h"
+#include "../sculpt_paint/paint_intern.h"
+
static void PE_create_particle_edit(Scene *scene, Object *ob, PointCache *cache, ParticleSystem *psys);
static void PTCacheUndo_clear(PTCacheEdit *edit);
static void recalc_emitter_field(Object *ob, ParticleSystem *psys);
@@ -3281,8 +3283,8 @@
int lastmouse[2];
} BrushEdit;
-static int brush_edit_init(bContext *C, wmOperator *op)
-{
+static int brush_edit_init(bContext *C, struct PaintStroke *stroke)
+{
Scene *scene= CTX_data_scene(C);
Object *ob= CTX_data_active_object(C);
ParticleEditSettings *pset= PE_settings(scene);
@@ -3290,14 +3292,16 @@
ARegion *ar= CTX_wm_region(C);
BrushEdit *bedit;
- if(pset->brushtype < 0)
+ if(!stroke || pset->brushtype < 0)
return 0;
initgrabz(ar->regiondata, ob->obmat[3][0], ob->obmat[3][1], ob->obmat[3][2]);
bedit= MEM_callocN(sizeof(BrushEdit), "BrushEdit");
bedit->first= 1;
- op->customdata= bedit;
+ /* Attach brushedit to paint stroke mode_data instead to wmOperator customdata. */
+ paint_stroke_set_mode_data(stroke, bedit);
+// op->customdata= bedit;
bedit->scene= scene;
bedit->ob= ob;
@@ -3306,9 +3310,11 @@
return 1;
}
-static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
-{
- BrushEdit *bedit= op->customdata;
+static void particle_stroke_update_step(bContext *C, struct PaintStroke *stroke, PointerRNA *itemptr)
+{
+ /* Get brushedit from paint stroke mode_data instead of wmOperator customdata. */
+ BrushEdit *bedit = paint_stroke_mode_data(stroke);
+// BrushEdit *bedit= op->customdata;
Scene *scene= bedit->scene;
Object *ob= bedit->ob;
PTCacheEdit *edit= bedit->edit;
@@ -3324,9 +3330,11 @@
if(!PE_start_edit(edit))
return;
- RNA_float_get_array(itemptr, "mouse", mousef);
- mouse[0] = mousef[0];
- mouse[1] = mousef[1];
+ RNA_float_get_array(itemptr, "mouse", mousef);
+ /* XXX (kwk) not sure if this is the right place for adjusting mouse coordinates
+ (previously in brush_edit_apply_event) but it works. */
+ mouse[0] = mousef[0] - ar->winrct.xmin;
+ mouse[1] = mousef[1] - ar->winrct.ymin;
flip= RNA_boolean_get(itemptr, "flip");
if(bedit->first) {
@@ -3529,78 +3537,63 @@
pset->flag |= lock_root;
}
-static void brush_edit_exit(bContext *C, wmOperator *op)
+static void particle_stroke_done(bContext *C, struct PaintStroke *stroke)
{
- BrushEdit *bedit= op->customdata;
-
+ /* Get brushedit from paint stroke mode_data instead of wmOperator customdata. */
+ BrushEdit *bedit= paint_stroke_mode_data(stroke);
+// BrushEdit *bedit= op->customdata;
+
MEM_freeN(bedit);
}
-static int brush_edit_exec(bContext *C, wmOperator *op)
+//static int brush_edit_exec(bContext *C, wmOperator *op)
+//{
+// struct PaintStroke *stroke = op->customdata;
+// if(!brush_edit_init(C, stroke))
+// return OPERATOR_CANCELLED;
+//
+// RNA_BEGIN(op->ptr, itemptr, "stroke") {
+// brush_edit_apply(C, op, &itemptr);
+// }
+// RNA_END;
+//
+// brush_edit_exit(C, op);
+//
+// return OPERATOR_FINISHED;
+//}
+
+static int particle_stroke_test_start(bContext *C, struct wmOperator *op, wmEvent *event)
{
- if(!brush_edit_init(C, op))
+ struct PaintStroke *stroke = op->customdata;
+
+ if(!brush_edit_init(C, stroke))
return OPERATOR_CANCELLED;
- RNA_BEGIN(op->ptr, itemptr, "stroke") {
- brush_edit_apply(C, op, &itemptr);
- }
- RNA_END;
-
- brush_edit_exit(C, op);
-
- return OPERATOR_FINISHED;
+ // XXX (kwk) enough checking and setting?
+ // XXX (kwk) What about a VPaintData equivalent (e.g. for ViewContext)?
+
+ return 1;
}
-static void brush_edit_apply_event(bContext *C, wmOperator *op, wmEvent *event)
-{
- ARegion *ar= CTX_wm_region(C);
- PointerRNA itemptr;
- float mouse[2];
-
- mouse[0]= event->x - ar->winrct.xmin;
- mouse[1]= event->y - ar->winrct.ymin;
-
- /* fill in stroke */
- RNA_collection_add(op->ptr, "stroke", &itemptr);
-
- RNA_float_set_array(&itemptr, "mouse", mouse);
- RNA_boolean_set(&itemptr, "flip", event->shift != 0); // XXX hardcoded
-
- /* apply */
- brush_edit_apply(C, op, &itemptr);
-}
-
static int brush_edit_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
- if(!brush_edit_init(C, op))
- return OPERATOR_CANCELLED;
+ op->customdata = paint_stroke_new(C, NULL, particle_stroke_test_start,
+ particle_stroke_update_step,
+ particle_stroke_done);
- brush_edit_apply_event(C, op, event);
-
+ /* add modal handler */
WM_event_add_modal_handler(C, op);
+ /* XXX (kwk) copied from vpaint_stroke_invoke() and not sure what it does :( */
+ op->type->modal(C, op, event);
+
return OPERATOR_RUNNING_MODAL;
}
-static int brush_edit_modal(bContext *C, wmOperator *op, wmEvent *event)
-{
- switch(event->type) {
- case LEFTMOUSE:
- case MIDDLEMOUSE:
- case RIGHTMOUSE: // XXX hardcoded
- brush_edit_exit(C, op);
- return OPERATOR_FINISHED;
- case MOUSEMOVE:
- brush_edit_apply_event(C, op, event);
- break;
- }
-
- return OPERATOR_RUNNING_MODAL;
-}
-
static int brush_edit_cancel(bContext *C, wmOperator *op)
{
- brush_edit_exit(C, op);
+ struct PaintStroke *stroke = op->customdata;
+ particle_stroke_done(C, stroke); /* XXX (kwk) OK to call directly? */
return OPERATOR_CANCELLED;
}
@@ -3612,17 +3605,23 @@
ot->idname= "PARTICLE_OT_brush_edit";
/* api callbacks */
- ot->exec= brush_edit_exec;
- ot->invoke= brush_edit_invoke;
- ot->modal= brush_edit_modal;
- ot->cancel= brush_edit_cancel;
- ot->poll= PE_poll_view3d;
-
+ ot->invoke = brush_edit_invoke;
+ ot->modal = paint_stroke_modal;
+ ot->poll = PE_poll_view3d;
+ ot->cancel = brush_edit_cancel; /* XXX (kwk) Is this needed/good? */
+ /* XXX (kwk) find out about exec callback. look in paint_vertex.c */
+
+ // Old callbacks:
+ // ot->exec= brush_edit_exec;
+ // ot->invoke= brush_edit_invoke;
+ // ot->modal= brush_edit_modal;
+ // ot->cancel= brush_edit_cancel;
+ // ot->poll= PE_poll_view3d;
+
/* flags */
- ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
-
- /* properties */
- RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
+
+ RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", "");
}
/*********************** undo ***************************/
Modified: branches/soc-2010-kwk/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/soc-2010-kwk/source/blender/makesdna/DNA_scene_types.h 2010-05-18 09:07:58 UTC (rev 28819)
+++ branches/soc-2010-kwk/source/blender/makesdna/DNA_scene_types.h 2010-05-18 09:53:16 UTC (rev 28820)
@@ -550,6 +550,8 @@
} ParticleBrushData;
typedef struct ParticleEditSettings {
+ Paint paint; /* XXX (kwk) really needed? */
+
short flag;
short totrekey;
short totaddkey;
@@ -595,6 +597,7 @@
unsigned int *vpaint_prev; /* previous mesh colors */
struct MDeformVert *wpaint_prev; /* previous vertex weights */
+ /* XXX (kwk) delete this and fix errors afterwards */
void *paintcursor; /* wm handle */
} VPaint;
More information about the Bf-blender-cvs
mailing list