[Bf-blender-cvs] [22285859127] hair_guides: RNA collection and UI list for groom bundles.

Lukas Tönne noreply at git.blender.org
Thu Jan 4 10:42:54 CET 2018


Commit: 22285859127fd3260a0b657ddce0e0b3ec5319dc
Author: Lukas Tönne
Date:   Thu Jan 4 08:57:12 2018 +0000
Branches: hair_guides
https://developer.blender.org/rB22285859127fd3260a0b657ddce0e0b3ec5319dc

RNA collection and UI list for groom bundles.

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

M	release/scripts/startup/bl_ui/properties_data_groom.py
M	source/blender/makesdna/DNA_groom_types.h
M	source/blender/makesrna/intern/rna_groom.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_groom.py b/release/scripts/startup/bl_ui/properties_data_groom.py
index 75b3540a96c..5adee6b054c 100644
--- a/release/scripts/startup/bl_ui/properties_data_groom.py
+++ b/release/scripts/startup/bl_ui/properties_data_groom.py
@@ -22,6 +22,20 @@ from bpy.types import Menu, Panel
 from rna_prop_ui import PropertyPanel
 
 
+class GROOM_UL_bundles(bpy.types.UIList):
+    def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index, flt_flag):
+        ob = data
+        bundle = item
+
+        if self.layout_type in {'DEFAULT', 'COMPACT'}:
+            #layout.prop(groom, "name", text="", emboss=False, icon_value=icon)
+            layout.label(text="", icon_value=icon)
+
+        elif self.layout_type == 'GRID':
+            layout.alignment = 'CENTER'
+            layout.label(text="", icon_value=icon)
+
+
 class DataButtonsPanel:
     bl_space_type = 'PROPERTIES'
     bl_region_type = 'WINDOW'
@@ -59,6 +73,10 @@ class DATA_PT_groom(DataButtonsPanel, Panel):
 
         groom = context.groom
 
+        layout.template_list("GROOM_UL_bundles", "bundles",
+                             groom, "bundles",
+                             groom.bundles, "active_index")
+
         split = layout.split()
 
         col = split.column()
@@ -90,6 +108,7 @@ class DATA_PT_custom_props_groom(DataButtonsPanel, PropertyPanel, Panel):
 
 
 classes = (
+    GROOM_UL_bundles,
     DATA_PT_context_groom,
     DATA_PT_groom,
     DATA_PT_groom_draw_settings,
diff --git a/source/blender/makesdna/DNA_groom_types.h b/source/blender/makesdna/DNA_groom_types.h
index 91e9b86a426..a69348f1574 100644
--- a/source/blender/makesdna/DNA_groom_types.h
+++ b/source/blender/makesdna/DNA_groom_types.h
@@ -96,6 +96,11 @@ typedef struct GroomBundle {
 	struct GroomSectionVertex *verts;       /* List of vertices */
 	struct GroomCurveCache *curvecache;     /* Cached center curve */
 	struct GroomShapeCache *shapecache;     /* Cached 2D shape curves */
+	
+	/* Scalp Region */
+	/* XXX Vertex groups are used temporarily for creating regions,
+	 * eventually should be replaced by a fully fledged 2D loop mesh */
+	char scalp_vgroup_name[64];             /* Scalp vertex group to use as region, MAX_VGROUP_NAME */
 } GroomBundle;
 
 typedef enum GroomBundleFlag
@@ -116,15 +121,17 @@ typedef struct Groom {
 	int curve_res;              /* Curve resolution */
 	int pad;
 	
-	struct BoundBox *bb;
-	
 	ListBase bundles;           /* List of GroomBundle */
+	int active_bundle;          /* Index of active bundle in bundles list */
+	int pad2;
 	
 	struct HairSystem *hair_system;                 /* Renderable hair geometry */
 	struct HairDrawSettings *hair_draw_settings;    /* Draw settings for hair geometry */
 	
 	struct Object *scalp_object;                    /* Surface for attaching hairs */
 	
+	struct BoundBox *bb;
+	
 	EditGroom *editgroom;
 	void *batch_cache;
 } Groom;
diff --git a/source/blender/makesrna/intern/rna_groom.c b/source/blender/makesrna/intern/rna_groom.c
index b8966cf27a6..55efa8169c7 100644
--- a/source/blender/makesrna/intern/rna_groom.c
+++ b/source/blender/makesrna/intern/rna_groom.c
@@ -52,6 +52,9 @@
 
 #ifdef RNA_RUNTIME
 
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+
 #include "WM_api.h"
 
 #include "BKE_groom.h"
@@ -69,8 +72,98 @@ static void rna_Groom_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), Poi
 	WM_main_add_notifier(NC_GROOM | ND_DATA, ptr->id.data);
 }
 
