[Bf-blender-cvs] [af4af60] hair_system: Make the "copy from particles" operator for hair always clear the system first, so replacing hair becomes easier.

Lukas Tönne noreply at git.blender.org
Fri Aug 15 16:47:59 CEST 2014


Commit: af4af60aecd115cfc7358e00106b227b080347e9
Author: Lukas Tönne
Date:   Fri Aug 15 14:53:05 2014 +0200
Branches: hair_system
https://developer.blender.org/rBaf4af60aecd115cfc7358e00106b227b080347e9

Make the "copy from particles" operator for hair always clear the system
first, so replacing hair becomes easier.

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

M	source/blender/blenkernel/BKE_hair.h
M	source/blender/blenkernel/intern/hair.c
M	source/blender/editors/physics/hair_ops.c

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

diff --git a/source/blender/blenkernel/BKE_hair.h b/source/blender/blenkernel/BKE_hair.h
index 1c51482..1066e6a 100644
--- a/source/blender/blenkernel/BKE_hair.h
+++ b/source/blender/blenkernel/BKE_hair.h
@@ -40,6 +40,8 @@ struct HairSystem *BKE_hairsys_new(void);
 void BKE_hairsys_free(struct HairSystem *hsys);
 struct HairSystem *BKE_hairsys_copy(struct HairSystem *hsys);
 
+void BKE_hairsys_clear(struct HairSystem *hsys);
+
 struct HairCurve *BKE_hair_curve_add(struct HairSystem *hsys);
 struct HairCurve *BKE_hair_curve_add_multi(struct HairSystem *hsys, int num);
 void BKE_hair_curve_remove(struct HairSystem *hsys, struct HairCurve *hair);
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index 4b9e8a7..26bb68f 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -72,16 +72,7 @@ HairSystem *BKE_hairsys_new(void)
 
 void BKE_hairsys_free(HairSystem *hsys)
 {
-	int totcurves = hsys->totcurves, i;
-	if (hsys->curves) {
-		for (i = 0; i < totcurves; ++i)
-			MEM_freeN(hsys->curves[i].points);
-		MEM_freeN(hsys->curves);
-	}
-	
-	if (hsys->render_iter)
-		MEM_freeN(hsys->render_iter);
-	
+	BKE_hairsys_clear(hsys);
 	MEM_freeN(hsys);
 }
 
@@ -99,6 +90,22 @@ HairSystem *BKE_hairsys_copy(HairSystem *hsys)
 	return thsys;
 }
 
+void BKE_hairsys_clear(HairSystem *hsys)
+{
+	int totcurves = hsys->totcurves, i;
+	if (hsys->curves) {
+		for (i = 0; i < totcurves; ++i)
+			MEM_freeN(hsys->curves[i].points);
+		MEM_freeN(hsys->curves);
+		hsys->curves = NULL;
+		hsys->totcurves = 0;
+	}
+	
+	if (hsys->render_iter) {
+		MEM_freeN(hsys->render_iter);
+		hsys->render_iter = NULL;
+	}
+}
 
 HairCurve *BKE_hair_curve_add(HairSystem *hsys)
 {
diff --git a/source/blender/editors/physics/hair_ops.c b/source/blender/editors/physics/hair_ops.c
index 15a08ae..aaf9a02 100644
--- a/source/blender/editors/physics/hair_ops.c
+++ b/source/blender/editors/physics/hair_ops.c
@@ -254,6 +254,8 @@ static int hair_copy_from_particles_exec(bContext *C, wmOperator *op)
 	HairModifierData *hmd;
 	ED_hair_get(C, &ob, &hsys, &hmd);
 	
+	BKE_hairsys_clear(hsys);
+	
 	for (psys = ob->particlesystem.first; psys; psys = psys->next) {
 		ParticleSystemModifierData *psmd;
 		if (psys->part->type != PART_HAIR) {
@@ -272,10 +274,10 @@ static int hair_copy_from_particles_exec(bContext *C, wmOperator *op)
 		}
 		
 		hair_copy_from_particles_psys(ob, hsys, psys, psmd->dm);
-		
-		hmd->flag &= ~MOD_HAIR_SOLVER_DATA_VALID;
 	}
 	
+	hmd->flag &= ~MOD_HAIR_SOLVER_DATA_VALID;
+	
 	BKE_hair_calculate_rest(hsys);
 	
 	WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);




More information about the Bf-blender-cvs mailing list