[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18489] branches/blender2.5/blender/source /blender: Now that modal sculpt does stuff, added exec code.

Nicholas Bishop nicholasbishop at gmail.com
Tue Jan 13 21:50:07 CET 2009


Revision: 18489
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18489
Author:   nicholasbishop
Date:     2009-01-13 21:50:07 +0100 (Tue, 13 Jan 2009)

Log Message:
-----------
Now that modal sculpt does stuff, added exec code. For this, added new Stroke RNA. For now, it's just 3D brush location, but lots more will be added (e.g. tablet pressure)

Pressing f4 to redo a stroke now works as expected.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c
    branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_brush.c

Modified: branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c	2009-01-13 20:41:45 UTC (rev 18488)
+++ branches/blender2.5/blender/source/blender/editors/sculpt/sculpt.c	2009-01-13 20:50:07 UTC (rev 18489)
@@ -81,6 +81,9 @@
 #include "sculpt_intern.h"
 #include "../space_view3d/view3d_intern.h" /* XXX: oh no, the next generation of bad level call! should move ViewDepths perhaps (also used for view matrices) */
 
+#include "RNA_access.h"
+#include "RNA_define.h"
+
 #include "IMB_imbuf_types.h"
 
 #include "RE_render_ext.h"
@@ -1615,19 +1618,6 @@
 	return G.f & G_SCULPTMODE;
 }
 
-static int sculpt_brush_stroke_exec(bContext *C, wmOperator *op)
-{
-	BrushAction a;
-
-	a.symm.center_3d[0] = 0;
-	a.symm.center_3d[1] = 0;
-	a.symm.center_3d[2] = 0;
-
-	do_symmetrical_brush_actions(&CTX_data_scene(C)->sculptdata, &a, NULL, NULL);
-
-	printf("brush stroke exec\n");
-}
-
 /* This is temporary, matrices should be data in operator for exec */
 static int sculpt_load_mats(bContext *C, bglMats *mats)
 {
@@ -1684,27 +1674,34 @@
 	return OPERATOR_RUNNING_MODAL;
 }
 
+/* Temporary, most of brush action will become rna properties */
+static void sculpt_action_init(BrushAction *a)
+{
+	memset(a, 0, sizeof(BrushAction));
+	
+	a->size_3d = 0.25;
+	a->scale[0] = 1;
+	a->scale[1] = 1;
+	a->scale[2] = 1;
+}
+
 static int sculpt_brush_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
 {
+	PointerRNA itemptr;
 	SculptData *sd = &CTX_data_scene(C)->sculptdata;
 	BrushAction a;
 	Object *ob= CTX_data_active_object(C);
 	ARegion *ar = CTX_wm_region(C);
 
-	a.symm.center_3d[0] = 0;
-	a.symm.center_3d[1] = 0;
-	a.symm.center_3d[2] = 0;
+	sculpt_action_init(&a);
 	unproject(sd->session, a.symm.center_3d, event->x, event->y, get_depth(C, event->x, event->y));
-	printf("depth=%f\n", get_depth(C, event->x, event->y));
-	printvecf("center", a.symm.center_3d);
-	a.size_3d = 0.25;
-	a.scale[0] = 1;
-	a.scale[1] = 1;
-	a.scale[2] = 1;
-	a.clip[0] = 0;
-	a.clip[1] = 0;
-	a.clip[2] = 0;
+	/*printf("depth=%f\n", get_depth(C, event->x, event->y));
+	  printvecf("center", a.symm.center_3d);*/
 
+	/* Add to stroke */
+	RNA_collection_add(op->ptr, "stroke", &itemptr);
+	RNA_float_set_array(&itemptr, "location", a.symm.center_3d);
+
 	do_symmetrical_brush_actions(&CTX_data_scene(C)->sculptdata, &a, NULL, NULL);
 	//calc_damaged_verts(sd->session, &a);
 	BLI_freelistN(&sd->session->damaged_verts);
@@ -1724,9 +1721,36 @@
 	return OPERATOR_RUNNING_MODAL;
 }
 
