[Bf-blender-cvs] [0f9eb48] temp_hair_flow: Moved the hair flow solve operator out of the hair edit mode.

Lukas Tönne noreply at git.blender.org
Thu Jan 8 15:51:05 CET 2015


Commit: 0f9eb48c6cfee2980f897b513609b0c68dbfa7e5
Author: Lukas Tönne
Date:   Thu Jan 8 14:06:41 2015 +0100
Branches: temp_hair_flow
https://developer.blender.org/rB0f9eb48c6cfee2980f897b513609b0c68dbfa7e5

Moved the hair flow solve operator out of the hair edit mode.

The reason is that the flow calculation will be based on external
objects and also conflict with the edit mode tools. Flow-based grooming
calculates the hair rest state just like edit mode does, but is an
alternative to the edit mode instead of a single tool.

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

M	release/scripts/startup/bl_ui/properties_particle.py
M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/BKE_editstrands.h
M	source/blender/blenkernel/intern/editstrands.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/hair/hair_edit.c
M	source/blender/editors/hair/hair_flow.c
M	source/blender/makesdna/DNA_particle_types.h

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

diff --git a/release/scripts/startup/bl_ui/properties_particle.py b/release/scripts/startup/bl_ui/properties_particle.py
index db33cb3..6d4f4b8 100644
--- a/release/scripts/startup/bl_ui/properties_particle.py
+++ b/release/scripts/startup/bl_ui/properties_particle.py
@@ -259,6 +259,32 @@ class PARTICLE_PT_emission(ParticleButtonsPanel, Panel):
         row.prop(part, "use_modifier_stack")
 
 
+class PARTICLE_PT_hair_flow(ParticleButtonsPanel, Panel):
+    bl_label = "Hair Flow"
+    bl_options = {'DEFAULT_CLOSED'}
+
+    @classmethod
+    def poll(cls, context):
+        psys = context.particle_system
+        if psys is None:
+            return False
+        if psys.settings is None:
+            return False
+        return psys.settings.type == 'HAIR'
+
+#    def draw_header(self, context):
+#        psys = context.particle_system
+#        self.layout.prop(psys, "use_hair_flow", text="")
+
+    def draw(self, context):
+        layout = self.layout
+        psys = context.particle_system
+
+        col = layout.column()
+        col.operator("hair.solve_flow")
+
+
+
 class PARTICLE_PT_hair_dynamics(ParticleButtonsPanel, Panel):
     bl_label = "Hair dynamics"
     bl_options = {'DEFAULT_CLOSED'}
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index ebbe0bf..c9f4c69 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -899,10 +899,6 @@ class VIEW3D_PT_tools_brush(Panel, View3DPaintPanel):
 
             col.prop(brush, "hair_tool", text="Tool")
 
-            col.separator()
-
-            col.operator("hair.solve_flow")
-
         # Sculpt Mode #
 
         elif context.sculpt_object and brush:
diff --git a/source/blender/blenkernel/BKE_editstrands.h b/source/blender/blenkernel/BKE_editstrands.h
index d8b822d..4a329af 100644
--- a/source/blender/blenkernel/BKE_editstrands.h
+++ b/source/blender/blenkernel/BKE_editstrands.h
@@ -90,6 +90,6 @@ void BKE_editstrands_ensure(struct BMEditStrands *es);
 /* === particle conversion === */
 
 struct BMesh *BKE_particles_to_bmesh(struct Object *ob, struct ParticleSystem *psys);
-void BKE_particles_from_bmesh(struct Object *ob, struct ParticleSystem *psys);
+void BKE_particles_from_bmesh(struct Object *ob, struct ParticleSystem *psys, struct BMEditStrands *edit);
 
 #endif
diff --git a/source/blender/blenkernel/intern/editstrands.c b/source/blender/blenkernel/intern/editstrands.c
index 777c8bd..14d619c 100644
--- a/source/blender/blenkernel/intern/editstrands.c
+++ b/source/blender/blenkernel/intern/editstrands.c
@@ -186,10 +186,10 @@ BMesh *BKE_particles_to_bmesh(Object *ob, ParticleSystem *psys)
 	return bm;
 }
 
-void BKE_particles_from_bmesh(Object *ob, ParticleSystem *psys)
+void BKE_particles_from_bmesh(Object *ob, ParticleSystem *psys, BMEditStrands *edit)
 {
 	ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys);
