[Bf-blender-cvs] [4a8eb2a] gooseberry: Allow clumping and roughness in Spiral kink mode as well.

Lukas Tönne noreply at git.blender.org
Tue Jan 13 20:59:35 CET 2015


Commit: 4a8eb2a5c2041b49ff4d2e6bacbe1feac27e363a
Author: Lukas Tönne
Date:   Tue Jan 13 20:58:28 2015 +0100
Branches: gooseberry
https://developer.blender.org/rB4a8eb2a5c2041b49ff4d2e6bacbe1feac27e363a

Allow clumping and roughness in Spiral kink mode as well.

This requires interpolating the parent key properties, because no single
parent key can be mapped to each key on the children any more.

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

M	source/blender/blenkernel/intern/particle.c
M	source/blender/blenkernel/intern/particle_child.c

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

diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 72ad770..0af2217 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -104,7 +104,7 @@ void psys_init_rng(void)
 static void get_child_modifier_parameters(ParticleSettings *part, ParticleThreadContext *ctx,
                                           ChildParticle *cpa, short cpa_from, int cpa_num, float *cpa_fuv, float *orco, ParticleTexture *ptex);
 extern void do_child_modifiers(ParticleSimulationData *sim,
-                               ParticleTexture *ptex, ParticleKey *par, float *par_rot, const float par_orco[3],
+                               ParticleTexture *ptex, const float par_co[3], const float par_vel[3], const float par_rot[4], const float par_orco[3],
                                ChildParticle *cpa, const float orco[3], float mat[4][4], ParticleKey *state, float t);
 
 /* few helpers for countall etc. */