+static int sculpt_brush_stroke_exec(bContext *C, wmOperator *op)
+{
+	BrushAction a;
+	Object *ob= CTX_data_active_object(C);
+	ARegion *ar = CTX_wm_region(C);
+	SculptData *sd = &CTX_data_scene(C)->sculptdata;
+
+	RNA_BEGIN(op->ptr, itemptr, "stroke") {
+		float loc[3];
+
+		sculpt_action_init(&a);		
+		RNA_float_get_array(&itemptr, "location", a.symm.center_3d);
+
+		do_symmetrical_brush_actions(sd, &a, NULL, NULL);
+		BLI_freelistN(&sd->session->damaged_verts);
+	}
+	RNA_END;
+
+	DAG_object_flush_update(CTX_data_scene(C), ob, OB_RECALC_DATA);
+	ED_region_tag_redraw(ar);
+
+	return OPERATOR_FINISHED;
+}
+
 void SCULPT_OT_brush_stroke(wmOperatorType *ot)
 {
-	
+	PropertyRNA *prop;
+
+	ot->flag |= OPTYPE_REGISTER;
+
 	/* identifiers */
 	ot->name= "Sculpt Mode";
 	ot->idname= "SCULPT_OT_brush_stroke";
@@ -1736,7 +1760,10 @@
 	ot->modal= sculpt_brush_stroke_modal;
 	ot->exec= sculpt_brush_stroke_exec;
 	ot->poll= sculpt_brush_stroke_poll;
-	
+
+	/* properties */
+	prop= RNA_def_property(ot->srna, "stroke", PROP_COLLECTION, PROP_NONE);
+	RNA_def_property_struct_runtime(prop, &RNA_OperatorStrokeElement);
 }
 
 /**** Toggle operator for turning sculpt mode on or off ****/

Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_access.h	2009-01-13 20:41:45 UTC (rev 18488)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_access.h	2009-01-13 20:50:07 UTC (rev 18489)
@@ -171,6 +171,7 @@
 extern StructRNA RNA_Operator;
 extern StructRNA RNA_OperatorMousePath;
 extern StructRNA RNA_OperatorProperties;
+extern StructRNA RNA_OperatorStrokeElement;
 extern StructRNA RNA_OrController;
 extern StructRNA RNA_OutflowFluidSettings;
 extern StructRNA RNA_PackedFile;

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_brush.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_brush.c	2009-01-13 20:41:45 UTC (rev 18488)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_brush.c	2009-01-13 20:50:07 UTC (rev 18489)
@@ -150,9 +150,48 @@
 	RNA_def_property_ui_range(prop, -1.0f , 1.0f, 10.0f, 3);
 }
 
+
+/* A brush stroke is a list of changes to the brush that
+ * can occur during a stroke
+ *
+ *  o 3D location of the brush (stored as collection due to symmetry)
+ *  o Tablet pressure
+ *  o Direction flip
+ *  o Tool switch
+ *  o Time
+ */
+static void rna_def_operator_stroke_element(BlenderRNA *brna)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+
+	srna= RNA_def_struct(brna, "OperatorStrokeElement", "IDPropertyGroup");
+	RNA_def_struct_ui_text(srna, "Operator Stroke Element", "");
+
+	prop= RNA_def_property(srna, "location", PROP_FLOAT, PROP_VECTOR);
+	RNA_def_property_flag(prop, PROP_IDPROPERTY);
+	RNA_def_property_array(prop, 3);
+	RNA_def_property_ui_text(prop, "Location", "");
+
+	/*prop= RNA_def_property(srna, "pressure", PROP_FLOAT, PROP_NONE);
+	RNA_def_property_flag(prop, PROP_IDPROPERTY);
+	RNA_def_property_range(prop, 0, 1);
+	RNA_def_property_ui_text(prop, "Pressure", "");*/
+
+	/*prop= RNA_def_property(srna, "flip", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_flag(prop, PROP_IDPROPERTY);
+	RNA_def_property_ui_text(prop, "Flip", "");*/
+
+	/* XXX: Tool (this will be for pressing a modifier key for a different brush,
+	        e.g. switching to a Smooth brush in the middle of the stroke */
+
+	/* XXX: Time (should be useful for airbrush mode) */
+}
+
 void RNA_def_brush(BlenderRNA *brna)
 {
 	rna_def_brush(brna);
+	rna_def_operator_stroke_element(brna);
 }
 
 #endif





More information about the Bf-blender-cvs mailing list