[Bf-blender-cvs] [4fd6a7a] strand_editmode: Revert previous hair edit operator scaffolding and port over the old operator for strokes instead.

Lukas Tönne noreply at git.blender.org
Mon Apr 20 14:23:17 CEST 2015


Commit: 4fd6a7a696858c79a6a245412c05b95e64b1011e
Author: Lukas Tönne
Date:   Sat Nov 29 19:00:50 2014 +0100
Branches: strand_editmode
https://developer.blender.org/rB4fd6a7a696858c79a6a245412c05b95e64b1011e

Revert previous hair edit operator scaffolding and port over the old
operator for strokes instead.

The paint system is much too complicated and does not add any real
advantage at this point.

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

M	source/blender/editors/hair/CMakeLists.txt
M	source/blender/editors/hair/hair_edit.c
M	source/blender/editors/hair/hair_intern.h
M	source/blender/editors/hair/hair_ops.c

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

diff --git a/source/blender/editors/hair/CMakeLists.txt b/source/blender/editors/hair/CMakeLists.txt
index f299b6e..41c2d42 100644
--- a/source/blender/editors/hair/CMakeLists.txt
+++ b/source/blender/editors/hair/CMakeLists.txt
@@ -37,6 +37,7 @@ set(INC_SYS
 set(SRC
 	hair_edit.c
 	hair_ops.c
+	hair_stroke.c
 
 	hair_intern.h
 )
diff --git a/source/blender/editors/hair/hair_edit.c b/source/blender/editors/hair/hair_edit.c
index 44e2dcf..c23354e 100644
--- a/source/blender/editors/hair/hair_edit.c
+++ b/source/blender/editors/hair/hair_edit.c
@@ -40,6 +40,7 @@
 #include "DNA_object_types.h"
 #include "DNA_particle_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
 
 #include "BKE_brush.h"
 #include "BKE_context.h"
@@ -48,7 +49,10 @@
 #include "BKE_paint.h"
 #include "BKE_particle.h"
 
+#include "bmesh.h"
+
 #include "RNA_access.h"
+#include "RNA_define.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -103,6 +107,27 @@ static bool apply_hair_edit(Object *ob)
 }
 
 
+/* ==== BMesh utilities ==== */
+
+void hair_bm_min_max(BMEditStrands *edit, float min[3], float max[3])
+{
+	BMVert *v;
+	BMIter iter;
+	
+	if (edit->bm->totvert > 0) {
+		INIT_MINMAX(min, max);
+		
+		BM_ITER_MESH(v, &iter, edit->bm, BM_VERTS_OF_MESH) {
+			minmax_v3v3_v3(min, max, v->co);
+		}
+	}
+	else {
+		zero_v3(min);
+		zero_v3(max);
+	}
+}
+
+
 /* ==== edit mode toggle ==== */
 
 int hair_edit_toggle_poll(bContext *C)
@@ -169,265 +194,375 @@ void HAIR_OT_hair_edit_toggle(wmOperatorType *ot)
 
 /* ==== brush stroke ==== */
 
