[Bf-blender-cvs] [4e3352c] hair_immediate_fixes: Store hair edit data in particle systems and manage it in the operator for entering/exiting the edit mode.

Lukas Tönne noreply at git.blender.org
Sat Dec 27 11:31:44 CET 2014


Commit: 4e3352ca0707d72e12b086fe6a6ff01a7a152f77
Author: Lukas Tönne
Date:   Tue Nov 25 09:30:59 2014 +0100
Branches: hair_immediate_fixes
https://developer.blender.org/rB4e3352ca0707d72e12b086fe6a6ff01a7a152f77

Store hair edit data in particle systems and manage it in the operator
for entering/exiting the edit mode.

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

M	source/blender/blenkernel/intern/edithair_particles.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/makesdna/DNA_particle_types.h

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

diff --git a/source/blender/blenkernel/intern/edithair_particles.c b/source/blender/blenkernel/intern/edithair_particles.c
index 215ba24..463af02 100644
--- a/source/blender/blenkernel/intern/edithair_particles.c
+++ b/source/blender/blenkernel/intern/edithair_particles.c
@@ -173,9 +173,6 @@ static void create_particle_data(ParticleSystem *psys, HairEditData *hedit)
 
 void BKE_edithair_to_particles(HairEditData *hedit, Object *UNUSED(ob), ParticleSystem *psys)
 {
-	psys->flag |= PSYS_EDITED;
-	
 	free_particle_data(psys);
-	
 	create_particle_data(psys, hedit);
 }
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 851d5ac..43d7e16 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -1283,6 +1283,7 @@ static ParticleSystem *copy_particlesystem(ParticleSystem *psys)
 	psysn->pathcache = NULL;
 	psysn->childcache = NULL;
 	psysn->edit = NULL;
+	psysn->hairedit = 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 70c0d19..63e06aa 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -64,6 +64,7 @@
 
 #include "BKE_boids.h"
 #include "BKE_cloth.h"
+#include "BKE_edithair.h"
 #include "BKE_effect.h"
 #include "BKE_global.h"
 #include "BKE_group.h"
@@ -566,6 +567,8 @@ void psys_free(Object *ob, ParticleSystem *psys)
 
 		if (psys->edit && psys->free_edit)
 			psys->free_edit(psys->edit);
+		if (psys->hairedit)
+			BKE_edithair_free(psys->hairedit);
 
 		if (psys->child) {
 			MEM_freeN(psys->child);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 4df51f5..cc881ee 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3930,6 +3930,7 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles)
 		
 		psys->edit = NULL;
 		psys->free_edit = NULL;
+		psys->hairedit = 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 e92d647..70da2ac 100644
--- a/source/blender/editors/hair/hair_edit.c
+++ b/source/blender/editors/hair/hair_edit.c
@@ -40,6 +40,7 @@
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
 #include "BKE_edithair.h"
+#include "BKE_particle.h"
 
 #include "RNA_access.h"
 
@@ -53,25 +54,42 @@
 
 static bool has_hair_data(Object *ob)
 {
-	ParticleSystem *psys;
+	ParticleSystem *psys = psys_get_current(ob);
+	if (psys->part->type == PART_HAIR)
+		return true;
 	
-	for (psys = ob->particlesystem.first; psys; psys = psys->next) {
-		if (psys->part->type == PART_HAIR)
-			return true;
+	return false;
+}
+
+static bool init_hair_edit(Object *ob)
+{
+	ParticleSystem *psys = psys_get_current(ob);
+	if (psys->part->type == PART_HAIR) {
+		HairEditData *hedit = psys->hairedit;
+		if (!hedit)
+			psys->hairedit = hedit = BKE_edithair_create();
+		
+		BKE_edithair_from_particles(hedit, ob, psys);
+		
+		return true;
 	}
 	
 	return false;
 }
 
-static bool init_hair_edit(Object *ob, HairEditData *hedit)
+static bool apply_hair_edit(Object *ob)
 {
-	ParticleSystem *psys;
-	
-	for (psys = ob->particlesystem.first; psys; psys = psys->next) {
-		if (psys->part->type == PART_HAIR) {
-			BKE_edithair_from_particles(hedit, ob, psys);
-			return true;
+	ParticleSystem *psys = psys_get_current(ob);
+	if (psys->part->type == PART_HAIR) {
+		if (psys->hairedit) {
+			BKE_edithair_to_particles(psys->hairedit, ob, psys);
+			psys->flag |= PSYS_EDITED;
+			
+			BKE_edithair_free(psys->hairedit);
+			psys->hairedit = NULL;
 		}
+		
+		return true;
 	}
 	
 	return false;
@@ -107,16 +125,14 @@ static int hair_edit_toggle_exec(bContext *C, wmOperator *op)
 	}
 
 	if (!is_mode_set) {
-		HairEditData *hedit = BKE_edithair_create();
-		
+		init_hair_edit(ob);
 		ob->mode |= mode_flag;
-		init_hair_edit(ob, hedit);
 		
 //		toggle_particle_cursor(C, 1);
 		WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_HAIR, NULL);
 	}
 	else {
-//		hair_edit_to_particles();
+		apply_hair_edit(ob);
 		ob->mode &= ~mode_flag;
 		
 //		toggle_particle_cursor(C, 0);
diff --git a/source/blender/makesdna/DNA_particle_types.h b/source/blender/makesdna/DNA_particle_types.h
index 4eff788..2c4c959 100644
--- a/source/blender/makesdna/DNA_particle_types.h
+++ b/source/blender/makesdna/DNA_particle_types.h
@@ -274,6 +274,7 @@ typedef struct ParticleSystem {
 
 	struct PTCacheEdit *edit;						/* particle editmode (runtime) */
 	void (*free_edit)(struct PTCacheEdit *edit);	/* free callback */
+	struct HairEditData *hairedit;			/* hair edit data (runtime) */
 
 	struct ParticleCacheKey **pathcache;	/* path cache (runtime) */
 	struct ParticleCacheKey **childcache;	/* child cache (runtime) */




More information about the Bf-blender-cvs mailing list