[Bf-blender-cvs] [30f3a2b] temp_merge_gooseberry_hair: Reorganizing hair child code a little bit to make it not totally insane.

Lukas Tönne noreply at git.blender.org
Mon Jan 19 20:51:35 CET 2015


Commit: 30f3a2b11b811c13b0e1ae66e4e533e7ad28c3c6
Author: Lukas Tönne
Date:   Fri Jan 9 11:31:00 2015 +0100
Branches: temp_merge_gooseberry_hair
https://developer.blender.org/rB30f3a2b11b811c13b0e1ae66e4e533e7ad28c3c6

Reorganizing hair child code a little bit to make it not totally insane.

This contains a few pieces of code for a future "modifier" system that
would allow more flexible combination of effects. Eventually a node
system is the way to go, but the current code makes that impossible.

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

M	source/blender/blenkernel/BKE_particle.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/particle.c
A	source/blender/blenkernel/intern/particle_child.c

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

diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index 0564515..40fbc1f 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -338,6 +338,11 @@ float psys_get_child_size(struct ParticleSystem *psys, struct ChildParticle *cpa
 void psys_get_particle_on_path(struct ParticleSimulationData *sim, int pa_num, struct ParticleKey *state, const bool vel);
 int psys_get_particle_state(struct ParticleSimulationData *sim, int p, struct ParticleKey *state, int always);
 
+/* child paths */
+void psys_apply_child_modifiers(struct ParticleThreadContext *ctx, struct ListBase *modifiers,
+                                struct ChildParticle *cpa, struct ParticleTexture *ptex, const float orco[3], const float ornor[3], float hairmat[4][4],
+                                struct ParticleCacheKey *keys, struct ParticleCacheKey *parent_keys);
+
 void psys_sph_init(struct ParticleSimulationData *sim, struct SPHData *sphdata);
 void psys_sph_finalise(struct SPHData *sphdata);
 void psys_sph_density(struct BVHTree *tree, struct SPHData *data, float co[3], float vars[2]);
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 5ded71e..90230e6 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -135,6 +135,7 @@ set(SRC
 	intern/packedFile.c
 	intern/paint.c
 	intern/particle.c
+	intern/particle_child.c
 	intern/particle_distribute.c
 	intern/particle_system.c
 	intern/pbvh.c
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index fd9dc21..b2bfe0c 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -102,9 +102,9 @@ 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);
-static void do_child_modifiers(ParticleSimulationData *sim,
-                               ParticleTexture *ptex, ParticleKey *par, float *par_rot, ChildParticle *cpa,
-                               float *orco, float mat[4][4], ParticleKey *state, float t);
+void do_child_modifiers(ParticleSimulationData *sim,
+                        ParticleTexture *ptex, ParticleKey *par, float *par_rot, ChildParticle *cpa,
+                        const float orco[3], float mat[4][4], ParticleKey *state, float t);
 
 /* few helpers for countall etc. */
 int count_particles(ParticleSystem *psys)
@@ -1983,7 +1983,7 @@ int do_guides(ListBase *effectors, ParticleKey *state, int index, float time)
 	}
 	return 0;
 }
