[Bf-blender-cvs] [45f30a9fdbc] hair_guides: Restructure the hair modifier so external tools define guide curves.

Lukas Tönne noreply at git.blender.org
Fri Nov 10 10:31:51 CET 2017


Commit: 45f30a9fdbc5bf57a0aa0fb2409aec3f37256ad5
Author: Lukas Tönne
Date:   Fri Nov 10 08:23:03 2017 +0000
Branches: hair_guides
https://developer.blender.org/rB45f30a9fdbc5bf57a0aa0fb2409aec3f37256ad5

Restructure the hair modifier so external tools define guide curves.

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

M	source/blender/blenkernel/BKE_hair.h
M	source/blender/blenkernel/intern/hair.c
M	source/blender/blenkernel/intern/hair_draw.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/draw/engines/eevee/eevee_materials.c
M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache.h
M	source/blender/draw/intern/draw_cache_impl.h
M	source/blender/draw/intern/draw_cache_impl_hair.c
M	source/blender/makesdna/DNA_hair_types.h
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_hair.c
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_hair.c

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

diff --git a/source/blender/blenkernel/BKE_hair.h b/source/blender/blenkernel/BKE_hair.h
index 94ec9ff80cc..bb94c7f8802 100644
--- a/source/blender/blenkernel/BKE_hair.h
+++ b/source/blender/blenkernel/BKE_hair.h
@@ -34,61 +34,39 @@
 
 #include "BLI_utildefines.h"
 
+static const unsigned int HAIR_STRAND_INDEX_NONE = 0xFFFFFFFF;
+
 struct HairFollicle;
 struct HairPattern;
-struct HairGroup;
 struct DerivedMesh;
 
-static const unsigned int STRAND_INDEX_NONE = 0xFFFFFFFF;
-
-struct HairPattern* BKE_hair_new(void);
-struct HairPattern* BKE_hair_copy(struct HairPattern *hair);
-void BKE_hair_free(struct HairPattern *hair);
-
-void BKE_hair_set_num_follicles(struct HairPattern *hair, int count);
-void BKE_hair_follicles_generate(struct HairPattern *hair, struct DerivedMesh *scalp, int count, unsigned int seed);
-
-struct HairGroup* BKE_hair_group_new(struct HairPattern *hair, int type);
-void BKE_hair_group_remove(struct HairPattern *hair, struct HairGroup *group);
-struct HairGroup* BKE_hair_group_copy(struct HairPattern *hair, struct HairGroup *group);
-void BKE_hair_group_moveto(struct HairPattern *hair, struct HairGroup *group, int position);
-
-void BKE_hair_group_name_set(struct HairPattern *hair, struct HairGroup *group, const char *name);
-
-void BKE_hair_update_groups(struct HairPattern *hair);
+struct HairSystem* BKE_hair_new(void);
+struct HairSystem* BKE_hair_copy(struct HairSystem *hsys);
+void BKE_hair_free(struct HairSystem *hsys);
 
-/* === Draw Buffer Texture === */
+void BKE_hair_generate_follicles(struct HairSystem* hsys, unsigned int seed);
 
-typedef struct HairDrawDataInterface {
-	const struct HairGroup *group;
-	struct DerivedMesh *scalp;
-	
-	int (*get_num_strands)(const struct HairDrawDataInterface* hairdata);
-	int (*get_num_verts)(const struct HairDrawDataInterface* hairdata);
-	
-	void (*get_strand_lengths)(const struct HairDrawDataInterface* hairdata, int *r_lengths);
-	void (*get_strand_roots)(const struct HairDrawDataInterface* hairdata, struct MeshSample *r_roots);
-	void (*get_strand_vertices)(const struct HairDrawDataInterface* hairdata, float (*r_positions)[3]);
-} HairDrawDataInterface;
+/* === Guide Strands === */
 
-int* BKE_hair_strands_get_fiber_lengths(const struct HairDrawDataInterface *hairdata, int subdiv);
-void BKE_hair_strands_get_texture_buffer_size(const struct HairDrawDataInterface *hairdata, int subdiv,
-                                              int *r_size, int *r_strand_map_start,
-                                              int *r_strand_vertex_start, int *r_fiber_start);
-void BKE_hair_strands_get_texture_buffer(const struct HairDrawDataInterface *hairdata, int subdiv, void *texbuffer);
+struct DerivedMesh* BKE_hair_get_scalp(const struct HairSystem *hsys);
+int BKE_hair_get_num_strands(const struct HairSystem *hsys);
+int BKE_hair_get_num_strands_verts(const struct HairSystem *hsys);
+void BKE_hair_get_strand_lengths(const struct HairSystem *hsys, int *r_lengths);
+void BKE_hair_get_strand_roots(const struct HairSystem *hsys, struct MeshSample *r_roots);
+void BKE_hair_get_strand_vertices(const struct HairSystem *hsys, float (*r_positions)[3]);
+void BKE_hair_get_follicle_weights(const struct HairSystem *hsys, unsigned int (*r_parents)[4], float (*r_weights)[4]);
 
 /* === Draw Cache === */
 
 enum {
 	BKE_HAIR_BATCH_DIRTY_ALL = 0,
 };
