[Bf-blender-cvs] [6fa838f6d30] strand_editmode: List of 'Hair Groups' in hair patterns that will generate actual fibers for rendering.

Lukas Tönne noreply at git.blender.org
Mon Aug 7 19:07:54 CEST 2017


Commit: 6fa838f6d30a9b1936416f54b4a637e86e04b2e1
Author: Lukas Tönne
Date:   Mon Aug 7 18:04:30 2017 +0100
Branches: strand_editmode
https://developer.blender.org/rB6fa838f6d30a9b1936416f54b4a637e86e04b2e1

List of 'Hair Groups' in hair patterns that will generate actual fibers for rendering.

Each group affects a subset of the hair follicles, so that multiple effects can be combined
without overlapping sample sets.

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

M	release/scripts/startup/bl_ui/__init__.py
M	release/scripts/startup/bl_ui/properties_data_modifier.py
A	release/scripts/startup/bl_ui/properties_hair.py
M	source/blender/blenkernel/BKE_hair.h
M	source/blender/blenkernel/intern/hair.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/makesdna/DNA_hair_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_hair.c

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

diff --git a/release/scripts/startup/bl_ui/__init__.py b/release/scripts/startup/bl_ui/__init__.py
index cc3d1ffc229..93103249522 100644
--- a/release/scripts/startup/bl_ui/__init__.py
+++ b/release/scripts/startup/bl_ui/__init__.py
@@ -43,6 +43,7 @@ _modules = [
     "properties_data_lightprobe",
     "properties_data_speaker",
     "properties_game",
+    "properties_hair",
     "properties_mask_common",
     "properties_material",
     "properties_object",
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 3bd7d434aeb..b162d23e679 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1533,11 +1533,19 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
 
         col = layout.column()
         col.label(text="Follicles:")
-        row = col.row(align = True)
-        row.enabled = False
-        row.prop(hair, "num_follicles")
+        col.label(text="Count: %d" % len(hair.follicles))
         col.operator("object.hair_follicles_generate", text="Generate")
 
+        col = layout.column()
+        col.template_list("HAIR_UL_groups", "", hair, "groups", hair, "active_group_index")
+
+        layout.separator()
+
+        group = hair.active_group
+        if group:
+            col = layout.column()
+            col.prop(group, "type")
+
 
 classes = (
     DATA_PT_modifiers,
diff --git a/release/scripts/startup/bl_ui/properties_hair.py b/release/scripts/startup/bl_ui/properties_hair.py
new file mode 100644
index 00000000000..2d234bf3f94
--- /dev/null
+++ b/release/scripts/startup/bl_ui/properties_hair.py
@@ -0,0 +1,40 @@
+# ##### 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.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+import bpy
+from bpy.types import UIList
+
+class HAIR_UL_groups(UIList):
+    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
+        group = item
+        if self.layout_type in {'DEFAULT', 'COMPACT'}:
+            layout.prop(group, "name", text="", emboss=False, icon_value=icon)
+        elif self.layout_type == 'GRID':
+            layout.alignment = 'CENTER'
+            layout.label(text="", icon_value=icon)
+
+
+classes = (
+    HAIR_UL_groups,
+)
+
+if __name__ == "__main__":  # only for live edit.
+    from bpy.utils import register_class
+    for cls in classes:
+        register_class(cls)
diff --git a/source/blender/blenkernel/BKE_hair.h b/source/blender/blenkernel/BKE_hair.h
index 1f96cdcb81b..0fa44b3de66 100644
--- a/source/blender/blenkernel/BKE_hair.h
+++ b/source/blender/blenkernel/BKE_hair.h
@@ -36,6 +36,7 @@
 
 struct HairFollicle;
 struct HairPattern;
+struct HairGroup;
 struct DerivedMesh;
 
 static const unsigned int STRAND_INDEX_NONE = 0xFFFFFFFF;
@@ -47,6 +48,13 @@ 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);
+
 /* ================================= */
 
 typedef struct HairFiber {
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index fa8bf398cd7..3802d5499f1 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -36,6 +36,7 @@
 #include "BLI_math.h"
 #include "BLI_kdtree.h"
 #include "BLI_rand.h"
+#include "BLI_string_utils.h"
 
 #include "DNA_hair_types.h"
 
@@ -43,25 +44,29 @@
 #include "BKE_mesh_sample.h"
 #include "BKE_hair.h"
 
+#include "BLT_translation.h"
+
 #include "bmesh.h"
 
 HairPattern* BKE_hair_new(void)
 {
-	HairPattern *hair = MEM_mallocN(sizeof(HairPattern), "hair");
+	HairPattern *hair = MEM_callocN(sizeof(HairPattern), "hair");
 	
-	hair->follicles = NULL;
-	hair->num_follicles = 0;
+	/* add a default hair group */
+	BKE_hair_group_new(hair, HAIR_GROUP_TYPE_NORMALS);
 	
 	return hair;
 }
 
 HairPattern* BKE_hair_copy(HairPattern *hair)
 {
-	HairPattern *newhair = MEM_dupallocN(hair);
+	HairPattern *nhair = MEM_dupallocN(hair);
+	
+	nhair->follicles = MEM_dupallocN(hair->follicles);
 	
-	newhair->follicles = MEM_dupallocN(hair->follicles);
+	BLI_duplicatelist(&nhair->groups, &hair->groups);
 	
-	return newhair;
+	return nhair;
 }
 
 void BKE_hair_free(struct HairPattern *hair)
@@ -70,6 +75,8 @@ void BKE_hair_free(struct HairPattern *hair)
 		MEM_freeN(hair->follicles);
 	}
 	
+	BLI_freelistN(&hair->groups);
+	
 	MEM_freeN(hair);
 }
 