+static void rna_GroomBundle_scalp_vgroup_name_set(PointerRNA *ptr, const char *value)
+{
+	Groom *groom = (Groom *)ptr->id.data;
+	GroomBundle *bundle = (GroomBundle *)ptr->data;
+	if (groom->scalp_object)
+	{
+		PointerRNA scalp_ptr;
+		RNA_id_pointer_create(&groom->scalp_object->id, &scalp_ptr);
+		rna_object_vgroup_name_set(&scalp_ptr, value, bundle->scalp_vgroup_name, sizeof(bundle->scalp_vgroup_name));
+	}
+	else
+	{
+		bundle->scalp_vgroup_name[0] = '\0';
+	}
+}
+
+static PointerRNA rna_Groom_active_bundle_get(PointerRNA *ptr)
+{
+	Groom *groom = (Groom *)ptr->id.data;
+	PointerRNA r_ptr;
+	RNA_pointer_create(&groom->id, &RNA_GroomBundle, BLI_findlink(&groom->bundles, groom->active_bundle), &r_ptr);
+	return r_ptr;
+}
+
+static int rna_Groom_active_bundle_index_get(PointerRNA *ptr)
+{
+	Groom *groom = (Groom *)ptr->id.data;
+	return groom->active_bundle;
+}
+
+static void rna_Groom_active_bundle_index_set(PointerRNA *ptr, int value)
+{
+	Groom *groom = (Groom *)ptr->id.data;
+	groom->active_bundle = value;
+}
+
+static void rna_Groom_active_bundle_index_range(
+        PointerRNA *ptr,
+        int *min,
+        int *max,
+        int *UNUSED(softmin),
+        int *UNUSED(softmax))
+{
+	Groom *groom = (Groom *)ptr->id.data;
+	*min = 0;
+	*max = max_ii(0, BLI_listbase_count(&groom->bundles) - 1);
+}
+
 #else
 
+static void rna_def_groom_bundle(BlenderRNA *brna)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+	
+	srna = RNA_def_struct(brna, "GroomBundle", NULL);
+	RNA_def_struct_sdna(srna, "GroomBundle");
+	RNA_def_struct_ui_text(srna, "Groom Bundle", "Bundle of hair originating from a scalp region");
+	
+	prop = RNA_def_property(srna, "scalp_vertex_group", PROP_STRING, PROP_NONE);
+	RNA_def_property_string_sdna(prop, NULL, "scalp_vgroup_name");
+	RNA_def_property_ui_text(prop, "Scalp Vertex Group", "Vertex group name of the scalp region");
+	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_GroomBundle_scalp_vgroup_name_set");
+	RNA_def_property_update(prop, 0, "rna_Groom_update_data");
+}
+
+/* groom.bundles */
+static void rna_def_groom_bundles(BlenderRNA *brna, PropertyRNA *cprop)
+{
+	StructRNA *srna;
+	PropertyRNA *prop;
+	
+	RNA_def_property_srna(cprop, "GroomBundles");
+	srna = RNA_def_struct(brna, "GroomBundles", NULL);
+	RNA_def_struct_sdna(srna, "Groom");
+	RNA_def_struct_ui_text(srna, "Groom Bundles", "Collection of groom bundles");
+	
+	prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
+	RNA_def_property_struct_type(prop, "GroomBundle");
+	RNA_def_property_pointer_funcs(prop, "rna_Groom_active_bundle_get", NULL, NULL, NULL);
+	RNA_def_property_ui_text(prop, "Active Groom Bundle", "Active groom bundle being displayed");
+	RNA_def_property_update(prop, NC_GROOM | ND_DRAW, NULL);
+	
+	prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
+	RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+	RNA_def_property_int_funcs(prop, "rna_Groom_active_bundle_index_get",
+	                           "rna_Groom_active_bundle_index_set",
+	                           "rna_Groom_active_bundle_index_range");
+	RNA_def_property_ui_text(prop, "Active Groom Bundle Index", "Index of active groom bundle");
+	RNA_def_property_update(prop, NC_GROOM | ND_DRAW, NULL);
+}
+
 static void rna_def_groom(BlenderRNA *brna)
 {
 	StructRNA *srna;
@@ -84,6 +177,12 @@ static void rna_def_groom(BlenderRNA *brna)
 	/* Animation Data */
 	rna_def_animdata_common(srna);
 	
+	prop = RNA_def_property(srna, "bundles", PROP_COLLECTION, PROP_NONE);
+	RNA_def_property_collection_sdna(prop, NULL, "bundles", NULL);
+	RNA_def_property_struct_type(prop, "GroomBundle");
+	RNA_def_property_ui_text(prop, "Bundles", "Bundles of hair");
+	rna_def_groom_bundles(brna, prop);
+	
 	prop = RNA_def_property(srna, "curve_resolution", PROP_INT, PROP_NONE);
 	RNA_def_property_int_sdna(prop, NULL, "curve_res");
 	RNA_def_property_range(prop, 1, 1024);
@@ -111,6 +210,7 @@ static void rna_def_groom(BlenderRNA *brna)
 void RNA_def_groom(BlenderRNA *brna)
 {
 	rna_def_groom(brna);
+	rna_def_groom_bundle(brna);
 }
 
 #endif



More information about the Bf-blender-cvs mailing list