-void BKE_hair_batch_cache_dirty(struct HairGroup *group, int mode);
-void BKE_hair_batch_cache_all_dirty(struct HairPattern *hair, int mode);
-void BKE_hair_batch_cache_free(struct HairGroup *group);
+void BKE_hair_batch_cache_dirty(struct HairSystem* hsys, int mode);
+void BKE_hair_batch_cache_free(struct HairSystem* hsys);
 
-int* BKE_hair_group_get_fiber_lengths(struct HairGroup *group, struct DerivedMesh *scalp, int subdiv);
-void BKE_hair_group_get_texture_buffer_size(struct HairGroup *group, struct DerivedMesh *scalp, int subdiv,
-                                            int *r_size, int *r_strand_map_start, int *r_strand_vertex_start, int *r_fiber_start);
-void BKE_hair_group_get_texture_buffer(struct HairGroup *group, struct DerivedMesh *scalp, int subdiv, void *texbuffer);
+int* BKE_hair_get_fiber_lengths(const struct HairSystem* hsys, int subdiv);
+void BKE_hair_get_texture_buffer_size(const struct HairSystem* hsys, int subdiv,
+                                              int *r_size, int *r_strand_map_start, int *r_strand_vertex_start, int *r_fiber_start);
+void BKE_hair_get_texture_buffer(const struct HairSystem* hsys, int subdiv, void *texbuffer);
 
 #endif
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index 48444b453f7..f904ff1e8c0 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -50,53 +50,41 @@
 
 #include "BLT_translation.h"
 
-HairPattern* BKE_hair_new(void)
+HairSystem* BKE_hair_new(void)
 {
-	HairPattern *hair = MEM_callocN(sizeof(HairPattern), "hair");
-	
-	/* add a default hair group */
-	BKE_hair_group_new(hair, HAIR_GROUP_TYPE_NORMALS);
+	HairSystem *hair = MEM_callocN(sizeof(HairSystem), "hair system");
 	
 	return hair;
 }
 
