[Bf-blender-cvs] [cb7d8a4a0f4] hair_object: Operator for hair edit brush strokes (to be implemented).

Lukas Toenne noreply at git.blender.org
Thu Dec 20 14:29:23 CET 2018


Commit: cb7d8a4a0f40603c7e98ff70d488edca41c38fef
Author: Lukas Toenne
Date:   Thu Dec 20 13:28:06 2018 +0000
Branches: hair_object
https://developer.blender.org/rBcb7d8a4a0f40603c7e98ff70d488edca41c38fef

Operator for hair edit brush strokes (to be implemented).

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	source/blender/editors/hair/CMakeLists.txt
M	source/blender/editors/hair/edithair.c
A	source/blender/editors/hair/edithair_brush.c
M	source/blender/editors/hair/hair_intern.h
M	source/blender/editors/hair/hair_ops.c
M	source/blender/editors/include/ED_hair.h

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 2b7622315c8..5c5c3c22206 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -4069,6 +4069,8 @@ def km_hair(params):
          {"properties": [("unselected", False)]}),
         ("hair.hide", {"type": 'H', "value": 'PRESS', "shift": True},
          {"properties": [("unselected", True)]}),
+        ("hair.brush_edit", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None),
+        ("hair.brush_edit", {"type": 'LEFTMOUSE', "value": 'PRESS', "shift": True}, None),
         *_template_items_proportional_editing(connected=False),
     ])
 
diff --git a/source/blender/editors/hair/CMakeLists.txt b/source/blender/editors/hair/CMakeLists.txt
index 4f74c24734c..3d309cd2508 100644
--- a/source/blender/editors/hair/CMakeLists.txt
+++ b/source/blender/editors/hair/CMakeLists.txt
@@ -36,6 +36,7 @@ set(INC_SYS
 set(SRC
 	hair_ops.c
 	edithair.c
+	edithair_brush.c
 	edithair_select.c
 	edithair_test.c
 
diff --git a/source/blender/editors/hair/edithair.c b/source/blender/editors/hair/edithair.c
index 5989143d2ec..8831c03e3be 100644
--- a/source/blender/editors/hair/edithair.c
+++ b/source/blender/editors/hair/edithair.c
@@ -56,6 +56,7 @@
 #include "ED_screen.h"
 #include "ED_types.h"
 #include "ED_util.h"
+#include "ED_view3d.h"
 
 #include "hair_intern.h"
 
@@ -99,8 +100,45 @@ void ED_hair_edithair_free(Object *ob)
 	}
 }
 
-int ED_hair_object_poll(bContext *C)
+bool ED_hair_poll_object(bContext *C)
 {
 	Object *ob = ED_object_context(C);
 	return ob && ob->type == OB_HAIR;
 }