-static void do_rough(float *loc, float mat[4][4], float t, float fac, float size, float thres, ParticleKey *state)
+static void do_rough(const float loc[3], float mat[4][4], float t, float fac, float size, float thres, ParticleKey *state)
 {
 	float rough[3];
 	float rco[3];
@@ -2049,20 +2049,6 @@ static void do_path_effectors(ParticleSimulationData *sim, int i, ParticleCacheK
 	if (k < steps)
 		*length = len_v3(vec);
 }
-static int check_path_length(int k, ParticleCacheKey *keys, ParticleCacheKey *state, float max_length, float *cur_length, float length, float *dvec)
-{
-	if (*cur_length + length > max_length) {
-		mul_v3_fl(dvec, (max_length - *cur_length) / length);
-		add_v3_v3v3(state->co, (state - 1)->co, dvec);
-		keys->steps = k;
-		/* something over the maximum step value */
-		return k = 100000;
-	}
-	else {
-		*cur_length += length;
-		return k;
-	}
-}
 static void offset_child(ChildParticle *cpa, ParticleKey *par, float *par_rot, ParticleKey *child, float flat, float radius)
 {
 	copy_v3_v3(child->co, cpa->fuv);
@@ -2141,38 +2127,6 @@ void psys_find_parents(ParticleSimulationData *sim)
 	BLI_kdtree_free(tree);
 }
 
-static void get_strand_normal(Material *ma, const float surfnor[3], float surfdist, float nor[3])
-{
-	float cross[3], nstrand[3], vnor[3], blend;
-
-	if (!((ma->mode & MA_STR_SURFDIFF) || (ma->strand_surfnor > 0.0f)))
-		return;
-
-	if (ma->mode & MA_STR_SURFDIFF) {
-		cross_v3_v3v3(cross, surfnor, nor);
-		cross_v3_v3v3(nstrand, nor, cross);
-
-		blend = dot_v3v3(nstrand, surfnor);
-		CLAMP(blend, 0.0f, 1.0f);
-
-		interp_v3_v3v3(vnor, nstrand, surfnor, blend);
-		normalize_v3(vnor);
-	}
-	else {
-		copy_v3_v3(vnor, nor);
-	}
-	
-	if (ma->strand_surfnor > 0.0f) {
-		if (ma->strand_surfnor > surfdist) {
-			blend = (ma->strand_surfnor - surfdist) / ma->strand_surfnor;
-			interp_v3_v3v3(vnor, vnor, surfnor, blend);
-			normalize_v3(vnor);
-		}
-	}
-
-	copy_v3_v3(nor, vnor);
-}
-
 static bool psys_thread_context_init_path(ParticleThreadContext *ctx, ParticleSimulationData *sim, Scene *scene, float cfra, int editupdate)
 {
 	ParticleSystem *psys = sim->psys;
@@ -2257,8 +2211,7 @@ static void psys_thread_create_path(ParticleTask *task, struct ChildParticle *cp
 	ParticleCacheKey *child, *par = NULL, *key[4];
 	ParticleTexture ptex;
 	float *cpa_fuv = 0, *par_rot = 0, rot[4];
-	float orco[3], ornor[3], hairmat[4][4], t, dvec[3], off1[4][3], off2[4][3];
-	float length, max_length = 1.0f, cur_length = 0.0f;
+	float orco[3], ornor[3], hairmat[4][4], dvec[3], off1[4][3], off2[4][3];
 	float eff_length, eff_vec[3], weight[4];
 	int k, cpa_num;
 	short cpa_from;
@@ -2456,6 +2409,18 @@ static void psys_thread_create_path(ParticleTask *task, struct ChildParticle *cp
 		}
 	}
 
+	if (ctx->totparent)
+		/* this is now threadsafe, virtual parents are calculated before rest of children */
+		par = (i >= ctx->totparent) ? cache[cpa->parent] : NULL;
+	else if (cpa->parent >= 0)
+		par = pcache[cpa->parent];
+	
+	{
+		ListBase modifiers;
+		BLI_listbase_clear(&modifiers);
+		psys_apply_child_modifiers(ctx, &modifiers, cpa, &ptex, orco, ornor, hairmat, child_keys, par);
+	}
+#if 0
 	for (k = 0, child = child_keys; k <= ctx->steps; k++, child++) {
 		t = (float)k / (float)ctx->steps;
 
@@ -2508,6 +2473,7 @@ static void psys_thread_create_path(ParticleTask *task, struct ChildParticle *cp
 			get_strand_normal(ctx->ma, ornor, cur_length, child->vel);
 		}
 	}
+#endif
 
 	/* Hide virtual parents */
 	if (i < ctx->totparent)
@@ -3777,7 +3743,7 @@ static void get_child_modifier_parameters(ParticleSettings *part, ParticleThread
 	if (ctx->vg_effector)
 		ptex->effector *= psys_interpolate_value_from_verts(ctx->dm, cpa_from, cpa_num, cpa_fuv, ctx->vg_effector);
 }
-static void do_child_modifiers(ParticleSimulationData *sim, ParticleTexture *ptex, ParticleKey *par, float *par_rot, ChildParticle *cpa, float *orco, float mat[4][4], ParticleKey *state, float t)
+void do_child_modifiers(ParticleSimulationData *sim, ParticleTexture *ptex, ParticleKey *par, float *par_rot, ChildParticle *cpa, const float orco[3], float mat[4][4], ParticleKey *state, float t)
 {
 	ParticleSettings *part = sim->psys->part;
 	int i = cpa - sim->psys->child;
diff --git a/source/blender/blenkernel/intern/particle_child.c b/source/blender/blenkernel/intern/particle_child.c
new file mode 100644
index 0000000..135ec78
--- /dev/null
+++ b/source/blender/blenkernel/intern/particle_child.c
@@ -0,0 +1,193 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/particle_child.c
+ *  \ingroup bke
+ */
+
+#include "BLI_math.h"
+
+#include "DNA_material_types.h"
+
+#include "BKE_particle.h"
+
+struct Material;
+
+extern void do_child_modifiers(ParticleSimulationData *sim, ParticleTexture *ptex, ParticleKey *par, float *par_rot, 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])
+{
+	float cross[3], nstrand[3], vnor[3], blend;
+
+	if (!((ma->mode & MA_STR_SURFDIFF) || (ma->strand_surfnor > 0.0f)))
+		return;
+
+	if (ma->mode & MA_STR_SURFDIFF) {
+		cross_v3_v3v3(cross, surfnor, nor);
+		cross_v3_v3v3(nstrand, nor, cross);
+
+		blend = dot_v3v3(nstrand, surfnor);
+		CLAMP(blend, 0.0f, 1.0f);
+
+		interp_v3_v3v3(vnor, nstrand, surfnor, blend);
+		normalize_v3(vnor);
+	}
+	else {
+		copy_v3_v3(vnor, nor);
+	}
+	
+	if (ma->strand_surfnor > 0.0f) {
+		if (ma->strand_surfnor > surfdist) {
+			blend = (ma->strand_surfnor - surfdist) / ma->strand_surfnor;
+			interp_v3_v3v3(vnor, vnor, surfnor, blend);
+			normalize_v3(vnor);
+		}
+	}
+
+	copy_v3_v3(nor, vnor);
+}
+
+/* ------------------------------------------------------------------------- */
+
+typedef struct ParticlePathIterator {
+	ParticleCacheKey *key;
+	int index;
+	float time;
+	
+	ParticleCacheKey *parent_key;
+	float parent_rotation[4];
+} ParticlePathIterator;
+
+static void psys_path_iter_get(ParticlePathIterator *iter, ParticleCacheKey *keys, int totkeys, ParticleCacheKey *parent, int index)
+{
+	BLI_assert(index >= 0 && index < totkeys);
+	
+	iter->key = keys + index;
+	iter->index = index;
+	iter->time = (float)index / (float)(totkeys - 1);
+	
+	if (parent) {
+		iter->parent_key = parent + index;
+		if (index > 0)
+			mul_qt_qtqt(iter->parent_rotation, iter->parent_key->rot, parent->rot);
+		else
+			copy_qt_qt(iter->parent_rotation, parent->rot);
+	}
+	else {
+		iter->parent_ke

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list