-HairPattern* BKE_hair_copy(HairPattern *hair)
-{
-	HairPattern *nhair = MEM_dupallocN(hair);
-	
-	nhair->follicles = MEM_dupallocN(hair->follicles);
-	
-	BLI_duplicatelist(&nhair->groups, &hair->groups);
-	
-	return nhair;
-}
-
-static void hair_group_free(HairGroup *group)
+HairSystem* BKE_hair_copy(HairSystem *hsys)
 {
-	BKE_hair_batch_cache_free(group);
+	HairSystem *nhsys = MEM_dupallocN(hsys);
 	
-	if (group->strands_parent_index) {
-		MEM_freeN(group->strands_parent_index);
-	}
-	if (group->strands_parent_weight) {
-		MEM_freeN(group->strands_parent_weight);
+	if (hsys->pattern)
+	{
+		nhsys->pattern = MEM_dupallocN(hsys->pattern);
+		nhsys->pattern->follicles = MEM_dupallocN(hsys->pattern->follicles);
 	}
+	
+	return nhsys;
 }
 
-void BKE_hair_free(struct HairPattern *hair)
+void BKE_hair_free(HairSystem *hsys)
 {
-	if (hair->follicles) {
-		MEM_freeN(hair->follicles);
-	}
-	
-	for (HairGroup *group = hair->groups.first; group; group = group->next) {
-		hair_group_free(group);
+	if (hsys->pattern)
+	{
+		if (hsys->pattern->follicles)
+		{
+			MEM_freeN(hsys->pattern->follicles);
+		}
+		MEM_freeN(hsys->pattern);
 	}
-	BLI_freelistN(&hair->groups);
 	
-	MEM_freeN(hair);
+	MEM_freeN(hsys);
 }
 
+#if 0
 void BKE_hair_set_num_follicles(HairPattern *hair, int count)
 {
 	if (hair->num_follicles != count) {
@@ -141,315 +129,10 @@ void BKE_hair_follicles_generate(HairPattern *hair, DerivedMesh *scalp, int coun
 	
 	BKE_mesh_sample_free_generator(gen);
 	
-	BKE_hair_batch_cache_all_dirty(hair, BKE_HAIR_BATCH_DIRTY_ALL);
+	BKE_hair_batch_cache_dirty(hair, BKE_HAIR_BATCH_DIRTY_ALL);
 	
 	BKE_hair_update_groups(hair);
 }
-
-HairGroup* BKE_hair_group_new(HairPattern *hair, int type)
-{
-	HairGroup *group = MEM_callocN(sizeof(HairGroup), "hair group");
-	
-	group->type = type;
-	BKE_hair_group_name_set(hair, group, DATA_("Group"));
-	
-	switch (type) {
-		case HAIR_GROUP_TYPE_NORMALS:
-			group->normals_max_length = 0.1f;
-			break;
-		case HAIR_GROUP_TYPE_STRANDS:
-			break;
-	}
-	
-	BLI_addtail(&hair->groups, group);
-	
-	return group;
-}
-
-void BKE_hair_group_remove(HairPattern *hair, HairGroup *group)
-{
-	if (!group) {
-		return;
-	}
-	BLI_assert(BLI_findindex(&hair->groups, group) >= 0);
-	
-	BLI_remlink(&hair->groups, group);
-	
-	hair_group_free(group);
-	MEM_freeN(group);
-}
-
-HairGroup* BKE_hair_group_copy(HairPattern *hair, HairGroup *group)
-{
-	if (!group) {
-		return NULL;
-	}
-	
-	HairGroup *ngroup = MEM_dupallocN(group);
-	
-	BLI_insertlinkafter(&hair->groups, group, ngroup);
-	return ngroup;
-}
-
-void BKE_hair_group_moveto(HairPattern *hair, HairGroup *group, int position)
-{
-	if (!group) {
-		return;
-	}
-	BLI_assert(BLI_findindex(&hair->groups, group) >= 0);
-	
-	BLI_remlink(&hair->groups, group);
-	BLI_insertlinkbefore(&hair->groups, BLI_findlink(&hair->groups, position), group);
-}
-
-void BKE_hair_group_name_set(HairPattern *hair, HairGroup *group, const char *name)
-{
-	BLI_strncpy_utf8(group->name, name, sizeof(group->name));
-	BLI_uniquename(&hair->groups, group, DATA_("Group"), '.', offsetof(HairGroup, name), sizeof(group->name));
-}
-
-#define HAIR_FOLLICLE_GROUP_NONE INT_MAX
-
-static void hair_claim_group_follicle(HairGroup *group, int group_index, int *follicle_group, int i)
-{
-	if (follicle_group[i] == HAIR_FOLLICLE_GROUP_NONE) {
-		follicle_group[i] = group_index;
-		++group->num_follicles;
-	}
-}
-
-static void hair_group_follicles_normals(HairPattern *hair, HairGroup *group, int group_index, int *follicle_group)
-{
-	const int num_follicles = hair->num_follicles;
-	for (int i = 0; i < num_follicles; ++i) {
-		// claim all
-		hair_claim_group_follicle(group, group_index, follicle_group, i);
-	}
-}
-
-static void hair_group_follicles_strands(HairPattern *hair, HairGroup *group, int group_index, int *follicle_group)
-{
-	// TODO
-	UNUSED_VARS(hair, group, group_index, follicle_group);
-}
-
-typedef struct HairFollicleSortContext {
-	const HairFollicle *start;
-	const int *follicle_group;
-} HairFollicleSortContext;
-
-static int cmpHairFollicleByGroup(const void *a, const void *b, void *ctx_)
-{
-	const HairFollicleSortContext *ctx = (const HairFollicleSortContext *)ctx_;
-	const size_t ia = (const HairFollicle *)a - ctx->start;
-	const size_t ib = (const HairFollicle *)b - ctx->start;
-	return ctx->follicle_group[ib] - ctx->follicle_group[ia];
-}
-
-void BKE_hair_update_groups(HairPattern *hair)
-{
-	const int num_follicles = hair->num_follicles;
-	int *follicle_group = MEM_mallocN(sizeof(int) * num_follicles, "hair follicle group index");
-	for (int i = 0; i < num_follicles; ++i) {
-		follicle_group[i] = HAIR_FOLLICLE_GROUP_NONE;
-	}
-	
-	int group_index = 0;
-	for (HairGroup *group = hair->groups.first; group; group = group->next, ++group_index) {
-		// Note: follicles array is sorted below
-		if (group->prev) {
-			group->follicles = group->prev->follicles + group->prev->num_follicles;
-		}
-		else {
-			group->follicles = hair->follicles;
-		}
-		
-		group->num_follicles = 0;
-		switch (group->type) {
-			case HAIR_GROUP_TYPE_NORMALS:
-				hair_group_follicles_normal

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list