-	BMesh *bm = psys->hairedit ? psys->hairedit->bm : NULL;
+	BMesh *bm = edit->bm;
 	
 	if (bm) {
 		if (psmd && psmd->dm) {
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 43d7e16..5d22b82 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -1284,6 +1284,7 @@ static ParticleSystem *copy_particlesystem(ParticleSystem *psys)
 	psysn->childcache = NULL;
 	psysn->edit = NULL;
 	psysn->hairedit = NULL;
+	psysn->hairflow = NULL;
 	psysn->pdd = NULL;
 	psysn->effectors = NULL;
 	psysn->tree = NULL;
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 6dc7794..7666b84 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -84,6 +84,8 @@
 #include "BKE_scene.h"
 #include "BKE_deform.h"
 
+#include "BPH_strands.h"
+
 #include "RE_render_ext.h"
 
 unsigned int PSYS_FRAND_SEED_OFFSET[PSYS_FRAND_COUNT];
@@ -572,6 +574,10 @@ void psys_free(Object *ob, ParticleSystem *psys)
 			MEM_freeN(psys->hairedit);
 			psys->hairedit = NULL;
 		}
+		if (psys->hairflow) {
+			BPH_strands_free_hair_flow(psys->hairflow);
+			psys->hairflow = NULL;
+		}
 
 		if (psys->child) {
 			MEM_freeN(psys->child);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 1262b5c..186c975 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3931,6 +3931,7 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles)
 		psys->edit = NULL;
 		psys->free_edit = NULL;
 		psys->hairedit = NULL;
+		psys->hairflow = NULL;
 		psys->pathcache = NULL;
 		psys->childcache = NULL;
 		BLI_listbase_clear(&psys->pathcachebufs);
diff --git a/source/blender/editors/hair/hair_edit.c b/source/blender/editors/hair/hair_edit.c
index 01cd1e4..0824449 100644
--- a/source/blender/editors/hair/hair_edit.c
+++ b/source/blender/editors/hair/hair_edit.c
@@ -104,7 +104,7 @@ static bool apply_hair_edit(Object *ob)
 	ParticleSystem *psys = psys_get_current(ob);
 	if (psys->part->type == PART_HAIR) {
 		if (psys->hairedit) {
-			BKE_particles_from_bmesh(ob, psys);
+			BKE_particles_from_bmesh(ob, psys, psys->hairedit);
 			psys->flag |= PSYS_EDITED;
 			
 			BKE_editstrands_free(psys->hairedit);
diff --git a/source/blender/editors/hair/hair_flow.c b/source/blender/editors/hair/hair_flow.c
index 17a4322..e9586fc 100644
--- a/source/blender/editors/hair/hair_flow.c
+++ b/source/blender/editors/hair/hair_flow.c
@@ -44,6 +44,7 @@
 #include "BKE_depsgraph.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_editstrands.h"
+#include "BKE_particle.h"
 
 #include "BPH_strands.h"
 
@@ -57,11 +58,17 @@
 
 #include "hair_intern.h"
 
+static int hair_flow_solve_poll(bContext *C)
+{
+	return hair_edit_toggle_poll(C);
+}
+
 static int hair_solve_flow_exec(bContext *C, wmOperator *op)
 {
 	Scene *scene = CTX_data_scene(C);
 	Object *ob = CTX_data_active_object(C);
-	BMEditStrands *edit = BKE_editstrands_from_object(ob);
+	ParticleSystem *psys = psys_get_current(ob);
+	struct HairFlowData *data;
 	
 	unsigned int seed = 111;
 	int max_strands = RNA_int_get(op->ptr, "max_strands");
@@ -69,14 +76,27 @@ static int hair_solve_flow_exec(bContext *C, wmOperator *op)
 	int segments = RNA_int_get(op->ptr, "segments");
 	int res = RNA_int_get(op->ptr, "resolution");
 	
-	struct HairFlowData *data = BPH_strands_solve_hair_flow(scene, ob, max_length, res, edit->debug_data);
+	if (!psys || !(ob->type == OB_MESH || ob->derivedFinal))
+		return OPERATOR_CANCELLED;
+	
+	data = BPH_strands_solve_hair_flow(scene, ob, max_length, res, NULL);
 	if (data) {
-		/* remove existing hair strands */
-		BM_mesh_clear(edit->bm);
+		BMesh *bm = BKE_particles_to_bmesh(ob, psys);
+		DerivedMesh *dm = ob->derivedFinal ? ob->derivedFinal : mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
+		BMEditStrands *edit = BKE_editstrands_create(bm, dm);
+		
 		/* generate new hair strands */
 		BPH_strands_sample_hair_flow(ob, edit, data, seed, max_strands, max_length, segments);
 		
+		BKE_particles_from_bmesh(ob, psys, edit);
+		psys->flag |= PSYS_EDITED;
+		BKE_editstrands_free(edit);
+		MEM_freeN(edit);
+		
 		BPH_strands_free_hair_flow(data);
+		
+		WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_HAIR, NULL);
+		DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
 	}
 	
 	WM_event_add_notifier(C, NC_OBJECT | ND_DRAW | NA_SELECTED, ob);
@@ -93,7 +113,7 @@ void HAIR_OT_solve_flow(wmOperatorType *ot)
 
 	/* api callbacks */
 	ot->exec = hair_solve_flow_exec;
-	ot->poll = hair_edit_poll;
+	ot->poll = hair_flow_solve_poll; /* uses temporary edit data */
 
 	/* flags */
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
diff --git a/source/blender/makesdna/DNA_particle_types.h b/source/blender/makesdna/DNA_particle_types.h
index c57d346..c4765a4 100644
--- a/source/blender/makesdna/DNA_particle_types.h
+++ b/source/blender/makesdna/DNA_particle_types.h
@@ -275,6 +275,7 @@ typedef struct ParticleSystem {
 	struct PTCacheEdit *edit;						/* particle editmode (runtime) */
 	void (*free_edit)(struct PTCacheEdit *edit);	/* free callback */
 	struct BMEditStrands *hairedit;			/* hair edit data (runtime) */
+	struct HairFlowData *hairflow;			/* hair flow data (runtime) */
 
 	struct ParticleCacheKey **pathcache;	/* path cache (runtime) */
 	struct ParticleCacheKey **childcache;	/* child cache (runtime) */




More information about the Bf-blender-cvs mailing list