-typedef struct HairStrokeOperation {
-	void *custom_paint;
-
-	float prevmouse[2];
-	float startmouse[2];
-	double starttime;
-
-	void *cursor;
-	ViewContext vc;
-} HairStrokeOperation;
-
-static HairStrokeOperation *hair_stroke_init(bContext *C, wmOperator *op, const float mouse[2])
+static int hair_stroke_poll(bContext *C)
 {
-	Scene *scene = CTX_data_scene(C);
-//	ToolSettings *settings = scene->toolsettings;
-	HairStrokeOperation *pop = MEM_callocN(sizeof(HairStrokeOperation), "PaintOperation"); /* caller frees */
-//	Brush *brush = BKE_paint_brush(&settings->imapaint.paint);
-	int mode = RNA_enum_get(op->ptr, "mode");
-	view3d_set_viewcontext(C, &pop->vc);
-
-	copy_v2_v2(pop->prevmouse, mouse);
-	copy_v2_v2(pop->startmouse, mouse);
-
-	/* initialize from context */
-	if (CTX_wm_region_view3d(C)) {
-		Object *ob = OBACT;
-		
-		pop->custom_paint = paint_proj_new_stroke(C, ob, mouse, mode);
-	}
-
-	if (!pop->custom_paint) {
-		MEM_freeN(pop);
-		return NULL;
+	Object *obact;
+	
+	obact = CTX_data_active_object(C);
+	if ((obact && obact->mode & OB_MODE_HAIR_EDIT) && CTX_wm_region_view3d(C)) {
+		return true;
 	}
-
-//	if ((brush->imagepaint_tool == PAINT_TOOL_FILL) && (brush->flag & BRUSH_USE_GRADIENT)) {
-//		pop->cursor = WM_paint_cursor_activate(CTX_wm_manager(C), image_paint_poll, gradient_draw_line, pop);
-//	}
 	
-//	ED_undo_paint_push_begin(UNDO_PAINT_IMAGE, op->type->name,
-//	                         ED_image_undo_restore, ED_image_undo_free, NULL);
-
-	return pop;
+	return false;
 }
 
-/* restore painting image to previous state. Used for anchored and drag-dot style brushes*/
-static void hair_stroke_restore(void)
-{
-	/* XXX TODO */
-//	ListBase *lb = undo_paint_push_get_list(UNDO_PAINT_IMAGE);
-//	image_undo_restore_runtime(lb);
-//	image_undo_invalidate();
-}
+typedef struct HairStroke {
+	Scene *scene;
+	Object *ob;
+	BMEditStrands *edit;
+	
+	bool first;
+	int lastmouse[2];
+	float zfac;
+	
+	/* optional cached view settings to avoid setting on every mousemove */
+//	PEData data;
+} HairStroke;
 
-static void hair_stroke_update_step(bContext *C, struct PaintStroke *stroke, PointerRNA *itemptr)
+static int hair_stroke_init(bContext *C, wmOperator *op)
 {
-	HairStrokeOperation *pop = paint_stroke_mode_data(stroke);
 	Scene *scene = CTX_data_scene(C);
-	ToolSettings *toolsettings = CTX_data_tool_settings(C);
-	UnifiedPaintSettings *ups = &toolsettings->unified_paint_settings;
-	Brush *brush = BKE_paint_brush(&toolsettings->imapaint.paint);
-
-	float alphafac = (brush->flag & BRUSH_ACCUMULATE) ? ups->overlap_factor : 1.0f;
-
-	/* initial brush values. Maybe it should be considered moving these to stroke system */
-	float startalpha = BKE_brush_alpha_get(scene, brush);
-
-	float mouse[2];
-	float pressure;
-	float size;
-	float distance = paint_stroke_distance_get(stroke);
-	int eraser;
+	Object *ob = CTX_data_active_object(C);
+//	ParticleEditSettings *pset = PE_settings(scene);
+	BMEditStrands *edit = BKE_editstrands_from_object(ob);
+	ARegion *ar = CTX_wm_region(C);
+	
+	HairStroke *stroke;
+	float min[3], max[3], center[3];
+	
+//	if (pset->brushtype < 0)
+//		return 0;
 
-	RNA_float_get_array(itemptr, "mouse", mouse);
-	pressure = RNA_float_get(itemptr, "pressure");
-	eraser = RNA_boolean_get(itemptr, "pen_flip");
-	size = max_ff(1.0f, RNA_float_get(itemptr, "size"));
-
-	/* stroking with fill tool only acts on stroke end */
-	if (brush->imagepaint_tool == PAINT_TOOL_FILL) {
-		copy_v2_v2(pop->prevmouse, mouse);
-		return;
-	}
+	/* set the 'distance factor' for grabbing (used in comb etc) */
+	hair_bm_min_max(edit, min, max);
+	mid_v3_v3v3(center, min, max);
 
-	if (BKE_brush_use_alpha_pressure(scene, brush))
-		BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * pressure * alphafac));
-	else
-		BKE_brush_alpha_set(scene, brush, max_ff(0.0f, startalpha * alphafac));
+	stroke = MEM_callocN(sizeof(HairStroke), "HairStroke");
+	stroke->first = true;
+	op->customdata = stroke;
 
-	if ((brush->flag & BRUSH_DRAG_DOT) || (brush->flag & BRUSH_ANCHORED)) {
-		hair_stroke_restore();
-	}
+	stroke->scene = scene;
+	stroke->ob = ob;
+	stroke->edit = edit;
 
-	paint_proj_stroke(C, pop->custom_paint, pop->prevmouse, mouse, eraser, pressure, distance, size);
+	stroke->zfac = ED_view3d_calc_zfac(ar->regiondata, center, NULL);
 
-	copy_v2_v2(pop->prevmouse, mouse);
+	/* cache view depths and settings for re-use */
+//	PE_set_view3d_data(C, &stroke->data);
 
-	/* restore brush values */
-	BKE_brush_alpha_set(scene, brush, startalpha);
+	return 1;
 }
 
-static void hair_stroke_redraw(const bContext *C, struct PaintStroke *stroke, bool final)
+static void hair_stroke_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
 {
-	HairStrokeOperation *pop = paint_stroke_mode_data(stroke);
+	HairStroke *stroke = op->customdata;
+	Scene *scene = stroke->scene;
+	Object *ob = stroke->ob;
+	BMEditStrands *edit = stroke->edit;
+//	ParticleEditSettings *pset= PE_settings(scene);
+//	ParticleSystemModifierData *psmd= edit->psys ? psys_get_modifier(ob, edit->psys) : NULL;
+//	ParticleBrushData *brush = &pset->brush[pset->brushtype];
+	ARegion *ar = CTX_wm_region(C);
+	
+	float /*vec[3],*/ mouse[2];
+	int mval[2];
+	int flip;
+//	int removed= 0, added=0, selected= 0, tot_steps= 1, step= 1;
+	float dx, dy/*, dmax*/;
+//	int lock_root = pset->flag & PE_LOCK_FIRST;
 
-	paint_proj_redraw(C, pop->custom_paint, final);
-}
+//	if (!PE_start_edit(edit))
+//		return;
 