@@ -1702,9 +1702,9 @@ void psys_particle_on_emitter(ParticleSystemModifierData *psmd, int from, int in
 /*			Path Cache							*/
 /************************************************/
 
-extern void do_kink(ParticleKey *state, ParticleKey *par, float *par_rot, float time, float freq, float shape, float amplitude, float flat,
+extern void do_kink(ParticleKey *state, const float par_co[3], const float par_vel[3], const float par_rot[4], float time, float freq, float shape, float amplitude, float flat,
                     short type, short axis, float obmat[4][4], int smooth_start);
-extern float do_clump(ParticleKey *state, ParticleKey *par, float time, const float orco_offset[3], float clumpfac, float clumppow, float pa_clump,
+extern float do_clump(ParticleKey *state, const float par_co[3], float time, const float orco_offset[3], float clumpfac, float clumppow, float pa_clump,
                       bool use_clump_noise, float clump_noise_size, CurveMapping *clumpcurve);
 
 void precalc_guides(ParticleSimulationData *sim, ListBase *effectors)
@@ -1823,13 +1823,15 @@ int do_guides(ParticleSettings *part, ListBase *effectors, ParticleKey *state, i
 			curvemapping_changed_all(part->roughcurve);
 		
 		{
-			ParticleKey key, par;
+			ParticleKey key;
+			float par_co[3] = {0.0f, 0.0f, 0.0f};
+			float par_vel[3] = {0.0f, 0.0f, 0.0f};
+			float par_rot[4] = {1.0f, 0.0f, 0.0f, 0.0f};
 			float orco_offset[3] = {0.0f, 0.0f, 0.0f};
 			
-			par.co[0] = par.co[1] = par.co[2] = 0.0f;
 			copy_v3_v3(key.co, vec_to_point);
-			do_kink(&key, &par, 0, guidetime, pd->kink_freq, pd->kink_shape, pd->kink_amp, 0.f, pd->kink, pd->kink_axis, 0, 0);
-			do_clump(&key, &par, guidetime, orco_offset, pd->clump_fac, pd->clump_pow, 1.0f,
+			do_kink(&key, par_co, par_vel, par_rot, guidetime, pd->kink_freq, pd->kink_shape, pd->kink_amp, 0.f, pd->kink, pd->kink_axis, 0, 0);
+			do_clump(&key, par_co, guidetime, orco_offset, pd->clump_fac, pd->clump_pow, 1.0f,
 			         part->child_flag & PART_CHILD_USE_CLUMP_NOISE, part->clump_noise_size, part->clumpcurve);
 			copy_v3_v3(vec_to_point, key.co);
 		}
@@ -3818,7 +3820,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey *
 				copy_particle_key(&tstate, state, 1);
 
 			/* apply different deformations to the child path */
-			do_child_modifiers(sim, &ptex, par, par->rot, par_orco, cpa, orco, hairmat, state, t);
+			do_child_modifiers(sim, &ptex, par->co, par->vel, par->rot, par_orco, cpa, orco, hairmat, state, t);
 
 			/* try to estimate correct velocity */
 			if (vel) {
@@ -3921,7 +3923,7 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta
 			CLAMP(t, 0.0f, 1.0f);
 
 			unit_m4(mat);
-			do_child_modifiers(sim, NULL, key1, key1->rot, par_orco, cpa, cpa->fuv, mat, state, t);
+			do_child_modifiers(sim, NULL, key1->co, key1->vel, key1->rot, par_orco, cpa, cpa->fuv, mat, state, t);
 
 			if (psys->lattice_deform_data)
 				calc_latt_deform(psys->lattice_deform_data, state->co, 1.0f);
diff --git a/source/blender/blenkernel/intern/particle_child.c b/source/blender/blenkernel/intern/particle_child.c
index 79ae34f..358e34e 100644
--- a/source/blender/blenkernel/intern/particle_child.c
+++ b/source/blender/blenkernel/intern/particle_child.c
@@ -39,12 +39,12 @@
 
 struct Material;
 
-void do_kink(ParticleKey *state, ParticleKey *par, float *par_rot, float time, float freq, float shape, float amplitude, float flat,
+void do_kink(ParticleKey *state, const float par_co[3], const float par_vel[3], const float par_rot[4], float time, float freq, float shape, float amplitude, float flat,
              short type, short axis, float obmat[4][4], int smooth_start);
-float do_clump(ParticleKey *state, ParticleKey *par, float time, const float orco_offset[3], float clumpfac, float clumppow, float pa_clump,
+float do_clump(ParticleKey *state, const float par_co[3], float time, const float orco_offset[3], float clumpfac, float clumppow, float pa_clump,
                bool use_clump_noise, float clump_noise_size, CurveMapping *clumpcurve);
 void do_child_modifiers(ParticleSimulationData *sim,
-                        ParticleTexture *ptex, ParticleKey *par, float *par_rot, const float par_orco[3],
+                        ParticleTexture *ptex, const float par_co[3], const float par_vel[3], const float par_rot[4], const float par_orco[3],
                         ChildParticle *cpa, const float orco[3], float mat[4][4], ParticleKey *state, float t);
 
 static void get_strand_normal(Material *ma, const float surfnor[3], float surfdist, float nor[3])
@@ -172,7 +172,7 @@ static void do_kink_spiral_deform(ParticleKey *state, const float dir[3], const
 
 static void do_kink_spiral(ParticleThreadContext *ctx, ParticleTexture *ptex, const float parent_orco[3],
                            ChildParticle *cpa, const float orco[3], float hairmat[4][4],
-                           ParticleCacheKey *keys, int *r_totkeys, float *r_max_length)
+                           ParticleCacheKey *keys, ParticleCacheKey *parent_keys, int *r_totkeys, float *r_max_length)
 {
 	struct ParticleSettings *part = ctx->sim.psys->part;
 	const int seed = ctx->sim.psys->child_seed + (int)(cpa - ctx->sim.psys->child);
@@ -193,7 +193,11 @@ static void do_kink_spiral(ParticleThreadContext *ctx, ParticleTexture *ptex, co
 	int k;
 	
 	float dir[3];
-	float spiral_start[3];
+	float spiral_start[3] = {0.0f, 0.0f, 0.0f};
+	float spiral_start_time = 0.0f;
+	float spiral_par_co[3] = {0.0f, 0.0f, 0.0f};
+	float spiral_par_vel[3] = {0.0f, 0.0f, 0.0f};
+	float spiral_par_rot[4] = {1.0f, 0.0f, 0.0f, 0.0f};
 	float len, totlen, cutlen;
 	int start_index = 0, end_index = 0;
 	float kink_base[3];
@@ -218,10 +222,18 @@ static void do_kink_spiral(ParticleThreadContext *ctx, ParticleTexture *ptex, co
 		
 		if (seglen > 0.0f && len + seglen >= cutlen) {
 			float fac = (cutlen - len) / seglen;
+			ParticleCacheKey *par = parent_keys + k;
+			
 			start_index = k + 1;
 			end_index = start_index + extrakeys;
+			
+			spiral_start_time = ((float)k + fac) / (float)(totkeys - 1);
 			interp_v3_v3v3(spiral_start, key->co, (key+1)->co, fac);
 			
+			interp_v3_v3v3(spiral_par_co, par->co, (par+1)->co, fac);
+			interp_v3_v3v3(spiral_par_vel, par->vel, (par+1)->vel, fac);
+			interp_qt_qtqt(spiral_par_rot, par->rot, (par+1)->rot, fac);
+			
 			break;
 		}
 		len += seglen;
@@ -234,15 +246,29 @@ static void do_kink_spiral(ParticleThreadContext *ctx, ParticleTexture *ptex, co
 	mul_mat3_m4_v3(ctx->sim.ob->obmat, kink_base);
 	
 	for (k = 0, key = keys; k < end_index; k++, key++) {
+		float par_time;
+		float *par_co, *par_vel, *par_rot;
+		
 		psys_path_iter_get(&iter, keys, end_index, NULL, k);
 		if (k < start_index) {
 			sub_v3_v3v3(dir, (key+1)->co, key->co);
 			normalize_v3(dir);
+			
+			par_time = (float)k / (float)(totkeys - 1);
+			par_co = parent_keys[k].co;
+			par_vel = parent_keys[k].vel;
+			par_rot = parent_keys[k].rot;
 		}
 		else {
 			float spiral_time = (float)(k - start_index) / (float)(extrakeys-1);
 			float kink[3], tmp[3];
 			
+			/* use same time value for every point on the spiral */
+			par_time = spiral_start_time;
+			par_co = spiral_par_co;
+			par_vel = spiral_par_vel;
+			par_rot = spiral_par_rot;
+			
 			project_v3_v3v3(tmp, kink_base, dir);
 			sub_v3_v3v3(kink, kink_base, tmp);
 			normalize_v3(kink);
@@ -259,8 +285,7 @@ static void do_kink_spiral(ParticleThreadContext *ctx, ParticleTexture *ptex, co
 		}
 		
 		/* apply different deformations to the child path */
-		/* XXX TODO does not work without parent key, replace by explicit loc, rot, dir arguments! */
-		do_child_modifiers(&ctx->sim, ptex, (ParticleKey *)iter.parent_key, iter.parent_rotation, parent_orco, cpa, orco, hairmat, (ParticleKey *)key, iter.time);
+		do_child_modifiers(&ctx->sim, ptex, par_co, par_vel, par_rot, parent_orco, cpa, orco, hairmat, (ParticleKey *)key, par_time);
 	}
 	
 	totlen = 0.0f;
@@ -312,7 +337,7 @@ void psys_apply_child_modifiers(ParticleThreadContext *ctx, struct ListBase *mod
 	(void)mod;
 	
 	if (part->kink == PART_KINK_SPIRAL) {
-		do_kink_spiral(ctx, ptex, parent_orco, cpa, orco, hairmat, keys, &totkeys, &max_length);
+		do_kink_spiral(ctx, ptex, parent_orco, cpa, orco, hairmat, keys, parent_keys, &totkeys, &max_length);
 		keys->segments = totkeys - 1;
 	}
 	else {
@@ -322,10 +347,13 @@ void psys_apply_child_modifiers(ParticleThreadContext *ctx, struct ListBase *mod
 		max_length = ptex->length;
 		
 		for (k = 0, key = keys; k < totkeys; k++, key++) {
+			ParticleKey *par;
+			
 			psys_path_iter_get(&iter, keys, totkeys, parent_keys, k);
+			par = (ParticleKey *)iter.parent_key;
 			
 			/* apply different deformations to the child path */
-			do_child_modifiers(&ctx->sim, ptex, (ParticleKey *)iter.parent_key, iter.parent_rotation, parent_orco, cpa, orco, hairmat, (ParticleKey *)key, iter.time);
+			do_child_modifiers(&ctx->sim, ptex, par->co, par->vel, iter.parent_rotation, parent_orco, cpa, orco, hairmat, (ParticleKey *)key, iter.time);
 		}
 	}
 
@@ -366,13 +394,13 @@ void psys_apply_child_modifiers(ParticleThreadContext *ctx, struct ListBase *mod
 
 /* ------------------------------------------------------------------

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list