@@ -117,6 +124,67 @@ void BKE_hair_follicles_generate(HairPattern *hair, DerivedMesh *scalp, int coun
 	BKE_mesh_sample_free_generator(gen);
 }
 
+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->max_length = 0.1f;
+			break;
+		case HAIR_GROUP_TYPE_STRANDS:
+			group->max_length = 0.5f;
+			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);
+	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));
+}
+
 /* ================================= */
 
 bool BKE_hair_fiber_get_location(const HairFiber *fiber, DerivedMesh *root_dm, float loc[3])
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index e71f593b530..44abe364c05 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5127,6 +5127,8 @@ static void direct_link_hair(FileData *fd, HairPattern *hair)
 	}
 	
 	hair->follicles = newdataadr(fd, hair->follicles);
+	
+	link_list(fd, &hair->groups);
 }
 
 static void direct_link_modifiers(FileData *fd, ListBase *lb)
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 2f7c64d3bd8..7425f6ae566 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1710,6 +1710,8 @@ static void write_fmaps(WriteData *wd, ListBase *fbase)
 static void write_hair(WriteData *wd, HairPattern *hair)
 {
 	writestruct(wd, DATA, HairPattern, hair->num_follicles, hair->follicles);
+	
+	writelist(wd, DATA, HairGroup, &hair->groups);
 }
 
 static void write_modifiers(WriteData *wd, ListBase *modbase)
diff --git a/source/blender/makesdna/DNA_hair_types.h b/source/blender/makesdna/DNA_hair_types.h
index 57619396e1b..5272731836a 100644
--- a/source/blender/makesdna/DNA_hair_types.h
+++ b/source/blender/makesdna/DNA_hair_types.h
@@ -47,9 +47,25 @@ typedef struct HairFollicle {
 typedef struct HairPattern {
 	struct HairFollicle *follicles;
 	int num_follicles;
-	int pad;
+	
+	int active_group;
+	ListBase groups;
 } HairPattern;
 
+typedef struct HairGroup {
+	struct HairGroup *next, *prev;
+	
+	char name[64]; /* MAX_NAME */
+	int type;
+	
+	float max_length;
+} HairGroup;
+
+typedef enum HairGroup_Type {
+	HAIR_GROUP_TYPE_NORMALS    = 1,
+	HAIR_GROUP_TYPE_STRANDS    = 2,
+} HairGroup_Type;
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 1c01b5b460d..74efd2e7ed2 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -283,7 +283,9 @@ extern StructRNA RNA_GaussianBlurSequence;
 extern StructRNA RNA_GlowSequence;
 extern StructRNA RNA_GreasePencil;
 extern StructRNA RNA_Group;
+extern StructRNA RNA_HairGroup;
 extern StructRNA RNA_HairModifier;
+extern StructRNA RNA_HairPattern;
 extern StructRNA RNA_Header;
 extern StructRNA RNA_HemiLamp;
 extern StructRNA RNA_Histogram;
diff --git a/source/blender/makesrna/intern/rna_hair.c b/source/blender/makesrna/intern/rna_hair.c
index 485d6797cc9..0fac022bcb8 100644
--- a/source/blender/makesrna/intern/rna_hair.c
+++ b/source/blender/makesrna/intern/rna_hair.c
@@ -39,25 +39,63 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_listbase.h"
+
+#include "DNA_modifier_types.h"
 #include "DNA_ob

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list