-static void hair_stroke_done(const bContext *C, struct PaintStroke *stroke)
-{
-	Scene *scene = CTX_data_scene(C);
-	ToolSettings *toolsettings = scene->toolsettings;
-	HairStrokeOperation *pop = paint_stroke_mode_data(stroke);
-	Brush *brush = BKE_paint_brush(&toolsettings->imapaint.paint);
-
-	toolsettings->imapaint.flag &= ~IMAGEPAINT_DRAWING;
-
-	if (brush->imagepaint_tool == PAINT_TOOL_FILL) {
-		if (brush->flag & BRUSH_USE_GRADIENT) {
-			paint_proj_stroke(C, pop->custom_paint, pop->startmouse, pop->prevmouse, paint_stroke_flipped(stroke),
-			                  1.0, 0.0, BKE_brush_size_get(scene, brush));
-			/* two redraws, one for GPU update, one for notification */
-			paint_proj_redraw(C, pop->custom_paint, false);
-			paint_proj_redraw(C, pop->custom_paint, true);
-		}
-		else {
-			paint_proj_stroke(C, pop->custom_paint, pop->startmouse, pop->prevmouse, paint_stroke_flipped(stroke),
-			                  1.0, 0.0, BKE_brush_size_get(scene, brush));
-			/* two redraws, one for GPU update, one for notification */
-			paint_proj_redraw(C, pop->custom_paint, false);
-			paint_proj_redraw(C, pop->custom_paint, true);
-		}
-	}
-	paint_proj_stroke_done(pop->custom_paint);
+	RNA_float_get_array(itemptr, "mouse", mouse);
+	flip = RNA_boolean_get(itemptr, "pen_flip");
 
-	if (pop->cursor) {
-		WM_paint_cursor_end(CTX_wm_manager(C), pop->cursor);
+	if (stroke->first) {
+		stroke->lastmouse[0] = mouse[0];
+		stroke->lastmouse[1] = mouse[1];
 	}
 
-	// XXX TODO
-//	image_undo_end();
+	dx = mouse[0] - stroke->lastmouse[0];
+	dy = mouse[1] - stroke->lastmouse[1];
+
+	mval[0] = mouse[0];
+	mval[1] = mouse[1];
 
-	/* duplicate warning, see texpaint_init */
+	/* disable locking temporatily for disconnected hair */
+//	if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR)
+//		pset->flag &= ~PE_LOCK_FIRST;
+
+//	if (((pset->brushtype == PE_BRUSH_ADD) ?
+//	     (sqrtf(dx * dx + dy * dy) > pset->brush[PE_BRUSH_ADD].step) : (dx != 0 || dy != 0)) || stroke->first)
+	{
 #if 0
-	if (pop->s.warnmultifile)
-		BKE_reportf(op->reports, RPT_WARNING, "Image requires 4 color channels to paint: %s", pop->s.warnmultifile);
-	if (pop->s.warnpackedfile)
-		BKE_reportf(op->reports, RPT_WARNING, "Packed MultiLayer files cannot be painted: %s", pop->s.warnpackedfile);
+		PEData data= stroke->data;
+
+		view3d_operator_needs_opengl(C);
+		selected= (short)count_selected_keys(scene, edit);
+
+		dmax = max_ff(fabsf(dx), fabsf(dy));
+		tot_steps = dmax/(0.2f * pe_brush_size_get(scene, brush)) + 1;
+
+		dx /= (float)tot_steps;
+		dy /= (float)tot_steps;
+
+		for (step = 1; step<=tot_steps; step++) {
+			mval[0] = stroke->lastmouse[0] + step*dx;
+			mval[1] = stroke->lastmouse[1] + step*dy;
+
+			switch (pset->brushtype) {
+				case PE_BRUSH_COMB:
+				{
+					const float mval_f[2] = {dx, dy};
+					data.mval= mval;
+					data.rad= pe_brush_size_get(scene, brush);
+
+					data.combfac= (brush->strength - 0.5f) * 2.0f;
+					if (data.combfac < 0.0f)
+						data.combfac= 1.0f - 9.0f * data.combfac;
+					else
+						data.combfac= 1.0f - data.combfac;
+
+					invert_m4_m4(ob->imat, ob->obmat);
+
+					ED_view3d_win_to_delta(ar, mval_f, vec, stroke->zfac);
+					data.dvec= vec;
+
+					foreach_mouse_hit_key(&data, br

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list