[Bf-blender-cvs] [c350141] temp_hair_modifiers: Added a second hair data layer to store modifier results.

Lukas Tönne noreply at git.blender.org
Mon Feb 2 16:11:39 CET 2015


Commit: c3501411d3457676abc787e54f1f4063dec977d5
Author: Lukas Tönne
Date:   Sun Feb 1 18:06:24 2015 +0100
Branches: temp_hair_modifiers
https://developer.blender.org/rBc3501411d3457676abc787e54f1f4063dec977d5

Added a second hair data layer to store modifier results.

This imitates the DerivedMesh principle from meshes. For hair the
modifiers will get the grooming or original growth result as input.
The result of the modifier eval will be written to the new data layer,
making a simple copy if modifiers are not used. Physics sim, rendering
and (depending of settings) drawing will then use the modified grooming
data.

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

M	source/blender/blenkernel/intern/object.c
M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenkernel/intern/particle_system.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/makesdna/DNA_particle_types.h

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

diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index f290ddd..01b09db 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -1249,8 +1249,11 @@ ParticleSystem *BKE_object_copy_particlesystem(ParticleSystem *psys)
 	psysn->child = MEM_dupallocN(psys->child);
 
 	if (psys->part->type == PART_HAIR) {
-		for (p = 0, pa = psysn->particles; p < psysn->totpart; p++, pa++)
+		for (p = 0, pa = psysn->particles; p < psysn->totpart; p++, pa++) {
 			pa->hair = MEM_dupallocN(pa->hair);
+			if (pa->hair_final)
+				pa->hair_final = MEM_dupallocN(pa->hair_final);
+		}
 	}
 
 	if (psysn->particles && (psysn->particles->keys || psysn->particles->boid)) {
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 7cf4eef..6d3e9eb 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -435,9 +435,14 @@ void free_hair(Object *UNUSED(ob), ParticleSystem *psys, int dynamics)
 	PARTICLE_P;
 
 	LOOP_PARTICLES {
-		if (pa->hair)
+		if (pa->hair) {
 			MEM_freeN(pa->hair);
-		pa->hair = NULL;
+			pa->hair = NULL;
+		}
+		if (pa->hair_final) {
+			MEM_freeN(pa->hair_final);
+			pa->hair_final = NULL;
+		}
 		pa->totkey = 0;
 	}
 
@@ -524,6 +529,8 @@ void psys_free_particles(ParticleSystem *psys)
 			LOOP_PARTICLES {
 				if (pa->hair)
 					MEM_freeN(pa->hair);
+				if (pa->hair_final)
+					MEM_freeN(pa->hair_final);
 			}
 		}
 		
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index 4a17e20..acc32a7 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -263,8 +263,12 @@ static void realloc_particles(ParticleSimulationData *sim, int new_totpart)
 				}
 			}
 
-			for (p=totsaved, pa=psys->particles+totsaved; p<psys->totpart; p++, pa++)
-				if (pa->hair) MEM_freeN(pa->hair);
+			for (p=totsaved, pa=psys->particles+totsaved; p<psys->totpart; p++, pa++) {
+				if (pa->hair)
+					MEM_freeN(pa->hair);
+				if (pa->hair_final)
+					MEM_freeN(pa->hair_final);
+			}
 
 			MEM_freeN(psys->particles);
 			psys_free_pdd(psys);
@@ -2980,10 +2984,10 @@ static bool psys_hair_use_simulation(ParticleData *pa, float max_length)
 	HairKey *key;
 	int k;
 	
-	if (pa->totkey < 2)
+	if (pa->totkey_final < 2)
 		return false;
 	
-	for (k=1, key=pa->hair+1; k<pa->totkey; k++,key++) {
+	for (k=1, key=pa->hair_final+1; k<pa->totkey_final; k++,key++) {
 		float length = len_v3v3(key->co, (key-1)->co);
 		if (length < min_length)
 			return false;
@@ -3155,7 +3159,7 @@ static void hair_create_input_dm(ParticleSimulationData *sim, int totpoint, int
 	/* calculate maximum segment length */
 	max_length = 0.0f;
 	LOOP_PARTICLES {
-		for (k=1, key=pa->hair+1; k<pa->totkey; k++,key++) {
+		for (k=1, key=pa->hair_final+1; k<pa->totkey_final; k++,key++) {
 			float length = len_v3v3(key->co, (key-1)->co);
 			if (max_length < length)
 				max_length = length;
@@ -3185,7 +3189,7 @@ static void hair_create_input_dm(ParticleSimulationData *sim, int totpoint, int
 		
 		bending_stiffness = CLAMPIS(1.0f - part->bending_random * psys_frand(psys, p + 666), 0.0f, 1.0f);
 		
-		for (k=0, key=pa->hair; k<pa->totkey; k++,key++) {
+		for (k=0, key=pa->hair_final; k<pa->totkey_final; k++,key++) {
 			ClothHairData *hair;
 			float *co, *co_next;
 			
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index a1cf6ff..34e9e0a 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3901,8 +3901,11 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles)
 		psys->particles=newdataadr(fd, psys->particles);
 		
 		if (psys->particles && psys->particles->hair) {
-			for (a=0, pa=psys->particles; a<psys->totpart; a++, pa++)
+			for (a=0, pa=psys->particles; a<psys->totpart; a++, pa++) {
 				pa->hair=newdataadr(fd, pa->hair);
+				pa->hair_final = NULL;
+				pa->totkey_final = 0;
+			}
 		}
 		
 		if (psys->particles && psys->particles->keys) {
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index ade2437..61dddd2 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -5555,7 +5555,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
 				
 				for (a = 0, pa = psys->particles; a < totpart; a++, pa++) {
 					if (pa->totkey > 1) {
-						HairKey *hkey = pa->hair;
+						HairKey *hkey = pa->hair_final;
 						
 						glVertexPointer(3, GL_FLOAT, sizeof(HairKey), hkey->world_co);
 						
@@ -5563,7 +5563,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
 //						UI_ThemeColor(TH_NORMAL);
 						glColor3f(0.58f, 0.67f, 1.0f);
 						
-						glDrawArrays(GL_LINE_STRIP, 0, pa->totkey);
+						glDrawArrays(GL_LINE_STRIP, 0, pa->totkey_final);
 					}
 				}
 				
diff --git a/source/blender/makesdna/DNA_particle_types.h b/source/blender/makesdna/DNA_particle_types.h
index f551d9e..af31c0c 100644
--- a/source/blender/makesdna/DNA_particle_types.h
+++ b/source/blender/makesdna/DNA_particle_types.h
@@ -100,12 +100,15 @@ typedef struct ParticleData {
 	ParticleKey prev_state; /* previous state */
 	
 	HairKey *hair;			/* hair vertices */
+	HairKey *hair_final;	/* hair vertices after applying modifiers */
 
 	ParticleKey *keys;		/* keyed keys */
 
 	BoidParticle *boid;		/* boids data */
 
 	int totkey;				/* amount of hair or keyed keys*/
+	int totkey_final;		/* final hair key amount */
+	int pad1;
 
 	float time, lifetime;	/* dietime is not nescessarily time+lifetime as	*/
 	float dietime;			/* particles can die unnaturally (collision)	*/
@@ -119,7 +122,7 @@ typedef struct ParticleData {
 	float size;				/* size and multiplier so that we can update size when ever */
 
 	float sphdensity;		/* density of sph particle */
-	int pad;
+	int pad2;
 
 	int hair_index;
 	short flag;




More information about the Bf-blender-cvs mailing list