[Bf-blender-cvs] [3ba96b7c4da] hair_guides: Add a hair system to particles to eventually replace the current pathcaches.

Lukas Tönne noreply at git.blender.org
Fri May 18 10:55:29 CEST 2018


Commit: 3ba96b7c4da8aa3461db5985b8d5c762695d49e2
Author: Lukas Tönne
Date:   Thu May 17 09:36:12 2018 +0100
Branches: hair_guides
https://developer.blender.org/rB3ba96b7c4da8aa3461db5985b8d5c762695d49e2

Add a hair system to particles to eventually replace the current pathcaches.

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

M	source/blender/blenkernel/BKE_hair.h
M	source/blender/blenkernel/intern/hair.c
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/blenloader/intern/writefile.c
M	source/blender/makesdna/DNA_particle_types.h

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

diff --git a/source/blender/blenkernel/BKE_hair.h b/source/blender/blenkernel/BKE_hair.h
index 08a28593712..34eb9d2df3a 100644
--- a/source/blender/blenkernel/BKE_hair.h
+++ b/source/blender/blenkernel/BKE_hair.h
@@ -81,6 +81,10 @@ void BKE_hair_set_guide_vertex(struct HairSystem *hsys, int index, int flag, con
  */
 void BKE_hair_set_hair_guides(struct HairSystem *hsys, struct HairGuideData *guides);
 
+/* Remove all guide curves.
+ */
+void BKE_hair_clear_guides(struct HairSystem *hsys);
+
 /* === Follicles === */
 
 /* Calculate surface area of a scalp mesh */
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index d6291dfa71f..2b0d95f83ad 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -285,13 +285,35 @@ void BKE_hair_set_hair_guides(HairSystem *hsys, HairGuideData *guides)
 	hsys->guides.verts = MEM_dupallocN(hsys->guides.verts);
 	hsys->guides.totverts = guides->totverts;
 
+#ifndef NDEBUG
 	const int vertcount = hair_guide_calc_vertstart(hsys);
 	BLI_assert(vertcount <= hsys->guides.totverts);
+#endif
 
 	hsys->flag |= HAIR_SYSTEM_UPDATE_FOLLICLE_BINDING;
 	BKE_hair_batch_cache_dirty(hsys, BKE_HAIR_BATCH_DIRTY_ALL);
 }
 
+void BKE_hair_clear_guides(HairSystem *hsys)
+{
+	if (hsys->guides.curves)
+	{
+		MEM_freeN(hsys->guides.curves);
+		hsys->guides.curves = NULL;
+	}
+	hsys->guides.totcurves = 0;
+
+	if (hsys->guides.verts)
+	{
+		MEM_freeN(hsys->guides.verts);
+		hsys->guides.verts = NULL;
+	}
+	hsys->guides.totverts = 0;
+
+	hsys->flag &= ~HAIR_SYSTEM_UPDATE_FOLLICLE_BINDING;
+	BKE_hair_batch_cache_dirty(hsys, BKE_HAIR_BATCH_DIRTY_ALL);
+}
+
 /* ================================= */
 
 BLI_INLINE void hair_fiber_verify_weights(HairFollicle *follicle)
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 3e4b646bcbb..63c7524ff2b 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -75,6 +75,7 @@
 #include "BKE_main.h"
 #include "BKE_global.h"
 #include "BKE_groom.h"
+#include "BKE_hair.h"
 #include "BKE_idprop.h"
 #include "BKE_armature.h"
 #include "BKE_action.h"
@@ -867,6 +868,10 @@ ParticleSystem *BKE_object_copy_particlesystem(ParticleSystem *psys, const int f
 		for (p = 0, pa = psysn->particles; p < psysn->totpart; p++, pa++)
 			pa->hair = MEM_dupallocN(pa->hair);
 	}
+	if (psys->hair_system)
+	{
+		psys->hair_system = BKE_hair_copy(psys->hair_system);
+	}
 
 	if (psysn->particles && (psysn->particles->keys || psysn->particles->boid)) {
 		ParticleKey *key = psysn->particles->keys;
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index c8e96285923..874fe56f613 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -68,6 +68,7 @@
 #include "BKE_effect.h"
 #include "BKE_global.h"
 #include "BKE_group.h"
+#include "BKE_hair.h"
 #include "BKE_main.h"
 #include "BKE_lattice.h"
 
@@ -440,6 +441,11 @@ void free_hair(Object *UNUSED(ob), ParticleSystem *psys, int dynamics)
 		pa->hair = NULL;
 		pa->totkey = 0;
 	}
+	if (psys->hair_system)
+	{
+		BKE_hair_free(psys->hair_system);
+	}
+	psys->hair_system = NULL;
 
 	psys->flag &= ~PSYS_HAIR_DONE;
 
@@ -539,6 +545,11 @@ void psys_free_particles(ParticleSystem *psys)
 		psys->particles = NULL;
 		psys->totpart = 0;
 	}