+
+
+bool ED_hair_poll_editmode(bContext *C)
+{
+	Object *ob = ED_object_context(C);
+	return ob && ob->type == OB_HAIR && (ob->mode & OB_MODE_EDIT);
+}
+
+bool ED_hair_poll_view3d(bContext *C)
+{
+	if (!ED_hair_poll_editmode) {
+		return false;
+	}
+
+	ScrArea *sa = CTX_wm_area(C);
+	ARegion *ar = CTX_wm_region(C);
+	return (sa && sa->spacetype == SPACE_VIEW3D) &&
+	       (ar && ar->regiontype == RGN_TYPE_WINDOW);
+}
+
+void ED_hair_init_view3d(bContext *C, ViewContext *vc)
+{
+	ED_view3d_viewcontext_init(C, vc);
+
+	if (V3D_IS_ZBUF(vc->v3d)) {
+		if (vc->v3d->flag & V3D_INVALID_BACKBUF) {
+			/* needed or else the draw matrix can be incorrect */
+			view3d_operator_needs_opengl(C);
+
+			ED_view3d_backbuf_validate(vc);
+			/* we may need to force an update here by setting the rv3d as dirty
+			 * for now it seems ok, but take care!:
+			 * rv3d->depths->dirty = 1; */
+			ED_view3d_depth_update(vc->ar);
+		}
+	}
+}
diff --git a/source/blender/editors/hair/edithair_brush.c b/source/blender/editors/hair/edithair_brush.c
new file mode 100644
index 00000000000..15cab0b6198
--- /dev/null
+++ b/source/blender/editors/hair/edithair_brush.c
@@ -0,0 +1,454 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/hair/edithair_brush.c
+ *  \ingroup edhair
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+
+#include "DNA_hair_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "BKE_context.h"
+#include "BKE_customdata.h"
+#include "BKE_hair.h"
+#include "BKE_mesh_sample.h"
+
+#include "DEG_depsgraph.h"
+
+#include "ED_hair.h"
+#include "ED_screen.h"
+#include "ED_view3d.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "UI_resources.h"
+
+#include "BLT_translation.h"
+
+#include "hair_intern.h"  /* own include */
+
+// typedef struct HairOperator {
+// } HairOperator;
+
+/************************* Brush edit operator ********************/
+
+typedef struct BrushEdit {
+	Scene *scene;
+	ViewLayer *view_layer;
+	Object *ob;
+	EditHair *edit;
+
+	bool first;
+	float lastmouse[2];
+	float zfac;
+
+	ViewContext vc;
+} BrushEdit;
+
+static bool brush_edit_init(bContext *C, wmOperator *op)
+{
+	Scene *scene = CTX_data_scene(C);
+	ViewLayer *view_layer = CTX_data_view_layer(C);
+	ARegion *ar = CTX_wm_region(C);
+	const HairEditSettings *hset = &scene->toolsettings->hair_edit;
+	Object *ob = CTX_data_active_object(C);
+	HairSystem *hsys = ob->data;
+	EditHair *edit = hsys->edithair;
+	
+	if (hset->brushtype < 0)
+		return false;
+
+	BrushEdit *bedit;
+	bedit = MEM_callocN(sizeof(BrushEdit), "BrushEdit");
+	op->customdata = bedit;
+
+	bedit->scene = scene;
+	bedit->view_layer = view_layer;
+	bedit->ob = ob;
+	bedit->edit = edit;
+	bedit->first = true;
+
+	/* set the 'distance factor' for grabbing (used in comb etc) */
+	float min[3], max[3];
+	INIT_MINMAX(min, max);
+	// TODO implement selection mechanism for affected hair points/scalp area
+	BKE_hair_minmax(hsys, min, max);
+	mid_v3_v3v3(min, min, max);
+	bedit->zfac = ED_view3d_calc_zfac(ar->regiondata, min, NULL);
+
+	ED_hair_init_view3d(C, &bedit->vc);
+
+	return true;
+}
+
+static void brush_edit_exit(wmOperator *op)
+{
+	BrushEdit *bedit = op->customdata;
+
+	MEM_freeN(bedit);
+}
+
+static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
+{
+	Depsgraph *depsgraph = CTX_data_depsgraph(C);
+	BrushEdit *bedit = op->customdata;
+
+	float mouse[2];
+	RNA_float_get_array(itemptr, "mouse", mouse);
+	bool flip = RNA_boolean_get(itemptr, "pen_flip");
+
+	if (bedit->first) {
+		bedit->lastmouse[0] = mouse[0];
+		bedit->lastmouse[1] = mouse[1];
+	}
+
+#if 0
+	BrushEdit *bedit = op->customdata;
+	Depsgraph *depsgraph = CTX_data_depsgraph(C);
+	Scene *scene = bedit->scene;
+	Object *ob = bedit->ob;
+	PTCacheEdit *edit = bedit->edit;
+	ParticleEditSettings *pset = PE_settings(scene);
+	ParticleSystemModifierData *psmd_eval = edit->psmd_eval;
+	ParticleBrushData *brush = &pset->brush[pset->brushtype];
+	ARegion *ar = CTX_wm_region(C);
+	float vec[3], mousef[2];
+	int mval[2];
+	int flip, mouse[2], removed = 0, added = 0, selected = 0, tot_steps = 1, step = 1;
+	float dx, dy, dmax;
+	int lock_root = pset->flag & PE_LOCK_FIRST;
+
+	if (!PE_start_edit(edit))
+		return;
+
+	RNA_float_get_array(itemptr, "mouse", mousef);
+	mouse[0] = mousef[0];
+	mouse[1] = mousef[1];
+	flip = RNA_boolean_get(itemptr, "pen_flip");
+
+	if (bedit->first) {
+		bedit->lastmouse[0] = mouse[0];
+		bedit->lastmouse[1] = mouse[1];
+	}
+
+	dx = mouse[0] - bedit->lastmouse[0];
+	dy = mouse[1] - bedit->lastmouse[1];
+
+	mval[0] = mouse[0];
+	mval[1] = mouse[1];
+
+
+	/* 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)) || bedit->first)
+	{
+		PEData data = bedit->data;
+		data.context = C; // TODO(mai): why isnt this set in bedit->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] = bedit->lastmouse[0] + step * dx;
+			mval[1] = bedit->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, bedit->zfac);
+					data.dvec = vec;
+
+					foreach_mouse_hit_key(&data, brush_comb, selected);
+					break;
+				}
+				case PE_BRUSH_CUT:
+				{
+					if (edit->psys && edit->pathcache) {
+						data.mval = mval;
+						data.rad = pe_brush_size_get(scene, brush);
+						data.cutfac = brush->strength;
+
+						if (selected)
+							foreach_selected_point(&data, brush_cut);
+						else
+							foreach_point(&data, brush_cut);
+
+						removed = remove_tagged_particles(ob, edit->psys, pe_x_mirror(ob));
+						if (pset->flag & PE_KEEP_LENGTHS)
+							recalc_lengths(edit);
+					}
+					else
+						removed = 0;
+
+					break;
+				}
+				case PE_BRUSH_LENGTH:
+				{
+					data.mval = mval;
+
+					data.rad = pe_brush_size_get(scene, brush);
+					data.growfac = brush->strength / 50.0f;
+
+					if (brush->invert ^ flip)
+						data.growfac = 1.0f - data.growfac;
+					else
+						data.growfac = 1.0f + data.growfac;
+
+					foreach_mouse_hit_point(&data, brush_length, selected);
+
+					if (pset->flag & PE_KEEP_LENGTHS)
+						recalc_lengths(edit);
+					break;
+				}
+				case PE_BRUSH_PUFF:
+				{
+					if (edit->psys) {
+						data.mesh = psmd_eval->mesh_final;
+						data.mval = mval;
+						data.rad = pe_brush_size_get(scene, brush);
+						data.select = selected;
+
+						data.pufffac = (brush->strength - 0.5f) * 2.0f;
+						if (data.pufffac < 0.0f)
+							data.pufffac = 1.0f - 9.0f * data.pufffac;
+						else
+							data.pufffac = 1.0f - data.pufffac;
+
+						data.invert = (brush->invert ^ flip);
+						invert_m4_m4(ob->imat, ob->

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list