+
+	if (psys->hair_system)
+	{
+		BKE_hair_clear_guides(psys->hair_system);
+	}
 }
 void psys_free_pdd(ParticleSystem *psys)
 {
@@ -2567,6 +2578,8 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re
 
 	psys->totcached = totpart;
 
+	// TODO update hair export cache
+
 	if (psys->lattice_deform_data) {
 		end_latt_deform(psys->lattice_deform_data);
 		psys->lattice_deform_data = NULL;
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index bc3218723ac..7265fb81026 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -74,6 +74,7 @@
 #include "BKE_collision.h"
 #include "BKE_colortools.h"
 #include "BKE_effect.h"
+#include "BKE_hair.h"
 #include "BKE_library_query.h"
 #include "BKE_particle.h"
 
@@ -4109,6 +4110,11 @@ void psys_changed_type(Object *ob, ParticleSystem *psys)
 		CLAMP(part->path_end, 0.0f, 100.0f);
 
 		BKE_ptcache_id_clear(&pid, PTCACHE_CLEAR_ALL, 0);
+
+		if (!psys->hair_system)
+		{
+			psys->hair_system = BKE_hair_new();
+		}
 	}
 	else {
 		free_hair(ob, psys, 1);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 140e66a4572..33143bf5a49 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4197,6 +4197,25 @@ static void direct_link_pointcache_list(FileData *fd, ListBase *ptcaches, PointC
 	}
 }
 
+static void direct_link_hair(FileData *fd, HairSystem* hsys)
+{
+	if (!hsys) {
+		return;
+	}
+	
+	hsys->pattern = newdataadr(fd, hsys->pattern);
+	if ( hsys->pattern )
+	{
+		hsys->pattern->follicles = newdataadr(fd, hsys->pattern->follicles);
+	}
+	
+	hsys->guides.curves = newdataadr(fd, hsys->guides.curves);
+	hsys->guides.verts = newdataadr(fd, hsys->guides.verts);
+	
+	hsys->draw_batch_cache = NULL;
+	hsys->draw_texture_cache = NULL;
+}
+
 static void lib_link_partdeflect(FileData *fd, ID *id, PartDeflect *pd)
 {
 	if (pd && pd->tex)
@@ -4413,6 +4432,10 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles)
 			for (a=0, pa=psys->particles; a<psys->totpart; a++, pa++)
 				pa->hair=newdataadr(fd, pa->hair);
 		}
+		if (psys->hair_system)
+		{
+			direct_link_hair(fd, psys->hair_system);
+		}
 		
 		if (psys->particles && psys->particles->keys) {
 			for (a=0, pa=psys->particles; a<psys->totpart; a++, pa++) {
@@ -5010,25 +5033,6 @@ static void direct_link_pose(FileData *fd, bPose *pose)
 	}
 }
 
-static void direct_link_hair(FileData *fd, HairSystem* hsys)
-{
-	if (!hsys) {
-		return;
-	}
-	
-	hsys->pattern = newdataadr(fd, hsys->pattern);
-	if ( hsys->pattern )
-	{
-		hsys->pattern->follicles = newdataadr(fd, hsys->pattern->follicles);
-	}
-	
-	hsys->guides.curves = newdataadr(fd, hsys->guides.curves);
-	hsys->guides.verts = newdataadr(fd, hsys->guides.verts);
-	
-	hsys->draw_batch_cache = NULL;
-	hsys->draw_texture_cache = NULL;
-}
-
 static void direct_link_modifiers(FileData *fd, ListBase *lb)
 {
 	ModifierData *md;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index d61f9996408..56be0178db6 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1353,6 +1353,18 @@ static void write_pointcaches(WriteData *wd, ListBase *ptcaches)
 	}
 }
 
+static void write_hair(WriteData *wd, HairSystem *hsys)
+{
+	if ( hsys->pattern )
+	{
+		writestruct(wd, DATA, HairPattern, 1, hsys->pattern);
+		writestruct(wd, DATA, HairFollicle, hsys->pattern->num_follicles, hsys->pattern->follicles);
+	}
+	
+	writestruct(wd, DATA, HairGuideCurve, hsys->guides.totcurves, hsys->guides.curves);
+	writestruct(wd, DATA, HairGuideVertex, hsys->guides.totverts, hsys->guides.verts);
+}
+
 static void write_particlesettings(WriteData *wd, ParticleSettings *part)
 {
 	if (part->id.us > 0 || wd->use_memfile) {
@@ -1432,6 +1444,10 @@ static void write_particlesystems(WriteData *wd, ListBase *particles)
 					writestruct(wd, DATA, HairKey, pa->totkey, pa->hair);
 				}
 			}
+			if (psys->hair_system)
+			{
+				write_hair(wd, psys->hair_system);
+			}
 
 			if (psys->particles->boid &&
 			    (psys->part->phystype == PART_PHYS_BOIDS))
@@ -1590,18 +1606,6 @@ static void write_fmaps(WriteData *wd, ListBase *fbase)
 	}
 }
 
-static void write_hair(WriteData *wd, HairSystem *hsys)
-{
-	if ( hsys->pattern )
-	{
-		writestruct(wd, DATA, HairPattern, 1, hsys->pattern);
-		writestruct(wd, DATA, HairFollicle, hsys->pattern->num_follicles, hsys->pattern->follicles);
-	}
-	
-	writestruct(wd, DATA, HairGuideCurve, hsys->guides.totcurves, hsys->guides.curves);
-	writestruct(wd, DATA, HairGuideVertex, hsys->guides.totverts, hsys->guides.verts);
-}
-
 static void write_modifiers(WriteData *wd, ListBase *modbase)
 {
 	ModifierData *md;
diff --git a/source/blender/makesdna/DNA_particle_types.h b/source/blender/makesdna/DNA_particle_types.h
index 2c330501820..4c63fe8d649 100644
--- a/source/blender/makesdna/DNA_particle_types.h
+++ b/source/blender/makesdna/DNA_particle_types.h
@@ -282,6 +282,7 @@ typedef struct ParticleSystem {
 	struct ParticleCacheKey **pathcache;	/* path cache (runtime) */
 	struct ParticleCacheKey **childcache;	/* child cache (runtime) */
 	ListBase pathcachebufs, childcachebufs;	/* buffers for the above */
+	struct HairSystem *hair_system;			/* Hair data for drawing and rendering */
 
 	struct ClothModifierData *clmd;					/* cloth simulation for hair */
 	struct DerivedMesh *hair_in_dm, *hair_out_dm;	/* input/output for cloth simulation */



More information about the Bf-blender-cvs mailing list